<?php
// 云市场分配的密钥Id
$secretId = 'xxxxxxx';
// 云市场分配的密钥Key
$secretKey = 'xxxxxx';
$source = 'market';
// 签名
$datetime = gmdate('D, d M Y H:i:s T');
$signStr = sprintf("x-date: %s\nx-source: %s", $datetime, $source);
$sign = base64_encode(hash_hmac('sha1', $signStr, $secretKey, true));
$auth = sprintf('hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"', $secretId, $sign);
// 请求方法
$method = 'POST';
// 请求头
$headers = array(
'X-Source' => $source,
'X-Date' => $datetime,
'Authorization' => $auth,
);
// 查询参数
$queryParams = array (
);
// body参数(POST方法下)
$bodyParams = array (
'photoFirstBase64' => '',
'photoFirstUrl' => 'https://www.xxx.com/pic/test1.jpg',
'photoSecondBase64' => '',
'photoSecondUrl' => 'https://www.xxx.com/pic/test3.jpg',
);
// url参数拼接
$url = 'https://service-nt7uxbtv-1305308687.sh.apigw.tencentcs.com/release/two-face/compare';
if (count($queryParams) > 0) {
$url .= '?' . http_build_query($queryParams);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//避免https 的ssl验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, array_map(function ($v, $k) {
return $k . ': ' . $v;
}, array_values($headers), array_keys($headers)));
if (in_array($method, array('POST', 'PUT', 'PATCH'), true)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($bodyParams));
}
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo "Error: " . curl_error($ch);
} else {
echo '<pre>';
var_dump(json_decode($data,true));
}
curl_close($ch);
返回值
json {"data":{"confidence":0.8298543095588684},"msg":"成功","success":true,"code":200,"taskNo":"26617750956684274266","charge":true}
数组