我正在尝试实施亚马逊MWS API。当我调用特定的URL时,我得到以下错误
The request signature we calculated does not match the signature you provided.
Check your AWS Secret Access Key and signing method
我已经尝试了所有可能的Stackoverflow解决方案和其他一些但我无法解决此问题。这是我的PHP代码
$param = array();
$param['AWSAccessKeyId'] = 'AKIAJ76NICWXXXXXXXXX';
$param['Action'] = 'GetReportRequestList';
$param['SellerId'] = 'A4XLZYW8XXXXX';
$param['SignatureMethod'] = 'HmacSHA256';
$param['SignatureVersion'] = '2';
$param['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version'] = '2011-10-01';
$param['MarketplaceId'] = 'A2EUQ1WTGCTBG2';
$url = array();
foreach ($param as $key => $val) {
$key = str_replace("%7E", "~", rawurlencode($key));
$val = str_replace("%7E", "~", rawurlencode($val));
$url[] = "{$key}={$val}";
}
uksort($url, 'strcmp');
$arr = implode('&', $url);
$sign = 'POST' . "\n";
$sign .= 'mws.amazonservices.com' . "\n";
$sign .= $arr;
$signature = hash_hmac("sha256", $sign, "+vWJ/hISrN2IyRMnaTHTaXXXXXXXX");
$link = "https://mws.amazonservices.com?";
$link .= $arr . "&Signature=" . urlencode(base64_encode($signature));
答案 0 :(得分:1)
未经测试。我在修改参数之前修改了代码以进行排序,并在指定RFC3986编码时将str_replace / rawurlencode替换为http_build_query。希望这对你有用
$param = array();
$param['AWSAccessKeyId'] = 'AKIAJ76NICWXXXXXXXXX';
$param['Action'] = 'GetReportRequestList';
$param['SellerId'] = 'A4XLZYW8XXXXX';
$param['SignatureMethod'] = 'HmacSHA256';
$param['SignatureVersion'] = '2';
$param['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version'] = '2011-10-01';
$param['MarketplaceId'] = 'A2EUQ1WTGCTBG2';
uksort($param, 'strcmp');
$sign = "POST\nmws.amazonservices.com\n/\n" . http_build_query($param, '', '&', PHP_QUERY_RFC3986);
$signature = base64_encode(hash_hmac("sha256", $sign, "+vWJ/hISrN2IyRMnaTHTaXXXXXXXX", true));
$param['Signature'] = $signature;
$ctx = stream_context_create([
"http" => [
"method" => "POST",
"header" => "Content-type: application/x-www-form-urlencoded\r\n\r\n",
"content" => http_build_query($param)
]
]);
$result = file_get_contents("https://mws.amazonservices.com/?", false, $ctx);
编辑: 这是亚马逊MWS文档的link。第16页描述了签名过程并解释了我的修改。
答案 1 :(得分:0)
这是解决方案。
msdeploy.exe