当ORDER元素作为单个元素作为数组或对象提交时,以下Soap Request起作用,但是我需要具有多个ORDER元素。我现在正在尝试SoapParam / SoapVar,但是一点都不走运。尝试在这一点上工作的日子。谢谢大家的时间!
.myEm[style="height: 0px"] {
border: 1px solid red;
}
产生一个对象:
function SendOrder($wan, $param) {
$url = "someurl";
$options = array(
"trace" => 1,
"exceptions" => 1,
"cache_wsdl" => WSDL_CACHE_NONE
);
try {
$client = new SoapClient($url, $options);
$xmlR = $client->ORDER($param);
//create a usable array
$json = json_encode($xmlR);
$array = json_decode($json,true);
dump($client->__getLastRequestHeaders());
dump($client->__getLastRequest());
dump($client->__getLastResponseHeaders());
dump($client->__getLastResponse());
return $array;
} catch (\Exception $e) {
return $e;
}
};
$param = new stdClass;
$param->REQUESTUNIQUEID = uniqid();
$person = 0;
$a = 0;
$orders = new stdClass;
foreach ($_SESSION['cartR'] as $c) {
$person++;
$menu_item = new stdClass;
$menu_item->PERSON = array('_' => "{$c->for_who}", 'NUMBER' => $person);
$menu_item->SERVICETIME = $service_time;
$menu_item->MENUITEM = array('_' => '', 'ID' => $c->product_id);
$menu_item->QUANTITY = 1;
$menu_item->PRICE = $c->price;
$menu_item->TOPPINGPART = "Whole";
$menu_item->ITEMLEVEL = 0;
$menu_item->POSWINDOW = array('_' => 'test', 'ID' => "");
$orders->MENUTIEM = $menu_item;
$param->ORDERS[] = $orders;
unset($menu_item);
}
$result = SendOrder($wan, $param);
我尝试了Stack OVerflow 3617398和其他一些建议。我正在尝试SoapVar和SoapParam完全没有成功,甚至没有收到对最少必需元素的精简要求。
在这种情况下,如何使用具有相同名称的多个元素正确创建/格式化对象?
与阵列的结果:
object(stdClass)#26 (13) {
["REQUESTUNIQUEID"]=>
string(13) "5c829ff8197fb"
["ORDERS"]=>
array(5) {
[0]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
[1]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
[2]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
[3]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
[4]=>
object(stdClass)#26 (1) {
["MENUTIEM"]=>
object(stdClass)#39 (6) {
["PERSON"]=>
array(2) {
["_"]=>
string(0) ""
["NUMBER"]=>
int(5)
}
["SERVICETIME"]=>
string(20) "0001-01-01T00:00:00Z"
["MENUITEM"]=>
array(2) {
["_"]=>
string(0) ""
["ID"]=>
int(8001)
}
["QUANTITY"]=>
int(1)
["PRICE"]=>
string(4) "2.50"
["ITEMLEVEL"]=>
int(0)
}
}
}
}
SOAPVAR和SOAPPARAM(我正在尝试使用SoapParam和SoapVar的不同组合,并使用与上述相同的url和相同选项的最小必需元素)
"
string(229) "HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/10.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 08 Mar 2019 18:57:11 GMT
Content-Length: 671
"
string(671) "5c82bb00d12a1 Web Service 27.4.3.320 Error false 0"
响应:
$unique_id = uniqid();
$client_software = new stdClass;
$client_software->SOFTWARENAME = 'company name';
$client_software->SOFTWAREAPIVERSION = 1;
$client_software->SOFTWARECODEVERSION = "1.0.0.0"
$client = new SoapClient($url, $options);
$xmlR = $client->CHECKIMPORT(
new SoapParam(new SoapVar($unique_id, XSD_STRING), 'REQUESTUNIQUEID'),
new SoapParam(new SoapVar($client_software, SOAP_ENC_OBJECT), 'CLIENTSOFTWARE'),
);
WSDL树
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/10.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 08 Mar 2019 19:06:03 GMT
Content-Length: 868
"
string(868) "Web Service 27.4.3.320 REQUESTUNIQUEID is missing. CLIENTSOFTWARE is missing. false 0