在 php 中获得来自 SOAP 的响应
Getting response from SOAP in php
我正在尝试使用 php.Actually 中使用 SOAP 的 Web 服务进行响应,其已付费 API 提前预订 flights.I 我的问题有两种情况,在两种情况下我都没有得到响应正确。
这是代码
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: Parsing WSDL: Couldn't find in 'http://59.162.33.102/ArzooWS/services/DOMFlightAvailability'
案例 2
$url=http://59.162.33.102/ArzooWS/services/DOMFlightAvailability?wsdl
在这种情况下也不例外,我将得到 __getFunctions()
的输出,但响应是
invalid XML format
我已经联系了 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=
我认为您的 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 table 中打印数据,因为响应是一个多维数组。
检查 How to create a HTML Table from a PHP array? 以了解如何解析数组以打印 HTML table.
根据 WSDL,in0
应该是 string
:
<wsdl:message name="getAvailabilityRequest">
<wsdl:part name="in0" type="xsd:string"></wsdl:part>
</wsdl:message>
既然 WSDL 没有描述它,您是怎么想出这样的 XML 的?您是否有此服务的任何其他文档?
这是 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;
?>
我正在尝试使用 php.Actually 中使用 SOAP 的 Web 服务进行响应,其已付费 API 提前预订 flights.I 我的问题有两种情况,在两种情况下我都没有得到响应正确。
这是代码
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: Parsing WSDL: Couldn't find in 'http://59.162.33.102/ArzooWS/services/DOMFlightAvailability'
案例 2
$url=http://59.162.33.102/ArzooWS/services/DOMFlightAvailability?wsdl
在这种情况下也不例外,我将得到 __getFunctions()
的输出,但响应是
invalid XML format
我已经联系了 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=
我认为您的 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 table 中打印数据,因为响应是一个多维数组。 检查 How to create a HTML Table from a PHP array? 以了解如何解析数组以打印 HTML table.
根据 WSDL,in0
应该是 string
:
<wsdl:message name="getAvailabilityRequest">
<wsdl:part name="in0" type="xsd:string"></wsdl:part>
</wsdl:message>
既然 WSDL 没有描述它,您是怎么想出这样的 XML 的?您是否有此服务的任何其他文档?
这是 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;
?>