首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >调用接口签名错误,请大神帮忙看一下,万分感谢!?

调用接口签名错误,请大神帮忙看一下,万分感谢!?

提问于 2020-03-27 13:50:30
回答 3关注 0查看 725

代码如下:

$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"}}

必传参数都传了啊,请问到底是什么地方错了呢,请大神帮忙一下,非常感谢!

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档