dongping4901 2018-08-18 16:30
浏览 488
已采纳

使用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 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#windows#的问题,请各位专家解答!(相关搜索:服务器)
  • ¥30 使用C++实现ATM系统
  • ¥20 求帮,直连能连上oracle12,但是thinkphp6就是报错
  • ¥15 paddleocr运行报错
  • ¥15 怎么用 matlab 设计滞后-超前串联校正网络
  • ¥15 MFC引用C#生成的dll,将dll放置到非exe程序目录,如何操作
  • ¥15 C#创建webservice接口,三方通过多次跳转访问本方服务,获取wsdl文档,wsdl中ip地址为局域网内本机地址而非三方直接访问的地址。
  • ¥15 关于#wireshark#的问题:需要安卓app流量数据集要安卓流量做包序列长度的实验,比如某些流量是在看视频还是在发评论
  • ¥15 Smail语句如何使用判断语句跳过验证卡密界面
  • ¥15 关于#wireshark#的问题:并且能够给数据做标注,如这个流量是在看视频或者是在转账