繁体   English   中英

与酒店的php Saber Soap API集成

[英]Integrating with php Sabre Soap API for hotels

从此处遵循Saber身份验证过程

https://developer.sabre.com/docs/read/soap_basics/Authentication

想要通过php获取saber SOAP API结果,但是使用curl来获取响应存在一些问题,如以下代码所示

$input_xml = '
<?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:ConversationId/>
            <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>IPCC</eb:CPAId>
            <eb:Service eb:type="OTA">SessionCreateRQ</eb:Service>
            <eb:Action>SessionCreateRQ</eb:Action>
            <eb:MessageData>
                <eb:MessageId>1000</eb:MessageId>
                <eb:Timestamp>2001-02-15T11:15:12Z</eb:Timestamp>
                <eb:TimeToLive>2001-02-15T11:15:12Z</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>USERNAME</wsse:Username>
                <wsse:Password>PASSWORD</wsse:Password>
                <Organization>IPCC</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 xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="cid:rootelement" xlink:type="simple"/>
        </eb:Manifest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
    $url = $envUrl;

        //setting the curl parameters.
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
        curl_setopt($ch, CURLOPT_POSTFIELDS,
                    "xmlRequest=" . $input_xml);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
        $data = curl_exec($ch);
        curl_close($ch);

        //convert the XML result into array
        $array_data = json_decode(json_encode(simplexml_load_string($data)), true);

        print_r('<pre>');
        print_r($array_data);
        print_r('</pre>');

$array_data返回任何内容+还尝试在创建会话之前

https://developer.sabre.com/docs/read/soap_apis/session_management/create_session

但是反应是一样的。 我知道在php中有一些与saber通信的好方法,请帮我找到它

这个问题有几个月的历史了,但也许我的回答仍然有用。

我设法成功使用PHP和CURL与Sabre的SOAP API通信。 查看您的代码并与我的代码进行比较,我有一些建议:

1)尝试按以下方式通过SOAP调用传递一些HTTP标头信息(我记得这很重要):

$action = 'SessionCreateRQ'; // Set this to whatever Sabre API action you are calling

$soapXML = $input_xml; // Your SOAP XML

$headers = array( 
   'Content-Type: text/xml; charset="utf-8"', 
   'Content-Length: ' . strlen($soapXML), 
   'Accept: text/xml', 
   'Keep-Alive: 300', 
   'Connection: keep-alive', 
   'Cache-Control: no-cache', 
   'Pragma: no-cache', 
   'SOAPAction: "' . $action . '"'
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapXML);

2)在调用curl_exec之后,请检查以下所有错误,这些错误应有助于调试:

$data = curl_exec($ch);
if(curl_error($ch)) {
    echo "Curl error: " . curl_error($ch);
} else {
    echo $data;
    ...
}

3)许多Saber SOAP API调用要求您首先创建一个会话。 因此,这通常需要使用SessionCreateRQ发出SOAP请求,然后您可以对所需的动作进行另一个SOAP调用,然后再向SessionCloseRQ发出另一个SOAP请求以关闭会话。 每个SOAP请求都需要正确设置完整的标头和有效负载,这有点麻烦,但这是必需的流程。

希望对您有所帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM