dongluoqiu0255 2017-07-07 07:39
浏览 39
已采纳

SOAP WSDL - 如何在PHP中为特定方法创建工作调用

I am working on a website that will use some API's and encountered a problem. Could somebody please help me? There is this method called "createOrder", that is killing me. It is used to create order at a supplier, as follows:

$id=$_POST['varname'];
echo $id;
$ilosc=$_POST['ilosc'];
echo "</br> Zamawiana ilosć to :";
echo $ilosc;
$orderInfo = $client->createOrder( 
array( 

    'description'=> 'OPIS',
    'clientNr' => '025537',
    'type' => 'FV_ZBIORCZA',
    'transport' =>'AD',
    'positions' => array(


    'id'=>$id,
    'count'=>$ilosc

    )

  ) ) ;

var_dump($orderInfo);

The problem is that it doesn't pass the "positions". It only creates a blank order (with these four first parameters). The problem is in my opinion that these "positions" block is designed to handle more than one item, so it has to be written in some different way.

Here is SOAP UI code for some help. It works with only "id" and "count" filled in (and api_keys as well of course) :

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://katalog.adpolska.pl/ws/api/1.0/">
   <soapenv:Header>
      <personal_key>?</personal_key>
      <kh_kod>?</kh_kod>
      <api_key>?</api_key>
   </soapenv:Header>
   <soapenv:Body>
      <ns:createOrder>
         <order>
            <!--You may enter the following 5 items in any order-->
            <description>OPIS</description>
            <clientNr>025537</clientNr>
            <type>FV_ZBIORCZA</type>
            <transport>AD</transport>
            <positions>
               <!--Zero or more repetitions:-->
               <item>
                  <!--You may enter the following 4 items in any order-->
                  <productId>
                     <!--You may enter the following 2 items in any order-->
                     <id>824210</id>
                     <index></index>
                  </productId>
                  <count>2</count>
                  <error></error>
                  <errorMessage></errorMessage>
               </item>
            </positions>
         </order>
      </ns:createOrder>
   </soapenv:Body>
</soapenv:Envelope>

Below the example from documentation, but this documentation has so many mistakes that I no longer look at it, and it also isnt working, but gives the idea:

    $orderInfo = $client->__soapCall('createOrder', [
        'order' => [
                'description' =>'myDesc',
                'clientNr' =>'my_cart_nr',
                'type' =>'FV',
                'transport' =>'AD',
                'positions' => [
                        [
                                'id' =>'907972',
                                'count' => 1
                        ],
                        [
                                'id' =>'908015',
                                'count' => 1
                        ]
                ]
        ]
]);

I've also used something like wsdltophp, and extracted structure of this function:

   <?php

Array
(
    [0] => ADStructOrder Object
        (
            [description] => OPIS
            [clientNr] => 025537
            [type] => FV_ZBIORCZA
            [transport] => AD
            [positions] => ADStructArrayOfOrderPosition Object
                (
                    [item] => Array
                        (
                            [0] => ADStructOrderPosition Object
                                (
                                    [productId] => ADStructProductId Object
                                        (
                                            [id] => 823514
                                            [index] =>
                                        )
                                    [count] => 1
                                    [error] =>
                                    [errorMessage] =>
                                )
                        )

                )
        )
?>

Could you please help me to achive working solution? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douhuo1738 2017-07-07 08:20
    关注

    As I see, your data structure should be like as

    <?php
    $productId = [
        'id' => 824210,
        'index' => ''
    ];
    $item = [
        'productId' => $productId,
        'count' => 2,
        'error' => '',
        'errorMessage' => ''
    ];
    $positions = [
        'item' => [$item],
    ];
    $order = [
        'description'=> 'OPIS',
        'clientNr' => '025537',
        'type' => 'FV_ZBIORCZA',
        'transport' =>'AD',
        'positions' => $positions,
    ];
    
    $orderInfo = $client->createOrder($order);
    

    hope it helps

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

报告相同问题?

悬赏问题

  • ¥15 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题