Обновление инвентаря в mws - PullRequest
0 голосов
/ 06 апреля 2020

Когда я обновляю инвентарь в mws с помощью блокнота mws, отклик 59389018358_POST_INVENTORY_AVAILABILITY_DATA_2020-04-06T14: 29: 14 + 00: 00_SUBMITTED_4cff6ad3-c1a8-4210-a879-834e не требуется, но обновление не требуется Проверьте мой код и дайте мне предложение или обновите код в ответе

Код:

    $sku1        = 'S9-02';
    $quantity1   = '30';
    $leadTimeToShip1 = '1';

    //amazon mws credentials
    $amazonSellerId         = 'xxxxxx';
    $amazonMWSAuthToken     = 'xxxxxx';
    $amazonAWSAccessKeyId   = 'xxxxxx';
    $amazonSecretKey        = 'xxxxxx';
    $amazonMarketPlaceId    = 'ATVPDKIKX0DER';

    $param = array();
    $param['AWSAccessKeyId']     = $amazonAWSAccessKeyId;
    $param['Action']             = 'SubmitFeed'; 
    $param['Merchant']           = $amazonSellerId;
    $param['MWSAuthToken']       = $amazonMWSAuthToken; 
    $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'; 
    $param['MarketplaceIdList.Id.1'] = $amazonMarketPlaceId;
    $param['PurgeAndReplace']    = 'false';

    $secret = $amazonSecretKey;

    $url = array();
    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>'.$amazonSellerId.'</MerchantIdentifier>
        </Header>
        <MessageType>Inventory</MessageType>
        <Message>
        <MessageID>1</MessageID>
        <OperationType>Update</OperationType>
        <Inventory>
        <SKU>'.$sku1.'</SKU>
        <Quantity>'.$quantity1.'</Quantity>
        <FulfillmentLatency>'.$leadTimeToShip1.'</FulfillmentLatency>
        </Inventory>
        </Message>
        </AmazonEnvelope>';

    //echo $amazon_feed;exit;
    sort($url);

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

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

    $signature      = hash_hmac("sha256", $sign, $secret, 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.com/Feeds/".$param['Version']."?";
    $link .= $arr . "&Signature=" . $signature;


    $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>';
    echo $response;
    print_r($response); //xml response
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...