gpt4 book ai didi

php - 亚马逊 MWS 错误 SignatureDoesNotMatch

转载 作者:行者123 更新时间:2023-12-01 22:29:05 24 4
gpt4 key购买 nike

我们正在尝试访问亚马逊 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 文件中所有 key 和 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>

希望有人可以帮助我们阅读所有其他帖子和开发人员指南 - 似乎没有任何帮助

最佳答案

我遇到了同样的问题(以及其他)。

Amazon 提供的 PHP 引用和示例中包含了答案。整件事是千层面代码的一个典型例子,读起来像是对各地编码人员的侮辱。

API 需要包含所有请求数据的 HTTP POST 和使用您的 key 制作的签名。数组的排序和 url 编码标准将字符串更改为符号。

Amazon 希望它像这样排序:

uksort($params, 'strcmp');

忘记整个 $url_parts 部分,它很乱。像这样使用 http_build_query() :

$url_string = http_build_query($params,'','&',PHP_QUERY_RFC3986);

Amazon 需要 RFC3986,因此空格被编码为“+”,而不是“%20”。时间戳也应该是这样的:

'Timestamp' => gmdate("Y-m-d\TH:i:s\\Z", time()),

祝你好运。

关于php - 亚马逊 MWS 错误 SignatureDoesNotMatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30392457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com