代码如下:
$time=time();
$nonce=rand();
$secretId = "AKIDZEm5IR1lCXnemqsaGtQp6WTChx0psjHb";
$secretKey = "GG1YqujkPRFtKYWLdi9LJ4bss9D2cy71";
$param["Nonce"] = $nonce;
$param["Timestamp"] = $time;
$param["SecretId"] = $secretId;
$param["Action"] = "SearchMedia";
$param["Version"] = "2018-07-17";
ksort($param);
$signStr = "GETvod.tencentcloudapi.com/?";
foreach ( $param as $key => $value ) {
$signStr = $signStr . $key . "=" . $value . "&";
}
$signStr = substr($signStr, 0, -1);
$signature = base64_encode(hash_hmac("sha1", $signStr, $secretKey, true));
$param["Signature"]=urlencode($signature);
$result=$this->postData('https://vod.tencentcloudapi.com/',$param);
postData代码如下:
function postData($url,$data,$header=array()) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
if (count($header)) {
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
if (is_array($data)) {
curl_setopt($ch, CURLOPT_POST, 1);
if(count($data)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}else{
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data,JSON_FORCE_OBJECT));
}
}
$res = curl_exec($ch);
// print_r(json_encode(curl_getinfo($ch)));die();
curl_close($ch);
return $res;
}
始终返回{"Response":{"Error":{"Code":"AuthFailure.SignatureFailure","Message":"The provided credentials could not be validated. Please check your signature is correct."},"RequestId":"a80355e8-ea69-465f-a3c4-b2ed46e1b757"}}
必传参数都传了啊,请问到底是什么地方错了呢,请大神帮忙一下,非常感谢!
相似问题