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;
}
相关推荐
小孔不爱coding7 小时前
在ubuntu20.04+系统部署VUE及Django项目的过程记录——以腾讯云为例
vue.js·django·腾讯云
A尘埃3 天前
腾讯云对象存储以及项目业务头像上传
腾讯云·图像上传
QuZhengRong7 天前
【AI】免费GPU算力平台部署wan2.1
人工智能·腾讯云·视频
山海青风7 天前
微信小程序实战案例 - 餐馆点餐系统 阶段 3 - 下单 & 云数据库
数据库·微信小程序·小程序·腾讯云
Pluto & Ethereal9 天前
新手宝塔部署thinkphp一步到位
运维·服务器·阿里云·php·腾讯云
wu~9709 天前
图片文本识别OCR+DeepSeekapi实现提取图片关键信息
ocr·腾讯云·文字识别·deepseek
wu~9709 天前
腾讯OCR文字识别实践--简历文本识别
ocr·腾讯云
大个个个个个儿10 天前
vue3腾讯云直播 前端拉流(前端页面展示直播)
前端·javascript·腾讯云
master cat10 天前
Ubuntu下载火狐浏览器
linux·ubuntu·腾讯云