参考:https://blog.51cto.com/u_15968310/6061423
1.下载安装 tls-sig-api-v2
生成非管理员id的时候需要“自有帐号导入即时通信”、才能生成对应user_id的签名;导入时“Identifier”这个字段相当于user_id
## 说明 此项目为 tls-sig-api-v2 版本 php 实现,之前非对称密钥无法使用此版本 api,如需使用请查看[这里](https://github.com/tencentyun/tls-sig-api-php)。 ## 集成 使用 composer 或者源码集成均可。 ### composer 集成 ``` json { "require": { "tencent/tls-sig-api-v2": "1.0" } }
2.
function randomsum($sum){ $z=""; for($i=0;$i<$sum/4;$i++){ $z .=rand(1000,9999); } return $z; } /** * curl post 模拟发送数据 * @param $cate * @return array */ function postCurls($url, $data){ $data = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); //HTTP浏览器访问版本 curl_setopt($curl, CURLOPT_HEADER, false); //头部信息 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //返回的内容作为变量储存 curl_setopt($curl, CURLOPT_URL, $url); //访问网址 curl_setopt($curl, CURLOPT_POST, true); //post请求 curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //请求数据 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,false); //对认证证书来源的检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //从证书中检查SSL加密算法是否存在 $result = curl_exec($curl); //抓取URL并把它传递给浏览器 curl_close($curl); //关闭当前curl return $result; }
3.创建操作类,调用curl。
<?php require_once "curl.php";//公共函数 require_once "TLSSigAPIv2.php";//签名生成 //$account = new User; // var_dump($account->genUserSig($id),0); // var_dump($account->account_import("2","1","1"),1); // var_dump($account->account_delete([ ["UserID"=>"1"] ]),2);die; // var_dump($account->account_check([ ["UserID"=>"1"] ]),3);die; // var_dump($account->querystate([1] ,1),4); class User{ private $sdkappid = ***; private $identifier = "***"; //自有帐号导入即时通信 public function account_import($Identifier,$Nick,$FaceUrl) { $url = "https://console.tim.qq.com/v4/im_open_login_svc/account_import?"; $url = $this->geturlparameter($url); $data = [ "Identifier" => $Identifier, "Nick" => $Nick, "FaceUrl" => $FaceUrl ]; // var_dump($data);die; $s = postCurls($url,$data); return $s; } //删除 public function account_delete($DeleteItem) { $url = "https://console.tim.qq.com/v4/im_open_login_svc/account_delete?"; $url = $this->geturlparameter($url); $data = [ "DeleteItem" => $DeleteItem ]; // echo( json_encode($data)); $s = postCurls($url,$data); return $s; } //查询帐号 public function account_check($CheckItem) { $url = "https://console.tim.qq.com/v4/im_open_login_svc/account_check?"; $url = $this->geturlparameter($url); $data = [ "CheckItem" => $CheckItem ]; // echo( json_encode($data)); $s = postCurls($url,$data); return $s; } //查询帐号在线状态 public function querystate($To_Account ,$IsNeedDetail) { $url = "https://console.tim.qq.com/v4/im_open_login_svc/account_check?"; $url = $this->geturlparameter($url); $data = [ "IsNeedDetail" => $IsNeedDetail, "To_Account" => $To_Account ]; // echo( json_encode($data)); $s = postCurls($url,$data); return $s; } //帐号生成的签名 public function genUserSig($id) { $TLSSigAPIv2 = new TLSSigAPIv2($this->sdkappid,false); // var_dump(1);die; $TLSSigAPIv2 = new TLSSigAPIv2($this->sdkappid,"b7009c4a7bc78740e5a472a443978d282805cf62d931db0bc89920d0d57a7c80"); return $TLSSigAPIv2->genUserSig($id); } //链接 public function geturlparameter($url) { $TLSSigAPIv2 = new TLSSigAPIv2($this->sdkappid,false); // var_dump(1);die; $TLSSigAPIv2 = new TLSSigAPIv2($this->sdkappid,"b7009c4a7bc78740e5a472a443978d282805cf62d931db0bc89920d0d57a7c80"); $zz = $url.http_build_query(array( "sdkappid" => $this->sdkappid, "identifier" => $this->identifier, "usersig" => $TLSSigAPIv2->genUserSig("administrator"), 'random' => randomsum(32), 'contenttype' => 'json' )); return $zz; } }
标签:account,TLSSigAPIv2,dump,url,im,sdkappid,腾讯,php,data From: https://www.cnblogs.com/wjs2019/p/18299837