几天以来,我正尝试通过php和php中的Amazon MWS更新Amazon上的库存量(不使用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

提交提要时,MWS会给您提供FeedSubmissionId,通过它您可以跟踪提要发生了什么。

如果转到MWS Scratchpad,则可以获取提要结果。
在“身份验证”表单中输入所需的凭据,然后选择 feed 作为Sezione AP,选择 GetFeedSubmissionResult 作为Operation。

然后将要求您提供您已经拥有的FeedSubmissionId。
看看该Feed发生了什么,为什么会失败?

您正在传递Marketplace Ids,这意味着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;

关于php - MWS提要php中的更新数量-亚马逊,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41161531/

10-11 10:22