xiaogang 3 роки тому
батько
коміт
fc5be8c03b

+ 23 - 18
app/Http/Controllers/Api/ChatController.php

xqd
@@ -31,26 +31,31 @@ class ChatController extends Controller
             if(!$toUser = User::query()->where(['tencent_im_user_id'=>$request->tencent_im_user_id])->first()){
                 throw new Exception("对应用户不存在");
             }
+            if(!ChatList::query()->where(['user_id'=>$user->id,'to_user_id'=>$toUser->id])->first()){
 
-            $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);
+                $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);
 
-            ChatList::query()->firstOrCreate([
-                'user_id'=>$user->id,
-                'to_user_id'=>$toUser->id,
-                'atime'=>date('Y-m-d H:i:s'),
-            ]);
-            ChatList::query()->firstOrCreate([
-                'user_id'=>$toUser->id,
-                'to_user_id'=>$user->id,
-                'atime'=>date('Y-m-d H:i:s'),
-            ]);
+                ChatList::query()->firstOrCreate([
+                    'user_id'=>$user->id,
+                    'to_user_id'=>$toUser->id,
+                    'atime'=>date('Y-m-d H:i:s'),
+                ]);
+                ChatList::query()->firstOrCreate([
+                    'user_id'=>$toUser->id,
+                    'to_user_id'=>$user->id,
+                    'atime'=>date('Y-m-d H:i:s'),
+                ]);
+
+            }else{
+                $res = [];
+            }
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();

+ 15 - 0
app/Http/Controllers/Api/TencentController.php

xqd
@@ -0,0 +1,15 @@
+<?php
+
+
+namespace App\Http\Controllers\Api;
+
+
+use Illuminate\Http\Request;
+use function Symfony\Component\Translation\t;
+
+class TencentController extends Controller
+{
+    public function notify(Request $request){
+        file_put_contents('/logs/tencent.log',var_export($request->post(),true).PHP_EOL,FILE_APPEND);
+    }
+}

+ 1 - 0
routes/api.php

xqd
@@ -201,6 +201,7 @@ $api->version('v1', [
     $api->any('/create_dynamic', 'TestController@create_dynamic')->name('create_dynamic');
     $api->any('/test_push', 'TestController@test_push')->name('test_push');
     $api->any('/jg_auth', 'TestController@jg_auth')->name('jg_auth');
+    $api->any('/tencent_notify', 'TencentController@notify')->name('notify');
 
 
 });