本文介绍了请与亚马逊API MWS一个签名查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做出卖家亚马逊网络服务(MWS)中的签名请求。
我用一个脚本从这里:
Converting亚马逊MWS暂存器查询API调用

I'm trying to make a signed request for Seller Amazon Web Services (MWS).I'm using a script from here:Converting amazon MWS scratchpad queries to API calls

但我不知道为什么我有一个错误:
我们计算请求签名不匹配您提供的签名。请检查您的AWS访问密钥和签名方法。详细信息请参考服务文档。

But I don't know why I've got an error:"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."

因此​​,这里是我的脚本:

So here is my script:

define ("AWS_ACCESS_KEY_ID", "xxxxx");
define ("MERCHANT_ID", "xxxxx");
define ("MARKETPLACE_ID", "xxxxx");
define ("AWS_SECRET_ACCESS_KEY","xxxxx");

$base_url = "https://mws.amazonservices.fr/Products/2011-10-01";
$method = "POST";
$host = "mws.amazonservices.fr";
$uri = "/Products/2011-10-01";

function amazon_xml($searchTerm) {

$params = array(
'AWSAccessKeyId' => AWS_ACCESS_KEY_ID,
'Action' => "GetLowestOfferListingsForSKU",
'SellerId' => MERCHANT_ID,
'SignatureMethod' => "HmacSHA256",
'SignatureVersion' => "2",
'Timestamp'=> date("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Version'=> "2011-10-01",
'MarketplaceId' => MARKETPLACE_ID,
'Query' => $searchTerm,
'ItemCondition'=> "New",
'ExcludeMe' => "false");


// 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 = str_replace("%7E", "~", implode("&", $url_parts));
$string_to_sign = "POST\nmws.amazonservices.fr\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 = rawurlencode(base64_encode($signature));

$url = "https://mws.amazonservices.fr/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);

return ($parsed_xml);
}

我不明白什么错
如果有人可以帮助....

I don't understand what's going wrong If someone could help....

在此先感谢!

推荐答案

请确保使用卷曲时,设置为GET的方法,在上面的例子改变

Make sure that when using cURL you set the method to "GET", in the above example change to

$方法=GET;

和它应该工作。

这篇关于请与亚马逊API MWS一个签名查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:59