我们正在尝试访问Amazon MWS Api,但我们就是无法让它工作,我们也不知道为什么。这是我们到目前为止已经尝试过的:
require_once('.config.inc.php');
$base_url = "https://mws.amazonservices.de/Products/2011-10-01";
$method = "POST";
$host = "mws.amazonservices.de";
$uri = "/Products/2011-10-01";
$params = array(
'AWSAccessKeyId' => <our Key>,
'Action' => "GetLowestOfferListingsForASIN",
'SellerId' => <our ID>,
'SignatureMethod' => "HmacSHA256",
'SignatureVersion' => "2",
'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()), //tried this with time()+7200 since our server is 2 hours back but we also accessed mws to get the time used there
'Version'=> "2011-10-01",
'MarketplaceId' => <our MpID>,
'ItemCondition' => 'new',
'ASINList.ASIN.1' => B00NN8LSXY );
// Sort the URL parameters
$url_parts = array();
foreach(array_keys($params) as $key)
$url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));
sort($url_parts);
// Construct the string to sign
$url_string = implode("&", $url_parts);
$string_to_sign = "POST\nmws.amazonservices.de\n/Products/2011-10-01\n" . $url_string;
// 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 = urlencode(base64_encode($signature));
$url = "https://mws.amazonservices.de/Products/2011-10-01" . '?' . $url_string . '&Signature=' . $signature;
$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);
$response = curl_exec($ch);
//$parsed_xml = simplexml_load_string($response);
echo $response;
//return ($parsed_xml);在.config.inc.php文件中,我们添加了所有的密钥和ID+
define('APPLICATION_NAME', '<our Firm>');
define('APPLICATION_VERSION', '1.0');在我们做这一切之前,我们检查了MWS-Scratchpad中的所有东西,但似乎所有东西都在那里(在mws.amazon.de上)工作。
但是我们仍然得到SignatureDoesNotMatch错误代码
<Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message>或者这个错误代码:
<Message>Request signature is for too far in the future. Timestamp date: 2015-05-23T04:54:38.000Z. Currently, 10 percent of requests that are more than 15 minutes in the future will be rejected.</Message>希望有人能帮上忙,我们看过了所有其他的帖子和开发人员指南--似乎没有什么帮助
发布于 2015-06-05 23:58:10
我也有同样的问题(在其他问题中)。
amazon提供的PHP参考和示例中有很深的答案。整件事都是千层面代码的典型例子,读起来就像是对任何地方的程序员的侮辱。
API需要一个HTTP POST,其中包含所有请求数据和用您的密钥进行的签名。数组的排序和url编码标准将字符串更改为sign。
亚马逊希望它是这样排序的:
uksort($params, 'strcmp');忘掉整个$url_parts部分吧,它很混乱。请使用http_build_query(),如下所示:
$url_string = http_build_query($params,'','&',PHP_QUERY_RFC3986);亚马逊需要RFC3986,因此空格被编码为'+',而不是'%20‘。此外,时间戳应如下所示:
'Timestamp' => gmdate("Y-m-d\TH:i:s\\Z", time()),祝好运。
发布于 2016-11-02 05:59:46
当你的机器/服务器的时间不正确时,就会发生这种情况。当我重新启动服务器时,它有时会发生在服务器上。只需设置与时间服务器的同步。
https://stackoverflow.com/questions/30392457
复制相似问题