使用PHP从Amazon MWS API获取订单数据

时间:2018-08-18 16:30:16

标签: php xml amazon-web-services api amazon

我正在尝试使用Amazon MWS api访问卖家的订单数据
我已经阅读了文档,并下载了Orders API的PHP客户端库。
当我使用具有相同信息的亚马逊暂存器时,我会获得XML正确的订单列表,但是当我尝试使用PHP客户端库来执行此操作时,我没有得到任何XML输出,而是得到了纯字符串。

代码

  #ListOrdersSample.php   #Page

require_once('.config.inc.php');


$serviceUrl = "https://mws.amazonservices.in/Orders/2013-09-01";

$config = array (
   'ServiceURL' => $serviceUrl,
   'ProxyHost' => null,
   'ProxyPort' => -1,
   'ProxyUsername' => null,
   'ProxyPassword' => null,
   'MaxErrorRetry' => 3,
 );

 $service = new MarketplaceWebServiceOrders_Client(
        AWS_ACCESS_KEY_ID,
        AWS_SECRET_ACCESS_KEY,
        APPLICATION_NAME,
        APPLICATION_VERSION,
        $config);

  $service = new MarketplaceWebServiceOrders_Mock();

 $request = new MarketplaceWebServiceOrders_Model_ListOrdersRequest();
 $request->setSellerId(MERCHANT_ID);
 $request->setCreatedAfter('2018-08-01');

 invokeListOrders($service, $request);

   function invokeListOrders(MarketplaceWebServiceOrders_Interface $service, 
$request)
  {
      try {
        $response = $service->ListOrders($request);

        echo ("Service Response\n");
        echo ("====================================================\n");

        $dom = new DOMDocument();
        $dom->loadXML($response->toXML());
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        echo $dom->saveXML();
        echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");

     } catch (MarketplaceWebServiceOrders_Exception $ex) {
        echo("Caught Exception: " . $ex->getMessage() . "\n");
        echo("Response Status Code: " . $ex->getStatusCode() . "\n");
        echo("Error Code: " . $ex->getErrorCode() . "\n");
        echo("Error Type: " . $ex->getErrorType() . "\n");
        echo("Request ID: " . $ex->getRequestId() . "\n");
        echo("XML: " . $ex->getXML() . "\n");
        echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . 
   "\n");
     }
 }

运行此脚本时,我得到的输出是:

Service Response    
====================================================================== 
String 1969-07-21T02:56:03Z 1969-07-21T02:56:03Z String String 1969-07- 
21T02:56:03Z 1969-07-21T02:56:03Z String String String String String String 
String String String String String String String String String String String 
String String 1 1 String String String String String String String String 
String String String String String String true String String String 1969-07- 
21T02:56:03Z 1969-07-21T02:56:03Z 1969-07-21T02:56:03Z 1969-07-21T02:56:03Z 
true String true true String true 1969-07-21T02:56:03Z true String 
ResponseHeaderMetadata: 

1 个答案:

答案 0 :(得分:2)

您的模拟服务将覆盖生产服务实例。看到重复的东西。

def message_Chat(self):
    text = self.message_box.text()
    self.tedit.append(text)
    self.message_box.clear()

请删除第二笔$ service和测试