我最近遇到了amazon lookupitem搜索API的问题。以前工作在一个脚本中我已经成功执行了数百个请求,但现在我不知道是什么问题这是我的Amazon.php
class Amazon
{
// public key
var $publicKey = "[public key]";
// private key
var $privateKey = "[private key]";
// affiliate tag
var $affiliateTag = 'affiliateTag';
/**
* @param $param
* @return mixed
*/
public function generateSignature($param)
{
// url basics
$signature['method'] = 'GET';
$signature['host'] = 'ecs.amazonaws.' . $param['region'];
$signature['uri'] = '/onca/xml';
// necessary parameters
$param['Service'] = "AWSECommerceService";
$param['AWSAccessKeyId'] = $this->publicKey;
$param['Timestamp'] = gmdate("Y-m-d\TH:i:s\Z");
$param['Version'] = '2009-10-01';
ksort($param);
foreach ($param as $key => $value) {
$key = str_replace("%7E", "~", rawurlencode($key));
$value = str_replace("%7E", "~", rawurlencode($value));
$queryParamsUrl[] = $key . "=" . $value;
}
// glue all the "params=value"'s with an ampersand
$signature['queryUrl'] = implode("&", $queryParamsUrl);
// we'll use this string to make the signature
$StringToSign = $signature['method'] . "\n" . $signature['host'] . "\n" . $signature['uri'] . "\n" . $signature['queryUrl'];
// make signature
$signature['string'] = str_replace("%7E", "~",
rawurlencode(
base64_encode(
hash_hmac("sha256", $StringToSign, $this->privateKey, True
)
)
)
);
return $signature;
}
/**
* @param $params
* @return string
*
*/
public function getSignedUrl($params)
{
$signature = $this->generateSignature($params);
return $signedUrl = "http://" . $signature['host'] . $signature['uri'] . '?' . $signature['queryUrl'] . '&Signature=' . $signature['string'];
}
}
这里是我称之为回复的地方
错误500我们遇到了内部错误。请再试一次。'
$Amazon = new Amazon();
$parameters = array(
"region" => "com",
"AssociateTag" => 'affiliateTag',
'ResponseGroup' => 'Medium',
"Operation" => "ItemLookup",
"SearchIndex" => "Books",
"IdType" => "ISBN",
"ItemId" => $isbn,
);
$queryUrl = $Amazon->getSignedUrl($parameters);
$response = simplexml_load_file($queryUrl);