dtnwm4807 2014-09-09 01:02
浏览 359

亚马逊MWS PHP标记订单已发货 - 使用XML变量提交订单履行

How to mark an order shipped in Amazon MWS by using an XML feed - using the correct endpoint, service, version and headers?

This was the question, and it took me 3 days to manage it since amazon api is extremely chaotic, documentation is medieval, and most critical information like proper endpoint addresses to submit any particular information is a mystery to find. I was only able to create it by imitating a request at scratchpad, randomly testing sections, combining the examples for other requests for totally different sections and actions. Submitting XML feeds is the only way to manage your orders currently.

So, this may help someone.

  • 写回答

1条回答 默认 最新

  • doubi1797 2014-09-09 01:02
    关注

    I was able to make below simple code work :

                            $param = array();
                            $param['AWSAccessKeyId']   = 'YOURKEY'; 
                            $param['Action']           = 'SubmitFeed'; 
                            $param['Merchant']         = 'YOURMERCHANTID'; 
                            $param['FeedType']         = '_POST_ORDER_FULFILLMENT_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['MarketplaceId.Id.1']    = 'MARKETPLACEID';
                            $param['PurgeAndReplace']    = 'false';
    
                            $secret = 'YOURSECRETKEY';
    
                            $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"?>
                                <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
                                <Header>
                                <DocumentVersion>1.01</DocumentVersion>
                                <MerchantIdentifier>YOURMERCHANTID</MerchantIdentifier>
                                </Header>
                                <MessageType>OrderFulfillment</MessageType>
                                <Message>
                                <MessageID>1</MessageID>
                                <OrderFulfillment>
                                <AmazonOrderID>YOUROWNORDERIDHERE</AmazonOrderID>
                                <FulfillmentDate>'.$param['Timestamp'].'</FulfillmentDate>
                                <FulfillmentData>
                                <CarrierName>TRACKINGCONAMEHERE</CarrierName>
                                <ShippingMethod>TRACKINGCONAMEORMETHODHERE</ShippingMethod>
                                <ShipperTrackingNumber>TRACKINGNOHERE</ShipperTrackingNumber>
                                </FulfillmentData>
                                </OrderFulfillment>
                                </Message>
                                </AmazonEnvelope>';
    
    
                            sort($url);
    
                            $arr   = implode('&', $url);
    
                            $sign  = 'POST' . "
    ";
                            $sign .= 'mws.amazonservices.com' . "
    ";
                            $sign .= '/Feeds/'.$param['Version'].'' . "
    ";
                            $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[]   =   'Expect:';
                            $httpHeader[]   =   'Accept:';              
    
                            $signature = urlencode(base64_encode($signature));
    
                            $link  = "https://mws.amazonservices.com/Feeds/".$param['Version']."?";
                            $link .= $arr . "&Signature=" . $signature;
                            echo '<br>';
                            echo($link); //for debugging - you can paste this into a browser and see if it loads.
                            echo '<br>';
                            $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);
                            curl_close($ch);
    

    Gives the below output :

    <?xml version="1.0"?><SubmitFeedResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/">SubmitFeedResult>FeedSubmissionInfo>FeedSubmissionId>XXXXXXXXXXXXXXXXXXX</FeedSubmissionId><FeedType>_POST_ORDER_FULFILLMENT_DATA_</FeedType><SubmittedDate>2014-09-09T00:36:29+00:00</SubmittedDate><FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus></FeedSubmissionInfo>/SubmitFeedResult>ResponseMetadata>RequestId>XXXXXXXXXXXXXXXXXXX</RequestId></ResponseMetadata></SubmitFeedResponse><?xml version="1.0"?><SubmitFeedResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/"><SubmitFeedResult><FeedSubmissionInfo><FeedSubmissionId>XXXXXXXXXXXXXXXXXXX</FeedSubmissionId>FeedType>_POST_ORDER_FULFILLMENT_DATA_</FeedType><SubmittedDate>2014-09-09T00:36:29+00:00</SubmittedDate>FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus></FeedSubmissionInfo>/SubmitFeedResult>ResponseMetadata>RequestId>XXXXXXXXXXXXXXXXXXX</RequestId></ResponseMetadata></SubmitFeedResponse>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题