[英]SOAP WSDL - How to create working call for specific method in PHP
我正在一個使用某些API的網站上工作,遇到了問題。 有人可以幫我嗎? 有一種叫做“ createOrder”的方法,這使我喪命。 它用於在供應商處創建訂單,如下所示:
$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);
問題是它沒有通過“位置”。 它僅創建一個空訂單(具有這四個第一個參數)。 我認為問題在於這些“位置”塊旨在處理多個項目,因此必須以不同的方式編寫。
這是一些幫助的SOAP UI代碼。 它僅適用於“ id”和“ count”(當然也包括api_keys):
<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>
在文檔示例的下面,但是此文檔有很多錯誤,我不再關注它了,它也不起作用,但是給出了這個主意:
$orderInfo = $client->__soapCall('createOrder', [
'order' => [
'description' =>'myDesc',
'clientNr' =>'my_cart_nr',
'type' =>'FV',
'transport' =>'AD',
'positions' => [
[
'id' =>'907972',
'count' => 1
],
[
'id' =>'908015',
'count' => 1
]
]
]
]);
我還使用過類似wsdltophp的東西,並提取了此函數的結構:
<?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] =>
)
)
)
)
?>
您能幫我獲得可行的解決方案嗎? 提前致謝。
如我所見,您的數據結構應類似於
<?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);
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.