893 lines
36 KiB
PHP
893 lines
36 KiB
PHP
<?php
|
||
|
||
namespace app\api\model;
|
||
|
||
|
||
use fast\Http;
|
||
use think\Db;
|
||
use think\Log;
|
||
use think\Model;
|
||
use think\facade\Env;
|
||
use fast\Tencentst;
|
||
|
||
class Tencent extends Model
|
||
{
|
||
|
||
//获取腾讯IM UserSig信息
|
||
//$uid => 用户id
|
||
public function tencent_user_sig_info($uid){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$tencentyun_im_key = $config['tencentyun_im_key'];
|
||
$tencent = new Tencentst($tencentyun_im_appid, $tencentyun_im_key);
|
||
$user_sig = $tencent->genUserSig($uid);
|
||
|
||
return $user_sig;
|
||
}
|
||
|
||
//单个账号导入
|
||
public function account_import($uid,$data=''){
|
||
$config = get_system_config();
|
||
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/im_open_login_svc/account_import?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
//https://xxxxxx/v4/im_open_login_svc/account_import?sdkappid=88888888&identifier=admin&usersig=xxx&random=99999999&contenttype=json
|
||
$curlPost = array(
|
||
'UserID' => 'u'.$uid,
|
||
'Nick' => '',
|
||
'FaceUrl' => '',
|
||
);
|
||
if($data){
|
||
//添加用户信息 昵称和头像
|
||
$curlPost['Nick'] = $data['nick'];
|
||
$curlPost['FaceUrl'] = $data['face_url'];
|
||
}
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '导入成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut['ErrorInfo']];
|
||
}
|
||
}
|
||
|
||
//单个删除账号
|
||
public function account_delete($uid){
|
||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/im_open_login_svc/account_delete?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost = array(
|
||
'DeleteItem' => array(
|
||
array(
|
||
'UserID' => 'u'.$uid, //
|
||
),
|
||
),
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||
}
|
||
}
|
||
|
||
//批量删除账号
|
||
public function account_deletes($udata){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/im_open_login_svc/account_delete?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost = array(
|
||
'DeleteItem' => $udata
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||
}
|
||
}
|
||
|
||
//查询账号
|
||
//$uid => 用户id
|
||
public function account_check($uid){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/im_open_login_svc/account_check?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'CheckItem' => array(
|
||
array(
|
||
'UserID' => 'u'.$uid, //
|
||
),
|
||
),
|
||
);
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
// var_dump($reslut);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
if($reslut['ResultItem'][0]['AccountStatus'] == 'Imported'){
|
||
return ['code' => 1, 'msg' => '查询成功', 'data' => $reslut];
|
||
}else{
|
||
return ['code' => 0, 'msg' => '查询失败', 'data' => $reslut];
|
||
}
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||
}
|
||
|
||
}
|
||
|
||
//拉入黑名单
|
||
public function black_list_add($uid, $receive_uid){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/sns/black_list_add?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'From_Account' => $uid,
|
||
'To_Account' => [$receive_uid],
|
||
);
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
Log::record("腾讯用户拉入黑名单".json_encode($reslut),"infos");
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 201, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
//移除黑名单
|
||
public function black_list_delete($uid, $receive_uid){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/sns/black_list_delete?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'From_Account' => $uid,
|
||
'To_Account' => [$receive_uid],
|
||
);
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 200, 'msg' => '移除成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 201, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
//发送群内系统消息
|
||
public function send_group_system_notification($rid, $message_data){
|
||
Log::record("腾讯群内系统消息发送结果".json_encode($rid.$message_data),"info");
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/send_group_system_notification?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'GroupId' => $rid,
|
||
'Content' => $message_data,
|
||
);
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
Log::record("腾讯群内系统消息发送结果".json_encode($reslut),"info");
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '发送成功', 'data' => $reslut];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||
}
|
||
}
|
||
|
||
/*
|
||
* 发送系统消息
|
||
* 向所有直播群下发广播消息
|
||
* 需 购买旗舰版或企业版套餐包
|
||
*/
|
||
public function send_broadcast_msg($message_data){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$random = time().rand(111,999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/send_broadcast_msg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'Random' => $random,
|
||
'MsgBody' => array(
|
||
array(
|
||
'MsgType' => 'TIMCustomElem',
|
||
'MsgContent' => array(
|
||
'Data' => $message_data,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
Log::record("广播消息信息".json_encode($reslut),"info");
|
||
Log::record("广播消息信息3".json_encode($admin_sig),"info");
|
||
Log::record("广播消息信息2".$admin_sig,"info");
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '发送成功', 'data' => $reslut];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||
}
|
||
}
|
||
|
||
//发送群内普通消息
|
||
public function send_group_msg($rid, $message_data, $uid=''){
|
||
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$random = time().rand(111,999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'GroupId' => $rid,
|
||
'From_Account' => $uid,
|
||
'Random' => $random,
|
||
'MsgBody' => array(
|
||
array(
|
||
'MsgType' => 'TIMTextElem',
|
||
'MsgContent' => array(
|
||
'Text' => $message_data,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
// $txt = date('Y-m-d H:i:s').'测试';
|
||
// error_log($txt, 3, 'a.txt');
|
||
return $reslut;
|
||
|
||
}
|
||
|
||
|
||
//创建群组
|
||
public function create_group($uid,$rid,$type='AVChatRoom',$url='',$group_name=''){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/create_group?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
if(!$group_name){
|
||
$group_name = 'u'.$uid;
|
||
}
|
||
$curlPost = array(
|
||
'Owner_Account' => 'u'.$uid,
|
||
'Type' => $type,
|
||
'GroupId' => strval($rid),
|
||
'Name' => $group_name,
|
||
'FaceUrl' => $url
|
||
);
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '添加成功', 'data' => $reslut];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||
}
|
||
}
|
||
|
||
//增加群成员
|
||
public function add_group_member($rid, $uid){
|
||
//检查用户是否存在
|
||
$user = $this->account_check($uid);
|
||
if($user['code'] != 1){
|
||
$this->account_import($uid);
|
||
}
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/add_group_member?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost = array(
|
||
'GroupId' => strval($rid),
|
||
'MemberList' => array(
|
||
array(
|
||
'Member_Account' => 'u'.$uid,
|
||
),
|
||
),
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '添加成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
|
||
//删除群成员
|
||
public function delete_group_member($rid, $uid){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/delete_group_member?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost = array(
|
||
'GroupId' => strval($rid),
|
||
'MemberToDel_Account' => array(
|
||
'u'.$uid
|
||
),
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
Log::record("腾讯群内删除成员结果".json_encode($reslut),"info");
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
//解散群,
|
||
public function delete_group($rid){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/destroy_group?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost = array(
|
||
'GroupId' => strval($rid),
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
//指定用户发送消息给用户
|
||
public function user_sendmsg($uid, $receive_uid, $message, $machine_type = 2, $OnlineOnlyFlag = 0){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/openim/sendmsg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'SyncOtherMachine' => $machine_type,
|
||
'From_Account' => strval('u'.$uid),
|
||
'To_Account' => strval('u'.$receive_uid),
|
||
'MsgRandom' => time(),
|
||
'MsgBody' => array(
|
||
array(
|
||
'MsgType' => 'TIMTextElem',
|
||
'MsgContent' => array(
|
||
'Text' => $message,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
if($OnlineOnlyFlag == 1){
|
||
$curlPost['OnlineOnlyFlag'] = 1;
|
||
}
|
||
Log::record("xitong消息信息1:".$admin_sig,"info");
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
Log::record("xitong消息信息2:".$reslut,"info");
|
||
return $reslut;
|
||
}
|
||
|
||
//批量发单聊消息
|
||
//若不希望将消息同步至 From_Account 则 SyncOtherMachine 填写2。
|
||
public function batchsendmsg($receive_uid, $message, $machine_type = 2){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/openim/batchsendmsg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'SyncOtherMachine' => $machine_type,
|
||
'To_Account' => $receive_uid,
|
||
'MsgRandom' => time(),
|
||
'MsgBody' => array(
|
||
array(
|
||
'MsgType' => 'TIMTextElem',
|
||
'MsgContent' => array(
|
||
'Text' => $message,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
return $reslut;
|
||
}
|
||
|
||
//获取APP中的所有群组
|
||
public function get_appid_group_list(){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/get_appid_group_list?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'Limit' => 20,
|
||
'Next' => 0,
|
||
);
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
}
|
||
|
||
|
||
public function txt(){
|
||
$postUrl = 'https://app.yayinyy.com/api/Agora/get_sstoken';
|
||
|
||
$curlPost = array(
|
||
'code' => '44863d01cd628e583efeb3b9eda510fd',
|
||
);
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
return $reslut;
|
||
}
|
||
|
||
//腾讯IM请求封装方法
|
||
public function tencent_post_url($postUrl, $curlPost){
|
||
|
||
$headerArray =array(
|
||
"Content-type:application/json",
|
||
"Accept:application/json",
|
||
);
|
||
|
||
$ch = curl_init();//初始化curl
|
||
curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
|
||
// curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||
$data = curl_exec($ch);//运行curl
|
||
curl_close($ch);
|
||
if ($data) {
|
||
$data = json_decode($data, true);
|
||
}
|
||
// dump($data);exit;
|
||
return $data;
|
||
}
|
||
|
||
//指定用户发送自定义消息给注册用户
|
||
public function user_custom_sendmsg($uid, $receive_uid, $message, $machine_type = 2){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/openim/sendmsg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'SyncOtherMachine' => $machine_type,
|
||
'From_Account' => strval($uid),
|
||
'To_Account' => strval($receive_uid),
|
||
'MsgRandom' => time(),
|
||
'MsgBody' => array(
|
||
array(
|
||
'MsgType' => 'TIMCustomElem',
|
||
'MsgContent' => array(
|
||
// 'Text' => $message,
|
||
'Data' => $message,
|
||
// 'Desc' => 'notification',
|
||
),
|
||
),
|
||
),
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
return $reslut;
|
||
}
|
||
|
||
//获取用户在线状态
|
||
public function query_user_online_status($to_uid_arr)
|
||
{
|
||
foreach($to_uid_arr as $key => $v) {
|
||
$to_uid_arr[$key] = strval($v);
|
||
}
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/openim/query_online_status?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'To_Account' => $to_uid_arr,
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
|
||
return $reslut;
|
||
}
|
||
|
||
//获取直播群在线人数
|
||
public function get_group_online_num($group_id){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/get_online_member_num?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost = array(
|
||
'GroupId' => 'room'.$group_id,
|
||
);
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
return $reslut;
|
||
}
|
||
|
||
|
||
//主动审核接口
|
||
public function content_moderation($type_name, $content){
|
||
return ['code' => 1, 'msg' => '通过审核', 'data' => null];
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$random = time().rand(111,999);
|
||
|
||
$postUrl = 'https://console.tim.qq.com/v4/im_msg_audit/content_moderation?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
|
||
$curlPost = array(
|
||
'AuditName' => 'C2C', //表明送审策略,取值:C2C/Group/UserInfo/GroupInfo/GroupMemberInfo/RelationChain
|
||
'ContentType' => $type_name, //送审类型,取值:Text/Image/Audio/Video。
|
||
'Content' => $content //送审内容,最大限制8KB,当审核文件时,填对应 URL。其中图片审核最大不超过5MB
|
||
);
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
if($reslut['Result'] == 'Pass'){
|
||
return ['code' => 1, 'msg' => '通过审核', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => '该内容不过审', 'data' => null];
|
||
}
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
|
||
//获取群详细资料
|
||
public function get_group_info($group_id){
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/get_group_info?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost['GroupIdList'] = [$group_id];
|
||
// $curlPost['ResponseFilter']->GroupBaseInfoFilter(
|
||
// ['Name', 'Notification', 'FaceUrl', 'Owner_Account']
|
||
// );
|
||
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut && $reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '操作成功', 'data' => $reslut['GroupInfo']];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
|
||
//修改群基础资料
|
||
public function modify_group_base_info($group_id, $group_name = '', $group_face_url = '', $group_notice = '')
|
||
{
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost['GroupId'] = $group_id;
|
||
if($group_name){
|
||
$curlPost['Name'] = $group_name;
|
||
}
|
||
if($group_face_url){
|
||
$curlPost['FaceUrl'] = $group_face_url;
|
||
}
|
||
if($group_notice){
|
||
$curlPost['Notification'] = $group_notice;
|
||
}
|
||
// $curlPost = array(
|
||
// 'GroupId' => $group_id,
|
||
// 'Name' => $group_name,//群名称
|
||
// 'FaceUrl' => $group_face_url,//群头像
|
||
// 'Notification' => $group_notice,//群公告
|
||
//
|
||
// );
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
|
||
//修改群成员资料
|
||
public function modify_group_member_info($group_id, $member_id, $member_role)
|
||
{
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/modify_group_member_info?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost['GroupId'] = $group_id;
|
||
$curlPost['Member_Account'] = $member_id;//群成员帐号
|
||
if($member_role == 1){
|
||
$curlPost['Role'] = 'Admin';//群成员角色,取值:Owner(群主),Admin(群管理员),Member(普通群成员)
|
||
}elseif ($member_role == 2){
|
||
$curlPost['Role'] = 'Member';
|
||
}
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
|
||
//查询用户在群组中的身份
|
||
public function get_group_member_info($group_id, $member_array)
|
||
{
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/get_role_in_group?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost['GroupId'] = $group_id;
|
||
$curlPost['User_Account'] = $member_array;
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '操作成功', 'data' => $reslut['UserIdList']];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
//修改用户信息
|
||
public function modify_user_infos($member_id, $member_name, $member_face_url)
|
||
{
|
||
$config = get_system_config();
|
||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||
$im_admin = 'administrator';
|
||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||
$rand = rand(111111111,9999999999);
|
||
$postUrl = 'https://console.tim.qq.com/v4/profile/portrait_set?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||
$curlPost['From_Account'] = 'u'.$member_id;
|
||
$curlPost['ProfileItem'] = [
|
||
[
|
||
'Tag' => 'Tag_Profile_IM_Nick',
|
||
'Value' => $member_name
|
||
],
|
||
[
|
||
'Tag' => 'Tag_Profile_IM_Image',
|
||
'Value' => $member_face_url
|
||
]
|
||
];
|
||
$curlPost = json_encode($curlPost);
|
||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||
Log::record("修改用户信息:".json_encode($reslut),"infos");
|
||
if($reslut['ActionStatus'] == 'OK'){
|
||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||
}else{
|
||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||
}
|
||
}
|
||
|
||
//====新写的↓=====上面的 能用则用=============================================================================================================
|
||
|
||
// 获取 Access Token(需缓存并定时刷新,每20分钟一次)
|
||
public function getAccessToken($appid, $secret) {
|
||
$url = "https://kyc1.qcloud.com/api/oauth2/access_token";
|
||
$params = [
|
||
'app_id' => $appid,
|
||
'secret' => $secret,
|
||
'grant_type' => 'client_credential',
|
||
'version' => '1.0.0'
|
||
];
|
||
$response = HTTP::get($url, $params);
|
||
return json_decode($response, true)['access_token'];
|
||
}
|
||
|
||
// 生成 Ticket
|
||
public function getSignTicket($accessToken,$appid) {
|
||
$config = get_system_config();
|
||
$url = "https://kyc1.qcloud.com/api/oauth2/api_ticket";
|
||
$params = [
|
||
'app_id' => $appid,
|
||
'access_token' => $accessToken,
|
||
'type' => 'SIGN',
|
||
'version' => '1.0.0'
|
||
];
|
||
$response = HTTP::get($url, $params);
|
||
return json_decode($response, true)['tickets'][0]['value'];
|
||
}
|
||
|
||
// 生成 Ticket
|
||
public function getNonceTicket($accessToken,$user_id,$appid) {
|
||
$config = get_system_config();
|
||
$url = "https://kyc1.qcloud.com/api/oauth2/api_ticket";
|
||
$params = [
|
||
'app_id' => $appid,
|
||
'access_token' => $accessToken,
|
||
'type' => 'NONCE',
|
||
'version' => '1.0.0',
|
||
'user_id' => 'u'.$user_id // 用户唯一标识
|
||
];
|
||
$response = HTTP::get($url, $params);
|
||
return json_decode($response, true)['tickets'][0]['value'];
|
||
}
|
||
|
||
// 使用 SHA1 生成签名
|
||
public function getSign($userId, $nonceStr, $ticket,$appid) {
|
||
$values = [$appid, 'u'.$userId, '1.0.0', $nonceStr,$ticket];
|
||
sort($values);
|
||
$string = implode('', $values);
|
||
return sha1($string);
|
||
}
|
||
|
||
public function getFaceId($orderNo,$userName,$userIdCard,$sign,$userId,$appid,$nonceStr) {
|
||
$data = json_encode([
|
||
'appId' => $appid,
|
||
'orderNo' => $orderNo, // 唯一订单号
|
||
'name' => $userName,
|
||
'idNo' => $userIdCard,
|
||
'userId' => 'u'.$userId,
|
||
'version' => '1.0.0',
|
||
'sign' => $sign, // 上一步生成的签名
|
||
'nonce' =>$nonceStr
|
||
]);
|
||
$url = "https://kyc1.qcloud.com/api/server/getAdvFaceId?orderNo={$orderNo}";
|
||
$headers = [
|
||
'Content-Type: application/json'
|
||
];
|
||
$ch = curl_init();
|
||
curl_setopt_array($ch, [
|
||
CURLOPT_URL => $url,
|
||
CURLOPT_POST => true,
|
||
CURLOPT_HTTPHEADER => $headers,
|
||
CURLOPT_POSTFIELDS => $data,
|
||
CURLOPT_RETURNTRANSFER => true,
|
||
CURLOPT_SSL_VERIFYPEER => false // 生产环境应验证SSL
|
||
]);
|
||
|
||
$response = curl_exec($ch);
|
||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||
curl_close($ch);
|
||
|
||
// 处理响应
|
||
if ($httpCode == 200) {
|
||
return json_decode($response, true)['result']['faceId'];
|
||
} else {
|
||
return ['code' => $httpCode, 'msg' => '接口请求失败'];
|
||
}
|
||
|
||
}
|
||
|
||
//获取实名结果(5.27废弃)
|
||
public function real_name_results($orderNo,$appid,$ticket) {
|
||
//生成签名
|
||
$values = [$appid,$orderNo,'1.0.0', $ticket,generateRandom(32)];
|
||
sort($values);
|
||
$string = implode('', $values);
|
||
$sign = sha1($string);
|
||
$data = json_encode([
|
||
'appId' => $appid,
|
||
'orderNo' => $orderNo, // 唯一订单号
|
||
'version' => '1.0.0',
|
||
'sign' => $sign,
|
||
'nonce' =>generateRandom(32)
|
||
]);
|
||
//https://kyc1.qcloud.com/api/v2/base/queryfacerecord?orderNo=xxx
|
||
$url = "https://kyc1.qcloud.com/api/v2/base/queryfacerecord?orderNo={$orderNo}";
|
||
$headers = [
|
||
'Content-Type: application/json'
|
||
];
|
||
$ch = curl_init();
|
||
curl_setopt_array($ch, [
|
||
CURLOPT_URL => $url,
|
||
CURLOPT_POST => true,
|
||
CURLOPT_HTTPHEADER => $headers,
|
||
CURLOPT_POSTFIELDS => $data,
|
||
CURLOPT_RETURNTRANSFER => true,
|
||
CURLOPT_SSL_VERIFYPEER => false // 生产环境应验证SSL
|
||
]);
|
||
|
||
$response = curl_exec($ch);
|
||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||
curl_close($ch);
|
||
var_dump($response);
|
||
// 处理响应
|
||
if ($httpCode == 200) {
|
||
return ['code' => 1, 'msg' => '成功', 'data' => json_decode($response, true)['code']];
|
||
} else {
|
||
return ['code' => $httpCode, 'msg' => '接口请求失败', 'data' => $response];
|
||
}
|
||
}
|
||
|
||
|
||
}
|