标签:超过 verify cot 城市 led xpl 漫游 dex 编写
使用本扩展前需要登录 即时通信 IM 控制台 创建应用,配置管理员、获取 app_id、Key 等关键信息更多请查看并熟读 即时通信 IM 服务端API , REST API 接口列表
<?php
namespace tencentyun\im;
/**
腾讯IM API
*/
class im{
private $sdkappid; // 创建应用时即时通信 IM 控制台分配的 SDKAppID
private $identifier; // 必须为 App 管理员帐号
private $key; // 私钥
private $usersig; // 签名
private $random; // 随机数
private $postfix; // url参数
public function __construct($sdkappid,$identifier,$key) {
$this->sdkappid = $sdkappid;
$this->identifier = $identifier;
$this->key = $key;
$this->usersig = $this->genSig($identifier);
$this->random = (int)$this->nonce_str();
$this->postfix = ‘?sdkappid=‘.$this->sdkappid.‘&identifier=‘.$this->identifier.‘&usersig=‘.$this->usersig.‘&random=‘.$this->random.‘&contenttype=json‘;
}
/**
@return [type] [description]
*/
public function push_msg($From_Account=‘‘,$To_Account,$MsgBody,$SyncOtherMachine=1){
$url = ‘https://console.tim.qq.com/v4/openim/sendmsg‘.$this->postfix;
$data = [
‘SyncOtherMachine‘ => (int)$SyncOtherMachine,
‘To_Account‘ => (string)$To_Account,
‘MsgRandom‘ => (int)$this->nonce_str(8), // 随机数
‘MsgTimeStamp‘ => time(), // 时间戳
‘MsgBody‘ => [$MsgBody],
];
if (!empty($From_Account)) {
$data[‘From_Account‘] = (string)$From_Account;
}
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
$info = $this->http_request($url,$data);
$info = json_decode($info,true);
return $info;
}
/**
<?php
namespace app\api\controller;
use app\common\controller\Base;
use think\Validate;
use think\Db;
use tencentyun\im\im as Tim;
/**
标签:超过 verify cot 城市 led xpl 漫游 dex 编写
原文地址:https://blog.51cto.com/13346331/2465278