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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题