usersig("administrator"); // 获取配置信息 $config = config("tencent_im"); $url = "?sdkappid=".$config["sdkappid"]; $url .= "&identifier=administrator"; $url .= "&usersig=".$usersig; $url .= "&random=".$random; $url .= "&contenttype=json"; $this->url = $url; } /** * 获取usersig签名-具体操作 */ private function usersig($user_id) { // 获取配置信息 $config = config("tencent_im"); $usersigObj = new getusersig($config["sdkappid"],$config["key"]); $usersig = $usersigObj->genUserSig($user_id); return $usersig; } /** * 获取房间用户 */ public function getRoomUser($params=[]) { $result = [ 'status' => 1, 'msg' => '获取成功', 'data' => [], ]; try { $partyArr = isset($params['party_ids']) ? $params['party_ids'] : []; $url = "https://console.tim.qq.com/v4/group_open_avchatroom_http_svc/get_members".$this->url; $tencentObj = new tencentim($url); //获取用户 ["57","62","63","105","106","107","108","109","116","119"] $memberList = []; if(!empty($partyArr)) { foreach ($partyArr as $key => $value) { $data["GroupId"] = (string)$value; $tencentRes = $tencentObj->toSend($data); if (isset($tencentRes['ActionStatus']) && $tencentRes['ActionStatus'] == 'OK') { if (isset($tencentRes['MemberList']) && !empty($tencentRes['MemberList'])) { foreach ($tencentRes['MemberList'] as $ukey => $uval) { $memberList[$value]['member_list'][] = [ 'avatar' => $uval['Avatar'], 'user_id'=> $uval['Member_Account'], 'nickname' => $uval['NickName'], ]; } $memberList[$value]['online_num'] = count($memberList[$value]['member_list']); } } } } $result['data'] = $memberList; } catch (\Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } /** * 获取房间自定义属性 */ public function getGroupAttr($params=[]) { $result = [ 'status' => 1, 'msg' => '获取成功', 'data' => [], ]; try { $partyId = isset($params['party_id']) ? $params['party_id'] : []; $url = "https://console.tim.qq.com/v4/group_open_attr_http_svc/get_group_attr".$this->url; $tencentObj = new tencentim($url); $imResult = []; if(!empty($partyId)) { $data["GroupId"] = $partyId; $imRes = $tencentObj->toSend($data); if (isset($imRes['ActionStatus']) && $imRes['ActionStatus'] != 'OK') { $errorInfo = isset($imRes['ErrorInfo']) ? $imRes['ErrorInfo'] : []; throw new Exception(json_encode($errorInfo)); } $imResult = isset($imRes['GroupAttrAry']) ? $imRes['GroupAttrAry'] : []; } $result['data'] = $imResult; } catch (\Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } /** * 更新房间属性 */ public function getGroupAttrEdit($params=[]) { $result = [ 'status' => 1, 'msg' => '获取成功', 'data' => [], ]; try { $partyId = isset($params['party_id']) ? $params['party_id'] : []; $partyAttr = isset($params['party_attr']) ? $params['party_attr'] : []; $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_attr".$this->url; $tencentObj = new tencentim($url); if(!empty($partyId)) { $data["GroupId"] = (string)$partyId; $data["GroupAttr"] = $partyAttr; $imRes = $tencentObj->toSend($data); if (isset($imRes['ActionStatus']) && $imRes['ActionStatus'] != 'OK') { $errorInfo = isset($imRes['ErrorInfo']) ? $imRes['ErrorInfo'] : []; throw new Exception(json_encode($errorInfo)); } } } catch (\Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } /** * 添加黑名单 */ public function addBlack($params=[]) { $result = [ 'status' => 1, 'msg' => '操作成功', 'data' => [], ]; try { $userId = isset($params['user_id']) ? $params['user_id'] : 0; $blackUserIds = isset($params['black_user_ids']) ? $params['black_user_ids'] : []; $url = "https://console.tim.qq.com/v4/sns/black_list_add".$this->url; $tencentObj = new tencentim($url); if(!empty($userId)) { $data["From_Account"] = (string)$userId; $data["To_Account"] = $blackUserIds; $imRes = $tencentObj->toSend($data); if (isset($imRes['ActionStatus']) && $imRes['ActionStatus'] != 'OK') { $errorInfo = isset($imRes['ErrorInfo']) ? $imRes['ErrorInfo'] : []; throw new Exception(json_encode($errorInfo)); } } } catch (\Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } /** * 删除黑名单 */ public function delBlack($params=[]) { $result = [ 'status' => 1, 'msg' => '操作成功', 'data' => [], ]; try { $userId = isset($params['user_id']) ? $params['user_id'] : 0; $blackUserIds = isset($params['black_user_ids']) ? $params['black_user_ids'] : []; $url = "https://console.tim.qq.com/v4/sns/black_list_delete".$this->url; $tencentObj = new tencentim($url); if(!empty($userId)) { $data["From_Account"] = (string)$userId; $data["To_Account"] = $blackUserIds; $imRes = $tencentObj->toSend($data); if (isset($imRes['ActionStatus']) && $imRes['ActionStatus'] != 'OK') { $errorInfo = isset($imRes['ErrorInfo']) ? $imRes['ErrorInfo'] : []; throw new Exception(json_encode($errorInfo)); } } } catch (\Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } /** * 删除黑名单 */ public function getBlackList($params=[]) { $result = [ 'status' => 1, 'msg' => '获取成功', 'data' => [], ]; try { $userId = isset($params['user_id']) ? $params['user_id'] : 0; $page = isset($params['page']) ? $params['page'] : 0; $limit = isset($params['limit']) ? $params['limit'] : 30; $url = "https://console.tim.qq.com/v4/sns/black_list_get".$this->url; $tencentObj = new tencentim($url); if(!empty($userId)) { $data["From_Account"] = $userId; $data["StartIndex"] = $page; $data["MaxLimited"] = $limit; $data["LastSequence"] = 0; $imRes = $tencentObj->toSend($data); if (isset($imRes['ActionStatus']) && $imRes['ActionStatus'] != 'OK') { $errorInfo = isset($imRes['ErrorInfo']) ? $imRes['ErrorInfo'] : []; throw new Exception(json_encode($errorInfo)); } $result['data'] = isset($imRes['BlackListItem']) ? $imRes['BlackListItem'] : []; } } catch (\Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } /** * 创建用户账号 */ public function accountImport($params=[]) { $result = [ 'status' => 1, 'msg' => '获取成功', 'data' => [], ]; try { $userId = isset($params['user_id']) ? $params['user_id'] : 0; $nickname = isset($params['nickname']) ? $params['nickname'] : ''; $avatar = isset($params['avatar']) ? $params['avatar'] : ''; $url = "https://console.tim.qq.com/v4/im_open_login_svc/account_import".$this->url; $tencentObj = new tencentim($url); if(!empty($userId)) { $data["UserID"] = (string)$userId; $data["Nick"] = $nickname; $data["FaceUrl"] = $avatar; $imRes = $tencentObj->toSend($data); if (isset($imRes['ActionStatus']) && $imRes['ActionStatus'] != 'OK') { $errorInfo = isset($imRes['ErrorInfo']) ? $imRes['ErrorInfo'] : []; throw new Exception(json_encode($errorInfo)); } } } catch (\Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } /** * 查询用户账号 */ public function accountCheck($params=[]) { $result = [ 'status' => 1, 'msg' => '获取成功', 'data' => [], ]; try { $userIds = isset($params['user_ids']) ? $params['user_ids'] : []; if(!empty($userIds)) { $url = "https://console.tim.qq.com/v4/im_open_login_svc/account_check".$this->url; $tencentObj = new tencentim($url); foreach ($userIds as $key => $value) { $userIdArr[] = [ 'UserID' => $value, ]; } $data["CheckItem"] = $userIdArr; $imRes = $tencentObj->toSend($data); if (isset($imRes['ActionStatus']) && $imRes['ActionStatus'] != 'OK') { $errorInfo = isset($imRes['ErrorInfo']) ? $imRes['ErrorInfo'] : []; throw new Exception(json_encode($errorInfo)); } $result['data'] = isset($imRes['ResultItem']) ? $imRes['ResultItem'] : []; } } catch (\Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } }