作者 何书鹏
1 个管道 的构建 通过 耗费 2 秒

腾讯im方法类优化

... ... @@ -164,34 +164,29 @@ class Tim extends Controller
return true;
}
/**
* 加好友
*/
public function friendAdd($user_id1,$user_id2,$add_sourse='Nearby'){
$usersig = $this->getSig($this->identifier);
$url = "https://console.tim.qq.com/v4/sns/friend_add?sdkappid={$this->sdkappid}&identifier={$this->identifier}&usersig={$usersig}&random=99999999&contenttype=json";
$data = [
'From_Account' => (string)$user_id1,
'AddFriendItem' => [
[
'To_Account' => (string)$user_id2,
'AddSource' => "AddSource_Type_{$add_sourse}"
],
]
];
/**
* 加好友
*/
public function friendAdd($user_id1,$add_friend_item){
$usersig = $this->getSig($this->identifier);
$url = "https://console.tim.qq.com/v4/sns/friend_add?sdkappid={$this->sdkappid}&identifier={$this->identifier}&usersig={$usersig}&random=99999999&contenttype=json";
$data = [
"From_Account" => (string)$user_id1,
"AddFriendItem" => $add_friend_item
];
$client = new Client();
$response = $client->request('POST',$url,['json'=>$data]);
$res = json_decode($response->getBody()->getContents(),true);
if(!isset($res['ErrorCode'])){
$res = json_decode($response->getBody()->getContents(),true);
if(!isset($res['ErrorCode'])){
$this->setError('加好友失败');
return false;
}
if($res['ErrorCode'] != 0){
}
if($res['ErrorCode'] != 0){
$this->setError($res['ErrorInfo']);
return false;
}
return true;
}
}
return true;
}
/**
* 拉取好友
... ... @@ -307,6 +302,22 @@ class Tim extends Controller
}
/**
* 校验好友
*/
public function friendCheck($user_id1,$friend_id_arr){
$usersig = $this->getSig($this->identifier);
$url = "https://console.tim.qq.com/v4/sns/friend_check?sdkappid={$this->sdkappid}&identifier={$this->identifier}&usersig={$usersig}&random=99999999&contenttype=json";
$data = [
"From_Account" => (string)$user_id1,
"To_Account" => $friend_id_arr,
"CheckType" => "CheckResult_Type_Both"
];
$client = new Client();
$response = $client->request('POST',$url,['json'=>$data]);
return json_decode($response->getBody()->getContents(),true);
}
/**
* 设置错误信息
*/
public function setError($error)
... ...