亚马逊提交给错误 [英] Amazon Submit Feed Error
问题描述
我想用更新的亚马逊量订阅API - >透过饲料(_POST_INVENTORY_AVAILABILITY_DATA _)
I want to update quantity on amazon using Feed Api->Sumbit Feed (_POST_INVENTORY_AVAILABILITY_DATA_)
下面是我的code:
$action = 'SubmitFeed';
$path = $_SERVER['DOCUMENT_ROOT'].'/resources/amazon_xml/quantity.xml';
$feed = '<?xml version="1.0" ?><AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>A3QPCC6I4V1QU3</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Inventory>
<SKU>6000013953</SKU>
<Quantity>1</Quantity>
</Inventory>
</Message>
</AmazonEnvelope>';
$feedHandle = fopen($path, 'rw+');
fwrite($feedHandle, $feed);
rewind($feedHandle);
$params = array(
'AWSAccessKeyId' => $data['aws_access_key'],
'Action' => $action,
'Merchant' => $data['merchant_id'],
'SignatureMethod' => "HmacSHA256",
'SignatureVersion' => "2",
'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Version'=> "2009-10-01",
'MarketplaceIdList.Id.1' => $data['marketplace_id'],
'FeedType'=> "_POST_INVENTORY_AVAILABILITY_DATA_",
'PurgeAndReplace'=> 'false',
'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true))
);
// 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 = "GET\nmws.amazonservices.in\n" . $url_string;
// Sign the request
$signature = hash_hmac("sha256", $string_to_sign, $data['aws_secret_key'], TRUE);
// Base64 encode the signature and make it URL safe
$signature = urlencode(base64_encode($signature));
$url = "https://mws.amazonservices.in" . '?' . $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);
//echo $url;exit;
echo '<pre>';
print_r($response);
echo '</pre>';
exit;
不过,我得到如下回应: -
But I am getting following response :-
<ErrorResponse xmlns="https://mws.amazonservices.com/">
<Error>
<Type>Sender</Type>
<Code>SignatureDoesNotMatch</Code>
<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>
</Error>
<RequestID>105f88cb-76e2-49c0-9d33-83d6069dd119</RequestID>
</ErrorResponse>
有人能告诉我如何发送一个XML文件API?还是我做错了什么?
Can somebody please tell me how to send a xml file to api? Or I am doing something wrong ?
quantity.xml
文件是正确的。
更新: -
$ C $,C是运行完美亚马逊便签
推荐答案
亚马逊AWS是很善变其签名。 2版要求您使用的 RFC 3986 以EN code数据
Amazon AWS is very fickle in its signature. Version 2 requires that you use RFC 3986 to encode your data
添加查询字符串组件(名称 - 值对,不包括最初的问号(?)为UTF-8字符,而它们的 URL连接根据RFC 3986 codeD (十六进制字符必须大写)和分类使用词典字节顺序。辞书字节顺序是区分大小写的。
Add the query string components (the name-value pairs, not including the initial question mark (?) as UTF-8 characters which are URL encoded per RFC 3986 (hexadecimal characters must be uppercased) and sorted using lexicographic byte ordering. Lexicographic byte ordering is case sensitive.
您的问题似乎是与你的签名的编码。
Your problem appears to be with your encoding of the signature.
$signature = urlencode(base64_encode($signature));
这将不符合RFC 3986. PHP有 rawurlen $ C $Ç做到这一点吧。
That will not conform to RFC 3986. PHP has rawurlencode to do that instead.
$signature = rawurlencode(base64_encode($signature));
这篇关于亚马逊提交给错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!