尝试在Amazon API上列出产品时SignatureDoesNotMatch

我想知道如果有人可以帮助。

我试图通过API在亚马逊上列出产品。

当使用GetOrders时,它可以很好地工作,但除了参数外,代码类似,使用SubmitFeed时会出现以下错误消息_POST_PRODUCT_DATA_

“发件人SignatureDoesNotMatch我们计算的请求签名与您提供的签名不匹配,请检查您的AWS Secret Access密钥和签名方法,详情请参阅服务文档。

我所有的细节都是正确的,秘密密钥,aws访问密钥等,并且我将字符串与Amazon API测试工具中生成的代码进行了签名进行了比较,它们完全相同,因此我不确定是什么问题是。

这里是我使用的代码 -

$timestamp = date('c', strtotime($todays_date_time));
$timestamp = gmdate('Y-m-dTH:i:sZ', strtotime($timestamp));

$params = array(
    'AWSAccessKeyId' => "MY_AWS_KEY",
    'Action' => "SubmitFeed",
    'Merchant' => "MY_SELLER_ID",
    'FeedType' => "_POST_PRODUCT_DATA_",
    'SignatureMethod' => "HmacSHA256",
    'SignatureVersion' => "2",
    'Timestamp'=> $timestamp,
    'Version'=> "2009-01-01",
    'MarketplaceIdList.Id.1' => "MY_MARKETPLACE_ID",
    'PurgeAndReplace'=>'false'
);

$secret = 'MY_SECRET_KEY';

$url_parts = array();

foreach(array_keys($params) as $key) {

    $url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));

}

然后在这里创建XML并将其存储在变量$ amazon_feed中,然后 -

sort($url_parts);

$url_string = implode("&", $url_parts);
$string_to_sign = "POSTnmws.amazonservices.co.ukn/n" . $url_string;

$signature = hash_hmac("sha256", $string_to_sign, $secret, TRUE);

$http_header     =   array();
$http_header[]   =   'Transfer-Encoding: chunked';
$http_header[]   =   'Content-Type: application/xml';
$http_header[]   =   'Content-MD5: ' . base64_encode(md5($amazon_feed, true));
$http_header[]   =   'Expect:';
$http_header[]   =   'Accept:';

$signature = urlencode(base64_encode($signature));

$link = "https://mws.amazonservices.co.uk/Feeds/2009-01-01?".$url_string."&Signature=".$signature;

$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $amazon_feed); 
$response = curl_exec($ch);

print_r($response);

$info = curl_getinfo($ch);
curl_close($ch);

任何人都可以提供帮助吗?


在你将它们传递给它们之前,你必须把你的参数ksort()

foreach(array_keys($params) as $key) {

    $url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));

}

例如

$params = array(
    'AWSAccessKeyId' => "MY_AWS_KEY",
    'Action' => "SubmitFeed",
    'SellerId' => "MY_SELLER_ID",
    'FeedType' => "_POST_PRODUCT_DATA_",
    'SignatureMethod' => "HmacSHA256",
    'SignatureVersion' => "2",
    'Timestamp'=> $timestamp,
    'Version'=> "2009-01-01",
    'MarketplaceIdList.Id.1' => "MY_MARKETPLACE_ID",
    'PurgeAndReplace'=>'false'
);

$secret = 'MY_SECRET_KEY';
$url_parts = array();
ksort($params);
foreach(array_keys($params) as $key) {

    $url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));

}

我不完全确定你正在签名的字符串,你应该试试这个(添加/ Feeds / 2009-01-01):

"POSTnmws-eu.amazonservices.comn/Feeds/2009-01-01n" . $url_string

此外,Amazon期望SellerId用于_POST_PRODUCT_DATA_操作,而不是Merchant

我建议你使用mws-eu-amazonservices.com而不是co.uk,你可以在所有的欧洲市场中使用它,并且不需要为每个市场改变它。 作为一个注释:

亚马逊并没有真正报告正确的错误。 如果只有SellerId是Merchant像上面那样,或者与您尝试执行的操作无关的任何其他内容,您也会发生错误。

链接地址: http://www.djcxy.com/p/38993.html

上一篇: SignatureDoesNotMatch when attempting to list a product on Amazon API

下一篇: Amazon MWS Scratchpad API