【问题标题】:Amazon Submit Feed Error亚马逊提交 Feed 错误
【发布时间】:2014-10-01 09:49:05
【问题描述】:

我想使用Feed Api->Sumbit Feed (_POST_INVENTORY_AVAILABILITY_DATA_)更新亚马逊上的数量

这是我的代码:

$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;

但我收到以下回复:-

<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 吗?还是我做错了什么?

quantity.xml 文件正确

更新:-

代码在 Amazon Scratchpad 上完美运行

【问题讨论】:

  • 根据您的代码,您的签名似乎有问题。
  • @hardiksolanki 有什么问题请告诉我
  • 你为什么在你的卷曲中使用两次签名?
  • 您在 $url 变量中传递您的签名,并在您的 curl 后域中传递。
  • 我已经更新了整个代码,请检查

标签: php curl amazon-web-services amazon-mws


【解决方案1】:

亚马逊 AWS 的签名非常善变。 Version 2 要求您使用 RFC 3986 对数据进行编码

添加查询字符串组件(名称-值对,不包括初始问号 (?) 作为 UTF-8 字符,按照 RFC 3986 进行 URL 编码(十六进制字符必须大写)并使用字典字节顺序进行排序。字典字节顺序区分大小写。

您的问题似乎与您的签名编码有关。

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

这不符合 RFC 3986。PHP 有 rawurlencode 来代替。

$signature = rawurlencode(base64_encode($signature));

【讨论】:

    【解决方案2】:

    您的$string_to_sign 似乎缺少作为第三行的 url 的本地部分。在您的情况下,该部分是空的,因此您只需要一个额外的换行符。

    $string_to_sign = "GET\nmws.amazonservices.in\n\n" . $url_string;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-25
      相关资源
      最近更新 更多