...
|
...
|
@@ -11,6 +11,8 @@ class Tim extends Controller |
|
|
protected $key;
|
|
|
protected $api;
|
|
|
protected $identifier = 'administrator';
|
|
|
// 错误信息
|
|
|
protected $_error = '';
|
|
|
|
|
|
public function __construct(){
|
|
|
vendor('autoload');
|
...
|
...
|
@@ -42,6 +44,62 @@ class Tim extends Controller |
|
|
return json_decode($response,true);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 导入用户账号
|
|
|
*/
|
|
|
public function importUser($user){
|
|
|
//导入腾讯im账号(先查询是否存在,不存在就导入)
|
|
|
$portrait_get_res = $this->portraitGet('user_'.$user['user_id']);//查询
|
|
|
if(!isset($portrait_get_res['ErrorCode'])){
|
|
|
$this->setError('拉取资料接口报错');
|
|
|
return false;
|
|
|
}
|
|
|
if($portrait_get_res['ErrorCode'] != 0 && $portrait_get_res['ErrorCode'] != 40003){
|
|
|
$this->setError($portrait_get_res['ErrorInfo']);
|
|
|
return false;
|
|
|
}
|
|
|
if($portrait_get_res['UserProfileItem'][0]['ResultCode'] == 40003){
|
|
|
$import_res = $this->accountImport('user_'.$user['id'],$user['nickname'],$user['avatar']);//导入
|
|
|
if(!isset($import_res['ErrorCode'])){
|
|
|
$this->setError('导入账号失败');
|
|
|
return false;
|
|
|
}
|
|
|
if($import_res['ErrorCode'] != 0){
|
|
|
$this->setError($import_res['ErrorInfo']);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 导入医生账号
|
|
|
*/
|
|
|
public function importDoctor($doctor){
|
|
|
//导入腾讯im账号(先查询是否存在,不存在就导入)
|
|
|
$portrait_get_res = $this->portraitGet('doctor_'.$doctor['id']);//查询
|
|
|
if(!isset($portrait_get_res['ErrorCode'])){
|
|
|
$this->setError('拉取资料接口报错');
|
|
|
return false;
|
|
|
}
|
|
|
if($portrait_get_res['ErrorCode'] != 0 && $portrait_get_res['ErrorCode'] != 40003){
|
|
|
$this->setError($portrait_get_res['ErrorInfo']);
|
|
|
return false;
|
|
|
}
|
|
|
if($portrait_get_res['UserProfileItem'][0]['ResultCode'] == 40003){
|
|
|
$import_res = $this->accountImport('doctor_'.$doctor['id'],$doctor['nickname'],$doctor['avatar']);//导入
|
|
|
if(!isset($import_res['ErrorCode'])){
|
|
|
$this->setError('导入账号失败');
|
|
|
return false;
|
|
|
}
|
|
|
if($import_res['ErrorCode'] != 0){
|
|
|
$this->setError($import_res['ErrorInfo']);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 帐号删除
|
|
|
*/
|
...
|
...
|
@@ -57,10 +115,12 @@ class Tim extends Controller |
|
|
$response = $client->request('POST',$url,$data);
|
|
|
$res = json_decode($response,true);
|
|
|
if(!isset($res['ErrorCode'])){
|
|
|
exception('帐号删除失败',200);
|
|
|
$this->setError('帐号删除失败');
|
|
|
return false;
|
|
|
}
|
|
|
if($res['ErrorCode'] != 0){
|
|
|
exception($res['ErrorInfo'],200);
|
|
|
$this->setError($res['ErrorInfo']);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -98,12 +158,12 @@ class Tim extends Controller |
|
|
$response = $client->request('POST',$url,$data);
|
|
|
$res = json_decode($response,true);
|
|
|
if(!isset($res['ErrorCode'])){
|
|
|
Db::rollback();
|
|
|
exception('加好友失败',200);
|
|
|
$this->setError('加好友失败');
|
|
|
return false;
|
|
|
}
|
|
|
if($res['ErrorCode'] != 0){
|
|
|
Db::rollback();
|
|
|
exception($res['ErrorInfo'],200);
|
|
|
$this->setError($res['ErrorInfo']);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -121,7 +181,7 @@ class Tim extends Controller |
|
|
]);
|
|
|
$client = new Client();
|
|
|
$response = $client->request('POST',$url,$data);
|
|
|
halt($response);
|
|
|
return json_decode($response,true);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -139,24 +199,25 @@ class Tim extends Controller |
|
|
$response = $client->request('POST',$url,$data);
|
|
|
$res = json_decode($response,true);
|
|
|
if(!isset($res['ErrorCode'])){
|
|
|
Db::rollback();
|
|
|
exception('删除好友失败',200);
|
|
|
$this->setError('删除好友失败');
|
|
|
return false;
|
|
|
}
|
|
|
if($res['ErrorCode'] != 0){
|
|
|
Db::rollback();
|
|
|
exception($res['ErrorInfo'],200);
|
|
|
$this->setError($res['ErrorInfo']);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送信息
|
|
|
*/
|
|
|
public function sendMsg($user_id,$msg){
|
|
|
public function sendMsg($user_id1,$user_id2,$msg){
|
|
|
$usersig = $this->getSig($this->identifier);
|
|
|
$url = "https://console.tim.qq.com/v4/openim/sendmsg?sdkappid={$this->sdkappid}&identifier={$this->identifier}&usersig={$usersig}&random=99999999&contenttype=json";
|
|
|
$data = json_encode([
|
|
|
'SyncOtherMachine' => 2,
|
|
|
'To_Account' => (string)$user_id,
|
|
|
'From_Account' => (string)$user_id1,
|
|
|
'To_Account' => (string)$user_id2,
|
|
|
'MsgLifeTime' => 60,
|
|
|
'MsgRandom' => 1287657,
|
|
|
'MsgTimeStamp' => 1557387418,
|
...
|
...
|
@@ -171,6 +232,48 @@ class Tim extends Controller |
|
|
]);
|
|
|
$client = new Client();
|
|
|
$response = $client->request('POST',$url,$data);
|
|
|
halt($response);
|
|
|
$res = json_decode($response,true);
|
|
|
if(!isset($res['ErrorCode'])){
|
|
|
$this->setError('发送信息失败');
|
|
|
return false;
|
|
|
}
|
|
|
if($res['ErrorCode'] != 0){
|
|
|
$this->setError($res['ErrorInfo']);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询单聊未读消息计数
|
|
|
*/
|
|
|
public function getNoreadMsgNum($user_id1,$user_id2){
|
|
|
$usersig = $this->getSig($this->identifier);
|
|
|
$url = "https://console.tim.qq.com/v4/openim/sendmsg?sdkappid={$this->sdkappid}&identifier={$this->identifier}&usersig={$usersig}&random=99999999&contenttype=json";
|
|
|
$data = json_encode([
|
|
|
"To_Account" => (string)$user_id1,
|
|
|
"Peer_Account" => [
|
|
|
(string)$user_id2,
|
|
|
]
|
|
|
]);
|
|
|
$client = new Client();
|
|
|
$response = $client->request('POST',$url,$data);
|
|
|
return json_decode($response,true);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置错误信息
|
|
|
*/
|
|
|
public function setError($error)
|
|
|
{
|
|
|
$this->_error = $error;
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取错误信息
|
|
|
*/
|
|
|
public function getError()
|
|
|
{
|
|
|
return $this->_error ? __($this->_error) : '';
|
|
|
}
|
|
|
} |
...
|
...
|
|