| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Services\TencentImAccountService;
- use App\Services\TencentImFriendService;
- use Illuminate\Http\Request;
- use PHPUnit\Util\Exception;
- class ChatController extends Controller
- {
- /**
- * 添加好友
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse|void
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function add_friend(Request $request){
- try {
- $user = auth('api')->user();
- if(empty($request->tencent_im_user_id)){
- throw new Exception("参数错误");
- }
- $tencent_account =new TencentImAccountService();
- $tencent_friend =new TencentImFriendService();
- //检测是否已经导入IM账号
- $check_result = $tencent_account->accountCheck([$request->tencent_im_user_id]);
- if(!isset($check_result) || (isset($check_result['AccountStatus'])&&$check_result['AccountStatus']=="NotImported")){
- throw new Exception("对方账户错误");
- }
- $res = $tencent_friend->friendAddItem($user->tencent_im_user_id,$request->tencent_im_user_id);
- }catch (\Exception $exception){
- return $this->response->errorForbidden($exception->getMessage());
- }
- return response()->json($res);
- }
- public function get_friend(Request $request){
- try {
- $user = auth('api')->user();
- $tencent_friend =new TencentImFriendService();
- $res = $tencent_friend->friendGet($user->tencent_im_user_id,$request->page);
- }catch (\Exception $exception){
- return $this->response->errorForbidden($exception->getMessage());
- }
- return response()->json($res);
- }
- }
|