admin管理员组文章数量:1532493
密钥和依赖类直接官网下载,主要展示PhpServer.php封装类,
<?php
require_once 'TLSSig.php';
class PhpServer
{
private $sdkappid = '140****74';//sdkId
private $identifier = 'P**r';//账户名称
/**
* 创建UserSig
* @param $username 用户账号
*/
public function createUserSig($Txy_identifier=null){
if(!$Txy_identifier){
$Txy_identifier = $this->identifier;
}
$api = new TLSSigAPI();
$api->SetAppid($this->sdkappid);
$private = file_get_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.'keys/private_key');
$api->SetPrivateKey($private);
$public = file_get_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.'keys/public_key');
$api->SetPublicKey($public);
$sig = $api->genSig($Txy_identifier);
return $sig;
}
/**
* 腾讯云通信公共接口
* @param array $options['Nick'] 昵称
* @param array $options['FaceUrl'] 头像url
* @param str $Interface 腾讯接口地址例如(registration_service/register_account_v1)
*/
public function interfaces($options,$Interface){
$usersig = $this->createUserSig();
$optionStr = "usersig=".$usersig."&identifier=".$this->identifier."&sdkappid=".$this->sdkappid."&random=".$this->returnRandom()."&contenttype=json";
$url = "https://console.tim.qq/v4/".$Interface."?".$optionStr;
$result = $this->postCurl ( $url, $options);
$info = json_decode($result,true);
//$info['usersig'] = $usersig;
return $info;
}
/**
* CURL Post发送数据
*
* @param $url 地址
* @param $option 参数数据
* @param $header 消息头
* @param $type 发送方式
*/
private function postCurl($url, $option, $type = 'POST') {
$curl = curl_init (); // 启动一个CURL会话
curl_setopt ( $curl, CURLOPT_URL, $url ); // 要访问的地址
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, FALSE ); // 对认证证书来源的检查
curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, FALSE ); // 从证书中检查SSL加密算法是否存在
curl_setopt ( $curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)' ); // 模拟用户使用的浏览器
if (! empty ( $option )) {
$options = json_encode ( $option );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $options ); // Post提交的数据包
}
curl_setopt ( $curl, CURLOPT_TIMEOUT, 30 ); // 设置超时限制防止死循环
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 ); // 获取的信息以文件流的形式返回
curl_setopt ( $curl, CURLOPT_CUSTOMREQUEST, $type );
$result = curl_exec ( $curl ); // 执行操作
curl_close ( $curl ); // 关闭CURL会话
return $result;
}
/**
* 返回随机数
*/
public function returnRandom(){
return rand("111111111","999999999");
}
调用 :
$api = new PhpServer();
$options['Identifier'] = $users ['member_id'];
$options['Nick'] = $users ['nickname'];
$options['FaceUrl'] = $users ['face'];
$ret = $api->interfaces($options,'im_open_login_svc/account_import');
版权声明:本文标题:腾讯云API接口封装 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1726067770a1054081.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论