1
我在通過我的CodeIgniter中的PHP使用亞馬遜web servise搜索時遇到問題。我得到的InvalidParameter時間戳不是來自服務器的ISO-8601格式響應。但我認爲時間戳並不是問題,因爲我試圖與http://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html中給定的日期格式進行比較,這看起來很好。誰能幫忙?這是我的代碼:Codeigniter或PHP亞馬遜API幫助
$private_key = 'XXXXXXXXXXXXXXXX'; // Took out real secret key
$method = "GET";
$host = "ecs.amazonaws.com";
$uri = "/onca/xml";
$timeStamp = gmdate("Y-m-d\TH:i:s.000\Z");
$timeStamp = str_replace(":", "%3A", $timeStamp);
$params["AWSAccesskeyId"] = "XXXXXXXXXXXX"; // Took out real access key
$params["ItemPage"] = $item_page;
$params["Keywords"] = $keywords;
$params["ResponseGroup"] = "Medium2%2525COffers";
$params["SearchIndex"] = "Books";
$params["Operation"] = "ItemSearch";
$params["Service"] = "AWSECommerceService";
$params["Timestamp"] = $timeStamp;
$params["Version"] = "2009-03-31";
ksort($params);
$canonicalized_query = array();
foreach ($params as $param=>$value)
{
$param = str_replace("%7E", "~", rawurlencode($param));
$value = str_replace("%7E", "~", rawurlencode($value));
$canonicalized_query[] = $param. "=". $value;
}
$canonicalized_query = implode("&", $canonicalized_query);
$string_to_sign = $method."\n\r".$host."\n\r".$uri."\n\r".$canonicalized_query;
$signature = base64_encode(hash_hmac("sha256",$string_to_sign, $private_key, True));
$signature = str_replace("%7E", "~", rawurlencode($signature));
$request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
$response = @file_get_contents($request);
if ($response === False)
{
return "response fail";
}
else
{
$parsed_xml = simplexml_load_string($response);
if ($parsed_xml === False)
{
return "parse fail";
}
else
{
return $parsed_xml;
}
}
P.S. - 就我個人而言,我認爲在對它進行哈希處理時,從$ string_to_sign中產生一些錯誤。