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

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

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

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥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,如何解決?