我正在尝试使用SOAP中的SOAP响应来自web.Actually其付费API预订航班。我有两个案例我的问题,在这两种情况下我都没有得到正确的响应。
这是代码
try{
$client = new SoapClient($url);
print_r($client->__getFunctions());
$values = $client->getAvailability($input_xml);
print_r($values);
}catch(exception $e){
echo 'error<br>';
echo $e->getMessage();
}
案例1
$url=http://59.162.33.102/ArzooWS/services/DOMFlightAvailability
在这种情况下,我将得到一个例外
SOAP-ERROR:解析WSDL:无法在&#39; http://59.162.33.102/ArzooWS/services/DOMFlightAvailability&#39;
中找到
案例2
$url=http://59.162.33.102/ArzooWS/services/DOMFlightAvailability?wsdl
在这种情况下没有异常我将获得__getFunctions()
的输出,但响应是
无效的XML格式
我已经联系了API服务提供商,他们会说出一切正常运行的信息。 这是xml
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getAvailability xmlns="http://avail.flight.arzoo.com">
<in0>
<Request>
<Origin>BOM</Origin>
<Destination>BLR</Destination>
<DepartDate>2015-05-15</DepartDate>
<ReturnDate>2015-05-20</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>1</ChildPax>
<InfantPax>1</InfantPax>
<Currency>INR</Currency>
<Preferredclass>B</Preferredclass>
<mode>ROUND</mode>
<Clientid>7XXX</Clientid>
<Clientpassword>XX</Clientpassword>
<Clienttype>XXX</Clienttype>
<PreferredAirline>AI,G8,IC,6E</PreferredAirline>
</Request>
</in0>
</getAvailability>
</soapenv:Body></soapenv:Envelope>
更新 以下是仅一次航班的样本回复
20875
7303
130
0
0
0
0
0
0
319
BLR
2015-05-15T07:45:00
BOM
2015-05-15T06:15:00
603
AI
603
0
Air India
3860
http://live.arzoo.com/FlightWS/image/AirIndia.gif
3
Z
13250
Z
6625
Business
mek+yu2iz7Q=
1000
This fare is Non Refundable Booking Class : Z|Cancellation Penalty: All bookings done are subject to cancellation penalty levied by the airlines.<br>In addition to the airlines cancellation penalty, we charge a service fee of Rs. 50 per passenger for all cancellations.|Date Change Penalty: In addition to the airlines date change penalty, we charge a service fee of Rs. 50 per passenger.|
0
0
0
0
3369
74
2150,147,1563
2150,147,1072
0,0,74
0
arzoo11
h/jf17QHSJphWFSOTFWg8tk50VHVm+kKk3MJJ4NqTDo3mXlTqg2QNScTJzH+TWN+pNURIyTJYKOW
O8yH8+0tznjZpdCApJT4KQTfIRJRrTZDwLtSiN0xXggcK2BneoFH2Pr/Vo/CRI/xTgfh9d8ZSmFY
VI5MVaDyYfwphO4fcQEnEycx/k1jftlsnmWWqYGnJxMnMf5NY36YIq2FtLkfcHtsd+IDEhxpxJuT
v4YyS+QnEycx/k1jfv+QxLuqYmdiJxMnMf5NY37/kMS7qmJnYicTJzH+TWN+OT2lxrlMEOeSMz+b
qzlxwlz7VeZtrnP7Hv3jj2fYS5nICxQuxGH6/79fDhZYRaCPuGMF+eC/zteWO8yH8+0tzpu80ORl
KER+BD/GuWW7DZ2bbbGbXj1Z0HOJPC4p49y3JxMnMf5NY377cKnYYdkF4kP854vEBONogwbVnQw0
AohFgCa1qKcQs0PAu1KI3TFezaEuVisWRglDwLtSiN0xXs2hLlYrFkYJQ8C7UojdMV7NoS5WKxZG
CUPAu1KI3TFezaEuVisWRglDwLtSiN0xXtz6IhL3LsgmAeGKrEtqevYnEycx/k1jfuI7TUNwKUQ0
x8cEZXwg6V6nH6TvjNSCRUPAu1KI3TFej7Y1Yu+fHhBzqWDbQb1E1IoDSY1wep73c6lg20G9RNSn
Ux8jbjT6hrp5c9fnhtxFljvMh/PtLc5KhxZKtuH3cJY7zIfz7S3O/SUTzGstO8VofEuXJIOZ0ptt
sZtePVnQqDUuNolYhru/Xw4WWEWgj4D+4B+dOi9iv18OFlhFoI+A/uAfnTovYr9fDhZYRaCPCq4g
JlaBMkdzqWDbQb1E1KdTHyNuNPqGz7rBmgDnrsY=
答案 0 :(得分:3)
我认为您的XML中存在太多信息。
您是否有任何关于如何格式化XML以调用getAvailability()
函数的文档?
在我看来,XML会更像这样:
<Request>
<Origin>BOM</Origin>
<Destination>BLR</Destination>
<DepartDate>2015-05-15</DepartDate>
<ReturnDate>2015-05-20</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>1</ChildPax>
<InfantPax>1</InfantPax>
<Currency>INR</Currency>
<Preferredclass>B</Preferredclass>
<mode>ROUND</mode>
<Clientid>7XXX</Clientid>
<Clientpassword>XX</Clientpassword>
<Clienttype>XXX</Clienttype>
<PreferredAirline>AI,G8,IC,6E</PreferredAirline>
</Request>
要阅读XML响应,请执行以下操作:
$values_array = json_decode(json_encode((array)simplexml_load_string($values)),1);
没有简单的方法在HTML表格中打印数据,因为响应是一个多维数组。 检查How to create a HTML Table from a PHP array?以了解如何解析数组以打印HTML表格。
答案 1 :(得分:0)
根据WSDL,in0
应为string
:
<wsdl:message name="getAvailabilityRequest">
<wsdl:part name="in0" type="xsd:string"></wsdl:part>
</wsdl:message>
你是如何想出这样的XML的,因为WSDL没有描述它?你有这项服务的其他文件吗?
答案 2 :(得分:-1)
这是由arzoo提供的航班可用性代码。 我在使用SOAP CLIENT时也遇到错误但是当我使用nusoap然后他们给我结果..如果你得到像ip / password mismatch这样的错误那么你会调用arzoo来验证你的clientid和clientpassword
<?php
ini_set('max_execution_time','180');
include 'lib/nusoap.php';
$location_URL ='http://avail.flight.arzoo.com';
$action_URL ='http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl';
$Request = '<Request>
<Origin>BOM</Origin>
<Destination>DEL</Destination>
<DepartDate>2017-02-02</DepartDate>
<ReturnDate>2017-02-02</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
<Currency>INR</Currency>
<Clientid>Given by Arzoo.com</Clientid>
<Clientpassword>Given by Arzoo.com</Clientpassword>
<Clienttype>ArzooFWS1.1</Clienttype>
<Preferredclass>E</Preferredclass>
<mode>ONE</mode>
<PreferredAirline>AI</PreferredAirline>
</Request>';
$clientinfo = array('soap_version'=>SOAP_1_1,
'location' =>$location_URL,
'uri' =>$action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
);
$client = new nusoap_client('http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl', $clientinfo);
//print_r($client);
$result = $client->call('getAvailability', array($Request));
echo"<pre>";
print_r($result);
$clientInfo =simplexml_load_string(utf8_encode($result));
$flight = $clientInfo->Response__Depart->OriginDestinationOptions->OriginDestinationOption;
$error =$clientInfo->error__tag;
//echo $error;
var_dump($flight);
//exit;
//echo"<pre>";
//print_r($result);
//ECHO $error;
?>