与 php Sabre Soap API 集成,用于酒店


Integrating with php Sabre Soap API for hotels

从这里开始执行 Sabre 身份验证过程

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

想要使用 php 获取 sabre 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中与sabre进行交流,请帮我找到它

这个问题已经有几个月了,但也许我的答案可能仍然有用。

我已经成功地使用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) 许多 Sabre SOAP API 调用要求您先创建会话。因此,这通常需要使用 SessionCreateRQ 发出 SOAP 请求,之后您可以对所需的操作进行另一个 SOAP 调用,然后向 SessionCloseRQ 发出另一个 SOAP 请求以关闭会话。每个 SOAP 请求都需要正确设置完整的标头和有效负载,这可能有点痛苦,但这是必需的流程。

我希望这有所帮助!