我正在使用azure rest API來獲取使用PHP的頁面範圍。我下面其餘的API文檔hereAuthenticationFailedServer無法驗證azure中的請求
我無法驗證其餘API,它說
在HTTP請求「6fsdfhyuiz78」中發現的MAC簽名是不一樣的 任何計算出的簽名。服務器使用以下字符串進行簽名 GET
我正在使用下面的代碼來獲取頁面範圍。在傳遞請求標頭時,我在這裏遺漏了一些東西來生成簽名認證簽名的字符串。如果有人能幫助我解決這個問題,那將會很棒。
$date = gmdate('D, d M Y H:i:s \G\M\T');
$account_name = "account name";
$containername = "container name";
$blob = "blobname.vhd";
$mypremiumdisk_ss1 = "2017-09-12V09:15:43.00001Z";
$mypremiumdisk_ss2 = "2017-09-12V09:55:47.00002Z";
$account_key = "account key";
$canonicalizedHeaders = "x-ms-date:$date\nx-ms-version:2015-07-08";
$canonicalizedResource = "/$account_name/$containername/$blob\ncomp:pagelist\nsnapshot:$mypremiumdisk_ss1\nprevsnapshot:$mypremiumdisk_ss2";
$arraysign = array();
$arraysign[] = 'GET'; /*HTTP Verb*/
$arraysign[] = ''; /*Content-Encoding*/
$arraysign[] = ''; /*Content-Language*/
$arraysign[] = ''; /*Content-Length (include value when zero)*/
$arraysign[] = ''; /*Content-MD5*/
$arraysign[] = ''; /*Content-Type*/
$arraysign[] = ''; /*Date*/
$arraysign[] = ''; /*If-Modified-Since */
$arraysign[] = ''; /*If-Match*/
$arraysign[] = ''; /*If-None-Match*/
$arraysign[] = ''; /*If-Unmodified-Since*/
$arraysign[] = ''; /*Range*/
$arraysign[] = $canonicalizedHeaders; /*CanonicalizedHeaders*/
$arraysign[] = $canonicalizedResource; /*CanonicalizedResource*/
$stringtosign = implode("\n", $arraysign);
$signature = 'SharedKey'.' '.$account_name.':'.base64_encode(hash_hmac('sha256', $stringtosign, base64_decode($account_key), true));
$endpoint = 'https://'.$account_name.'.blob.core.windows.net';
echo $url = $endpoint.'/'.$containername.'/'.$blob.'?comp=pagelist&snapshot='.$mypremiumdisk_ss1.'&prevsnapshot='.$mypremiumdisk_ss2;
$headers = [
"x-ms-date:{$date}",
'x-ms-version:2015-07-08',
'Accept:application/json;odata=nometadata',
'Accept-Charset:UTF-8',
"Authorization:{$signature}"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
echo '<pre>';print_r($response);
請編輯您的問題,幷包括2件事:1)'$ stringtosign'輸出和2)響應正文。 –