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

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改