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;
}
相关推荐
NY62 天前
腾讯云上TKE集群中通过clb-ingress公网访问到后端服务
云计算·腾讯云
冲的运维日常4 天前
跨云镜像迁移实战:阿里云 → 腾讯云
阿里云·云计算·腾讯云
麦兜*5 天前
Redis数据迁移实战:从自建到云托管(阿里云/腾讯云)的平滑过渡
java·spring boot·redis·spring·spring cloud·阿里云·腾讯云
whltaoin5 天前
SpringCloud项目阶段五:openFeign服务接入以及接入腾讯云内容安全服务实现文章提交违规信息自动审核
spring cloud·腾讯云·openfeign·内容安全
uesowys5 天前
腾讯云容器服务
腾讯云·容器服务
Clownseven5 天前
忘记云服务器密码怎么办?阿里云/腾讯云/AWS密码重置官方指南
服务器·阿里云·腾讯云
@Ryan Ding5 天前
阿里云与腾讯云产品操作与体验:云平台运维实战技术解析
阿里云·云计算·负载均衡·腾讯云·cdn
Clownseven7 天前
宝塔面板搭建RustDesk教程:告别命令行,一键拥有私有远程桌面
docker·腾讯云
Clownseven18 天前
阿里云ECS vs 腾讯云CVM:2核4G服务器性能实测对比 (2025)
服务器·阿里云·腾讯云
凯子坚持 c18 天前
AI 赋能云端运维:基于 MCP 协议深度集成 Codebuddy CLI 与腾讯云 Lighthouse 的实战全解
运维·人工智能·腾讯云·腾讯轻量云ai创想家