Browse Source

商户添加和编辑,影响im

lizhen_gitee 6 months ago
parent
commit
4c7fccab4c

+ 6 - 0
application/api/controller/User.php

@@ -6,6 +6,7 @@ use app\common\controller\Api;
 use app\common\library\Sms;
 use think\Validate;
 use think\Db;
+use app\common\library\Tenim;
 /**
  * 会员接口
  */
@@ -129,6 +130,11 @@ class User extends Api
             $this->error('修改资料失败');
         }
 
+        //如果有修改头像或昵称,同步到im
+        //user_用户端小程序,master_师傅,kefu_客服
+        $tenim = new Tenim();
+        $rs = $tenim->useredit('user_'. $this->auth->id, $data['nickname'], $data['avatar']);
+
         $this->success();
     }
 

+ 43 - 0
application/common/library/Tenim.php

@@ -107,6 +107,49 @@ class Tenim
 
     }
 
+    //设置资料
+    public function useredit($userid,$nickname = '',$avatar = ''){
+        $random = rand(10000000,99999999);
+        $usersig = $this->usersig("administrator");
+        //dump($usersig);
+        // 获取配置信息
+        $config = config("tencent_im");
+        $url = "https://console.tim.qq.com/v4/profile/portrait_set";
+        $url .= "?sdkappid=".$config["sdkappid"];
+        $url .= "&identifier=administrator";
+        $url .= "&usersig=".$usersig;
+        $url .= "&random=".$random;
+        $url .= "&contenttype=json";
+        $tencentObj = new tencentim($url);
+
+        $ProfileItem = [];
+        if($nickname){
+            $ProfileItem[] = [
+                'Tag'   => 'Tag_Profile_IM_Nick',
+                'Value' => $nickname
+            ];
+        }
+        if($avatar){
+            $ProfileItem[] = [
+                'Tag'   => 'Tag_Profile_IM_Image',
+                'Value' => $avatar
+            ];
+        }
+        $data = [
+            'From_Account' => $userid,
+            'ProfileItem'  => $ProfileItem
+        ];
+
+        $res = $tencentObj->toSend($data);
+
+        if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
+            $error = !empty($res['ErrorInfo']) ? 'im error:'.$res['ErrorInfo'] : 'im error';
+            return $error;
+        }
+
+        return true;
+    }
+
     //注册用户到im
     public function register($userid,$nickname,$avatar) {
 

+ 11 - 0
application/company/controller/Usercompany.php

@@ -6,6 +6,7 @@ use app\common\controller\Apic;
 use think\Db;
 use app\common\model\User as Usermodel;
 use think\Exception;
+use app\common\library\Tenim;
 /**
  * 客户管理
  */
@@ -101,6 +102,11 @@ class Usercompany extends Apic
 
         $user_id = $register_rs;
 
+        //注册到im
+        //user_用户端小程序,master_师傅,kefu_客服
+        $tenim = new Tenim();
+        $rs = $tenim->register('user_'. $user_id, $extend['nickname'], localpath_to_netpath($extend['avatar']));
+
         $zuobiao = input('zuobiao','','trim');
         $zuobiao = explode(',',$zuobiao);
 
@@ -186,6 +192,11 @@ class Usercompany extends Apic
             $this->error('操作失败');
         }
 
+        //如果有修改头像或昵称,同步到im
+        //user_用户端小程序,master_师傅,kefu_客服
+        $tenim = new Tenim();
+        $rs = $tenim->useredit('user_'. $info['user_id'], $nickname, '');
+
         //
         $zuobiao = input('zuobiao','','trim');
         $zuobiao = explode(',',$zuobiao);