我正在尝试通过 XML / SOAP 从 Travelports uAPI 获得回复,但我不只是得到任何有用的东西。 print_r
和var_dump
以及echo
都显示Resource id #2
哪些是,但无法继续下去。
我已经尝试过他们的API测试工具来发送XML请求,它运行正常,但却无法让它在PHP中运行。我以前解析过XML但从不发送请求。
代码:
<?php
$CREDENTIALS = '******************';
$message = '
<?xml version="1.0" encoding="utf-16"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<s:Body>
<air:AvailabilitySearchReq TraceId="P107788" AuthorizedBy="User" TargetBranch="P107788" xmlns:air="http://www.travelport.com/schema/air_v23_0" xmlns:com="http://www.travelport.com/schema/common_v20_0">
<com:BillingPointOfSaleInfo OriginApplication="UAPI" />
<air:SearchAirLeg>
<air:SearchOrigin>
<com:Airport Code="SYD" />
</air:SearchOrigin>
<air:SearchDestination>
<com:Airport Code="MEL" />
</air:SearchDestination>
<air:SearchDepTime PreferredTime="2013-12-30" />
</air:SearchAirLeg>
<air:SearchAirLeg>
<air:SearchOrigin>
<com:Airport Code="MEL" />
</air:SearchOrigin>
<air:SearchDestination>
<com:Airport Code="SYD" />
</air:SearchDestination>
<air:SearchDepTime PreferredTime="2014-01-02" />
</air:SearchAirLeg>
<air:AirSearchModifiers>
<air:PreferredProviders>
<com:Provider Code="1P" />
</air:PreferredProviders>
<air:PreferredCarriers>
<com:Carrier Code="QF" />
</air:PreferredCarriers>
</air:AirSearchModifiers>
<com:SearchPassenger Code="ADT" />
<com:SearchPassenger Code="ADT" />
</air:AvailabilitySearchReq>
</s:Body>
</s:Envelope>
';
$auth = $CREDENTIALS; //should base_64_encode() this!
$soap_do = curl_init("https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/Service");
$header = array(
"Content-Type: text/xml;charset=UTF-8",
"Accept: gzip,deflate",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"\"",
"Authorization: Basic $auth",
"Content-length: ".strlen($message),
);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 60);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $message);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true);
curl_exec($soap_do);
print_r($soap_do); echo '<br>';
var_dump($soap_do);
echo '<br>'.$soap_do;
?>
任何让我入门的帮助都会很棒。 :)
答案 0 :(得分:3)
我是Travelport的合作伙伴技术专家,我理解您的挫折感。我们之前对端点的使用和描述一直令人困惑。如果您登录我们的开发人员门户,则会有更新的PHP示例; https://developer.travelport.com/app/developer-network/resource-centre-uapi
最简单的方法是取消选择全部&#39;,然后专门选择&#39;示例代码&#39;。
试一试!
答案 1 :(得分:1)
只需更改
$soap_do = curl_init("https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/Service");
到
$soap_do = curl_init("https://americas-uapi.copy-webservices.travelport.com/B2BGateway/connect/uAPI/AirService");