我在我的在线旅游系统中实施SOAP API,我正在尝试使用 curl request 获取 SOAP API访问令牌。
我已按照本文https://developer.sabre.com/resources/getting_started_with_sabre_apis/how_to_get_a_token#3sub4使用 PCC编号 “s6ci”获取SOAP API访问令牌,但是当我运行该代码时,我变空了响应。
请你检查一下,让我知道我在做错了什么?
以下是我使用soap api时使用的代码。
$environment = 'https://api.test.sabre.com';
// request string
$request = '<?xml version="1.0" encoding="utf-8"?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<soap-env:Header>
<eb:MessageHeader soap-env:mustUnderstand="1" eb:version="1.0">
<eb:From>
<eb:PartyId />
</eb:From>
<eb:To>
<eb:PartyId />
</eb:To>
<eb:CPAId>s6ci</eb:CPAId>
<eb:ConversationId>V1@280b16ec-5eac-46c0-893f-c88f8e8cb632@310b16ec-5dad-46c0-893f-c88f8e8cb643@780b16ec-5eac-46c0-893f-c88f8e8cb699</eb:ConversationId>
<eb:Service>SessionCreateRQ</eb:Service>
<eb:Action>SessionCreateRQ</eb:Action>
<eb:MessageData />
</eb:MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
<wsse:UsernameToken>
<wsse:Username>MyUsername</wsse:Username>
<wsse:Password>MyPassword</wsse:Password>
<Organization>s6ci</Organization>
<Domain />
</wsse:UsernameToken>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
<eb:Manifest soap-env:mustUnderstand="1" eb:version="1.0">
<eb:Reference xlink:href="cid:rootelement" xlink:type="simple" />
</eb:Manifest>
<SessionCreateRQ>
<POS>
<Source PseudoCityCode="s6ci" />
</POS>
</SessionCreateRQ>
<ns:SessionCreateRQ xmlns:ns="http://www.opentravel.org/OTA/2002/11" />
</soap-env:Body>
</soap-env:Envelope>
';
//initialize curl request
$ch = curl_init($environment);
$headers = array(
'Content-Type: text/xml; charset=utf-8',
'Accept: text/xml',
"Content-Length: " . strlen($request)
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
// print response
echo 'Token '.$result;
exit;
$doc = new DOMDocument();
$doc->loadXML($result);
curl_close($ch);
return json_decode($result);
等待您的回复。
谢谢。 艾米T
答案 0 :(得分:0)
无论如何都无法获得代码回复。我粘贴了你的工作代码。请更换XXXX(根据有多少个字符来取代它们来自/它们是什么)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Header>
<eb:MessageHeader SOAP-ENV:mustUnderstand="1" eb:version="1.0">
<eb:From>
<eb:PartyId type="urn:x12.org:IO5:01">999999</eb:PartyId>
</eb:From>
<eb:To>
<eb:PartyId type="urn:x12.org:IO5:01">123123</eb:PartyId>
</eb:To>
<eb:CPAId>XXXX(PCC)</eb:CPAId>
<eb:ConversationId>SWS-Test-Y8BI</eb:ConversationId>
<eb:Service eb:type="OTA">SessionCreateRQ</eb:Service>
<eb:Action>SessionCreateRQ</eb:Action>
<eb:MessageData>
<eb:MessageId>1000</eb:MessageId>
<eb:Timestamp>2012-06-07T10:00:00</eb:Timestamp>
<eb:TimeToLive>2013-06-06T23:59:59</eb:TimeToLive>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
<wsse:UsernameToken>
<wsse:Username>XXXXXX(Uname)</wsse:Username>
<wsse:Password>XXXXXXXX(PW)</wsse:Password>
<Organization>XXXX(PCC)</Organization>
<Domain>DEFAULT</Domain>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<SessionCreateRQ>
<POS>
<Source PseudoCityCode="XXXX(PCC)"/>
</POS>
</SessionCreateRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
答案 1 :(得分:0)
你说得对。以下是工作代码段。我刚刚在Postman中使用这个登录Saber。
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<soap-env:Header>
<eb:MessageHeader soap-env:mustUnderstand="1" eb:version="1.0">
<eb:From>
<eb:PartyId/>
</eb:From>
<eb:To>
<eb:PartyId/>
</eb:To>
<eb:CPAId>XXXX(PCC)</eb:CPAId>
<eb:ConversationId>SWS-Test-Y8BI</eb:ConversationId>
<eb:Service>SessionCreateRQ</eb:Service>
<eb:Action>SessionCreateRQ</eb:Action>
<eb:MessageData>
<eb:MessageId>mid:20001209-133003-2333@clientofsabre.com</eb:MessageId>
<eb:Timestamp>2018-04-04T022:58:31Z</eb:Timestamp>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
<wsse:UsernameToken>
<wsse:Username>XXXXXX(Uname)</wsse:Username>
<wsse:Password>XXXXXXXX(PW)</wsse:Password>
<Organization>XXXX(PCC)</Organization>
<Domain>DEFAULT</Domain>
</wsse:UsernameToken>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
<eb:Manifest soap-env:mustUnderstand="1" eb:version="1.0">
<eb:Reference xlink:href="cid:rootelement" xlink:type="simple" />
</eb:Manifest>
<SessionCreateRQ>
<POS>
<Source PseudoCityCode="XXXX(PCC)" />
</POS>
</SessionCreateRQ>
<ns:SessionCreateRQ xmlns:ns="http://www.opentravel.org/OTA/2002/11" />
</soap-env:Body>
</soap-env:Envelope>
在您的示例中,您在MessageData下缺少MessageID和Timestamp。在域中,您再次进入PCC。这应该是“默认”。当我从我的例子中取出这些元素时它停止了工作,所以我假设这也是你的问题。