dongping4901
2018-08-18 16:30 阅读 364

使用PHP从亚马逊MWS API获取订单数据

I am Trying to access the Orders Data of a seller using Amazon MWS api
I have followed the documentation and Downloaded the PHP client library for Orders API.
When i use the amazon scratchpad using the same information i get the proper list of orders in XML, but when i try to do this using PHP client library i don't get any XML output, instead i get plain string.

CODE

  #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
");
        echo ("====================================================
");

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

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

On running this script the output i get is:

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条回答 默认 最新

  • 已采纳
    duanliaolan6178 duanliaolan6178 2018-08-18 16:44

    You Mock service is overriding the production service instance. See the duplicate.

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

    remove the 2nd $service and test, please

    点赞 评论 复制链接分享

相关推荐