2012-05-27 92 views
0
<?php 
error_reporting(E_ALL); 
ini_set("display_errors", 1); 
$AWS_ACCESS_KEY_ID = "KEY"; 
$AWS_SECRET_ACCESS_KEY = "ACCESS KEY"; 

$base_url = "http://webservices.amazon.com/onca/xml?"; 
$url_params = array('Operation'=>"ItemSearch",'Service'=>"AWSECommerceService", 
'AWSAccessKeyId'=>$AWS_ACCESS_KEY_ID,'AssociateTag'=>"associateTag", 
'Version'=>"2011-08-01",'Availability'=>"Available",'Condition'=>"All", 
'ItemPage'=>"1",'ResponseGroup'=>"Images,ItemAttributes,EditorialReview", 
'Keywords'=>"Amazon"); 

// Add the Timestamp 
$url_params['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()); 

// Sort the URL parameters 
$url_parts = array(); 
foreach(array_keys($url_params) as $key) 
    $url_parts[] = $key."=".$url_params[$key]; 
sort($url_parts); 

// Construct the string to sign 
$string_to_sign = "GET\webservices.amazon.com\n/onca/xml?\n".implode("&",$url_parts); 
$string_to_sign = str_replace('+','%20',$string_to_sign); 
$string_to_sign = str_replace(':','%3A',$string_to_sign); 
$string_to_sign = str_replace(';',urlencode(';'),$string_to_sign); 

// Sign the request 
$signature = hash_hmac("sha256",$string_to_sign,$AWS_SECRET_ACCESS_KEY,TRUE); 

// Base64 encode the signature and make it URL safe 
$signature = base64_encode($signature); 
$signature = str_replace('+','%2B',$signature); 
$signature = str_replace('=','%3D',$signature); 

$url_string = implode("&",$url_parts); 
$url = $base_url.$url_string."&Signature=".$signature; 
print $url; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 

$xml_response = curl_exec($ch); 
echo $xml_response; 
    ?> 

這會返回一個簽名錯誤; 爲什麼?亞馬遜網絡服務簽名錯誤

這是輸出,密鑰和標記替換隱私

http://webservices.amazon.com/onca/xml?AWSAccessKeyId=KEY&AssociateTag=ASSIOCATE TAG &可用性=可用&條件=所有& ItemPage = 1 &關鍵詞=亞馬遜&操作= ItemSearch & ResponseGroup =圖片,ItemAttributes中,EditorialReview &服務= AWSECommerceService &時間戳= 2012-05-27T09:35:43.000Z &版本= 2011-08-01 &簽名= KEVlbW6G9ygvHheTf5m0ymguE64LEaYGDtQZQe0bCLQ%3D

回答

1

不確定您是否仍需要此方面的幫助,但最有可能失敗的原因是您未在呼叫中提供有效的關聯代碼。

'AssociateTag'=>"associateTag" 

所以,你需要將這個值更改爲:

'AssociateTag'=>"(my-assigned-associate-tag)" 

必須使用亞馬遜提供給您的關聯標籤。我認爲關聯標籤通常以數字「20」結尾,但我無法驗證。如果你不知道你的助理標籤,登錄到您的會員帳號在這裏:Amazon affiliate page

...,這將是在頁面的左上角價值「作爲中/跟蹤ID簽名」 。

0

簽名錯誤主要是由於訪問密鑰ID和密鑰ID

請交叉驗證這個ID的不匹配。

的用戶還查看了:聯繫人標籤