$secretKey = '你的secretKey';
$srcStr = 'GETfaceid.tencentcloudapi.com/?';// 文档中示例是POST的 这里改成GET 这里踩个坑- -
$param = [
"Action"=> 'DetectAuth',//默认
"Nonce"=> rand(1000,9999),
"SecretId"=>"你的secretId",
'Region'=>'ap-beijing',//区域列表中选
"Timestamp"=> time(),
'RuleId'=>'0',//自己创建的RuleID
"Token"=>'',//为空
"Version"=>'2018-03-01'//默认
];
ksort($param); //参数排序
//return json($param);
$srcStr .= urldecode(http_build_query($param));
//return $srcStr;
//排序后连接字符串 生成签名 官网有验证签名的地方 签名不对的话 可以把时间戳和随机数写死之后校验
$sign = urlencode(base64_encode(hash_hmac('sha1', $srcStr, $secretKey, true)));;
// return $sign;
$url ='https://faceid.tencentcloudapi.com/?Action=DetectAuth&Nonce='.$param['Nonce'].'&Region=ap-beijing&RuleId=0&SecretId='.$param['SecretId'].'&Signature='.$sign.'&Timestamp='.$param['Timestamp'].'&Token=&Version=2018-03-01';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11');
//curl_setopt($ch, CURLOPT_POST, 1);
$res = curl_exec($ch);
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($res,true);
return $res;
引用:https://www.it610.com/article/1282052778855776256.htm