0
我想在Sinch服務中提出conferenceCallout請求,但我遇到了簽名問題。我粘貼的代碼:授權請求故障
<?php
//JSon Object
$conferencia['method']="conferenceCallout";
$participante['cli']="46000000000";
$destination['type']="username";
$destination['endpoint']="roke1";
$participante['destination']=$destination;
$participante['domain']="mxp";
$participante['custom']="customData";
$participante['locale']="en-US";
$participante['greeting']="Welcome to my conference";
$participante['conferenceId']="conferencia_de_prueba";
$participante["enableDice"]=false;
$conferencia['conferenceCallout']=$participante;
$data=json_encode($conferencia);
$md5_body = base64_encode (MD5 (utf8_encode (json_encode($conferencia))));
$applicationKey="XXXXXX-xXXX-XXXX-XXXX-XXXXXXXX";
$applicationSecret="XXXXXXXXXXXXXXXX==";
$timestamp = new DateTime('NOW');
$StringToSign ="POST
".$md5_body."
application/json
x-timestamp:".$timestamp->format(DateTime::ISO8601)."
/v1/callouts";
$utf8encode=utf8_encode($StringToSign);
$hash= hash_hmac("sha256",$applicationSecret,$utf8encode);
$base64=base64_encode($hash);
$Signature =$base64;
$Autorization = "Application"." ".$applicationKey.":".$Signature;
$ch = curl_init('https://callingapi.sinch.com/v1/callouts');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization:' . $Autorization,
'X-Timestamp: ' . $timestamp->format(DateTime::ISO8601),
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
echo $result;
?>
但我得到錯誤代碼40102是40102-無效簽名。
任何人都可以幫助我嗎?我做錯了什麼?
最好的問候。
看起來你錯過了正在簽名的字符串之間的'\ n'。 \ n「+ CanonicalizedResource;' – drew010
Content-Type +」\ n「嘗試使用\ n和\ r並且不起作用:( – Roke
當base64編碼MD5哈希和HMAC時,您需要編碼原始輸出:'$ md5 = base64_encode(md5($ message,true));''base64_encode hash_hmac('sha256',$ stringToSign,$ applicationSecret,true));' – drew010