PHP腾讯云人脸核身获取SIGN Ticket

参考腾讯云官方文档:人脸核身 获取 SIGN ticket_腾讯云

前提条件:已经获取了access_token。获取方法可参考:

PHP腾讯云人脸核身获取Access Token-CSDN博客

php 复制代码
public function getSignTicket(){
        

    $access_token = file_get_contents('/data/config/tx_face_accesstoken.txt');

    if(!$access_token){
        return;
    }

    $data = [
        'appId' => '', //WBappid,https://cloud.tencent.com/document/product/1007/49634
        'access_token' => $access_token,
	    'type' => 'SIGN', 
        'version' => '1.0.0'
    ];

    $str = http_build_query($data);
    $url = 'https://kyc1.qcloud.com/api/oauth2/api_ticket?'.$str;
        
    $result = $this->cmf_curl_get($url);

    $arr = json_decode($result,true);

    if($arr['code'] == 0){
        $ticket = $arr['tickets'][0]['value'];
        //写入磁盘
        file_put_contents('/data/config/tx_face_signticket.txt',$ticket);
    }
}

function cmf_curl_get($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    $SSL = substr($url, 0, 8) == "https://" ? true : false;
    if ($SSL) {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名
    }
    $content = curl_exec($ch);
    curl_close($ch);
    return $content;
}
相关推荐
axihaihai2 天前
腾讯云镜像仓库访问问题
linux·服务器·腾讯云
胖咕噜的稞达鸭2 天前
基础IO 文件在内核中是怎么被管理的 重定向的含义 在自定义shell中加入重定向
linux·c++·git·腾讯云·visual studio·csdn开发云
腾讯云大数据2 天前
合合信息携手腾讯云升级智能决策平台,多业务场景查询效率提升45%
云计算·腾讯云
禁默6 天前
汽车领域智能体开发全解析—腾讯云黑客松Agent应用创新挑战赛微信公众号赛道实战复盘
云计算·汽车·腾讯云·智能体
污斑兔7 天前
腾讯云 CloudBase 数据库 CRUD 完整指南
数据库·云计算·腾讯云
TH_18 天前
腾讯云-(8)-宝塔面板-安装Docker
docker·云计算·腾讯云
TH_18 天前
腾讯云-(3)-Linux宝塔面板使用
linux·云计算·腾讯云
TH_19 天前
腾讯云-(5)-宝塔软件安装
云计算·腾讯云
G31135422739 天前
腾讯云国际站云服务器和国内站产品有什么区别呢?
服务器·云计算·腾讯云