php 中的 MWS Feeds 更新数量 - 亚马逊

MWS Feeds Update Quantities in php - Amazon

这几天我试图通过 php 和 php 中的亚马逊 MWS 更新亚马逊上的库存数量(不使用 MWS API,因为我认为它们已经过时了)

这是我的代码:

$param = array();
    $param['AWSAccessKeyId']     = $this->CHIAVE_ACCESSO;
    $param['Action']             = 'SubmitFeed';
    $param['Merchant']           = $this->SELLER_ID;
    $param['FeedType']       = '_POST_INVENTORY_AVAILABILITY_DATA_';
    $param['SignatureMethod']    = 'HmacSHA256';
    $param['SignatureVersion']   = '2';
    $param['Timestamp']          = gmdate("Y-m-d\TH:i:s.\0\0\0\Z", time());
    $param['Version']            = '2009-01-01';
    $params['MarketplaceId.Id.1'] = $this->MARCKETPLACE_IT;
    $params['MarketplaceId.Id.2'] = $this->MARCKETPLACE_UK;
    $params['MarketplaceId.Id.3'] = $this->MARCKETPLACE_ES;
    $params['MarketplaceId.Id.4'] = $this->MARCKETPLACE_DE;
    $params['MarketplaceId.Id.5'] = $this->MARCKETPLACE_FR;
    $param['PurgeAndReplace']    = 'false';


    foreach ($param as $key => $val) {

        $key = str_replace("%7E", "~", rawurlencode($key));
        $val = str_replace("%7E", "~", rawurlencode($val));
        $url[] = "{$key}={$val}";
    }

    $amazon_feed = '<?xml version="1.0" encoding="utf-8"?>
                    <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
                    <Header>
                    <DocumentVersion>1.01</DocumentVersion>
                    <MerchantIdentifier>' .$this->SELLER_ID. '</MerchantIdentifier>
                    </Header>

                    <MessageType>Inventory</MessageType>
                    <Message>
                    <MessageID>1</MessageID>
                    <OperationType>Update</OperationType>
                    <Inventory>
                    <SKU>'.$sku.'</SKU>
                    <Quantity>'.$qty.'</Quantity>
                    </Inventory>
                    </Message>
                    </AmazonEnvelope>';

    sort($url);

    $arr   = implode('&', $url);

    $sign  = 'POST' . "\n";
    $sign .= 'mws.amazonservices.it' . "\n";
    $sign .= '/Feeds/'.$param['Version'].'' . "\n";
    $sign .= $arr;

    $signature      = hash_hmac("sha256", $sign, $this->secretKey, true);
    $httpHeader     =   array();
    $httpHeader[]   =   'Transfer-Encoding: chunked';
    $httpHeader[]   =   'Content-Type: application/xml';
    $httpHeader[]   =   'Content-MD5: ' . base64_encode(md5($amazon_feed, true));
    //$httpHeader[]   =   'x-amazon-user-agent: MyScriptName/1.0';
    $httpHeader[]   =   'Expect:';
    $httpHeader[]   =   'Accept:';

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

    $link  = "https://mws.amazonservices.it/Feeds/".$param['Version']."?";
    $link .= $arr . "&Signature=" . $signature;

    echo $link;

    $ch = curl_init($link);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
    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);
    $info = curl_getinfo($ch);
    $errors=curl_error($ch);
    curl_close($ch);

    echo '<pre>';
    print_r($response); //xml response

响应是

50691017150_POST_INVENTORY_AVAILABILITY_DATA_2016-12-15T10:00:09+00:00_SUBMITTED_47843855-c5fb-4db9-bc3c-1ccd0aff4169

但是当我进入亚马逊库存时,我看不到任何变化。我也试过等几天,但没有任何变化。 我做错了什么?

在此先感谢您的帮助!

使用 MWS Scratchpad 我遇到的错误如下

<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
    <DocumentVersion>1.02</DocumentVersion>
    <MerchantIdentifier>A2PDC8GCZHAL2D</MerchantIdentifier>
</Header>
<MessageType>ProcessingReport</MessageType>
<Message>
    <MessageID>1</MessageID>
    <ProcessingReport>
        <DocumentTransactionID>50691017150</DocumentTransactionID>
        <StatusCode>Complete</StatusCode>
        <ProcessingSummary>
            <MessagesProcessed>1</MessagesProcessed>
            <MessagesSuccessful>0</MessagesSuccessful>
            <MessagesWithError>1</MessagesWithError>
            <MessagesWithWarning>0</MessagesWithWarning>
        </ProcessingSummary>
        <Result>
            <MessageID>1</MessageID>
            <ResultCode>Error</ResultCode>
            <ResultMessageCode>13013</ResultMessageCode>
            <ResultDescription>This SKU does not exist in the Amazon.com catalog. Your inventory data was not processed. For reasons why, and help fixing this, see http://sellercentral.amazon.it/gp/errorcode/13013</ResultDescription>
            <AdditionalInfo>
                <SKU>887235757035</SKU>
            </AdditionalInfo>
        </Result>
    </ProcessingReport>
</Message>

但是这个 sku 存在于我的目录中

实际响应总是来自 MWS XML,您可以在其中看到 50691017150 实际上是您的 FeedSubmissionId

当您提交 Feed 时,MWS 会返回一个 FeedSubmissionId,您可以通过它跟踪您的 Feed 发生了什么。

如果您转到MWS Scratchpad,您可以获得提要结果。
Authentication 表单和 select feed 作为 Sezione AP 和 GetFeedSubmissionResult 作为操作.

您将被要求提供您已有的 FeedSubmissionId。 看看那个提要发生了什么,为什么失败了?

您正在传递市场 ID,这意味着 sku 在那里可用。但是在您的情况下,它可能在其中任何一个中都不可用。而 MarketplaceId 是可选的,你可以删除

$params['MarketplaceId.Id.1'] = $this->MARCKETPLACE_IT;
$params['MarketplaceId.Id.2'] = $this->MARCKETPLACE_UK;
$params['MarketplaceId.Id.3'] = $this->MARCKETPLACE_ES;
$params['MarketplaceId.Id.4'] = $this->MARCKETPLACE_DE;
$params['MarketplaceId.Id.5'] = $this->MARCKETPLACE_FR;