xiaogang 3 years ago
parent
commit
d660a7af2f

+ 7 - 0
app/Services/HomeService.php

xqd
@@ -276,6 +276,13 @@ class HomeService
         if(empty($param['user_id'])){
             throw new Exception("参数错误");
         }
+        if(!$touser = User::query()->where('id',$param['user_id'])->first()){
+            throw new Exception("用户不存在");
+        }
+
+        $tencentim = new TencentImFriendService();
+        $tencentim->friend_black_add($user->tencent_im_user_id,$touser->tencent_im_user_id);
+
         if(UserBlacklistModel::query()->where(['user_id'=>$user->id,'black_id'=>$param['user_id']])->first()){
             throw new Exception("该用户已被拉黑");
         }

+ 28 - 0
app/Services/TencentImFriendService.php

xqd xqd
@@ -26,6 +26,8 @@ class TencentImFriendService
         'friendAddItem' => 'v4/sns/friend_add',   //单个添加好友,
         'friendGet' => 'v4/sns/friend_get', //拉取好友,
         'friendCheck' => 'v4/sns/friend_check', //校验好友
+        'black_add' => 'v4/sns/black_list_add', //拉黑好友
+        'black_del' => 'v4/sns/black_list_delete', //删除拉黑好友
     ];
 
     static public function verifyUserApplyFriendExists(User $fromUser, User $toUser)
@@ -215,4 +217,30 @@ class TencentImFriendService
     }
 
 
+    //拉黑
+    public function friend_black_add(string $fromAccount, string $toAccount)
+    {
+        $this->restApiName = self::TENCENT_REST_APIS['black_add'];
+        $baseApiHost = $this->getTencentImRestApiBaseHost();
+        $params = [
+            'From_Account' => $fromAccount,
+            'To_Account' => $toAccount,
+        ];
+        $apiResult = $this->requestApi($baseApiHost, $params);
+        return $apiResult;
+    }
+
+    //取消拉黑
+    public function friend_black_del(string $fromAccount, string $toAccount)
+    {
+        $this->restApiName = self::TENCENT_REST_APIS['black_del'];
+        $baseApiHost = $this->getTencentImRestApiBaseHost();
+        $params = [
+            'From_Account' => $fromAccount,
+            'To_Account' => $toAccount,
+        ];
+        $apiResult = $this->requestApi($baseApiHost, $params);
+        return $apiResult;
+    }
+
 }

+ 5 - 0
app/Services/UserService.php

xqd
@@ -123,6 +123,11 @@ class UserService
         if(!$black = UserBlacklistModel::query()->where(['id'=>$id,'user_id'=>$user->id])->first()){
             throw new Exception("对方不在你的黑名单中");
         }
+        $black_user = User::query()->where('id',$black->black_id)->first();
+
+        $tencentim = new TencentImFriendService();
+        $tencentim->friend_black_del($user->tencent_im_user_id,$black_user->tencent_im_user_id);
+
         $black->delete();
         return true;
     }