【问题标题】:Not able access SOAP API Access Token无法访问 SOAP API 访问令牌
【发布时间】:2018-04-02 12:25:38
【问题描述】:

我正在我的在线旅行系统中实现 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

【问题讨论】:

    标签: sabre


    【解决方案1】:

    您的代码也无法以某种方式得到响应。我把我的工作代码贴给你了。请替换 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>
    

    【讨论】:

    【解决方案2】:

    你是对的。下面是一个工作代码段。我刚刚在 Postman 中使用它登录了 Sabre。

    <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 和时间戳。在域中,您再次输入 PCC。那应该是“默认”。当我从示例中删除这些元素时,它停止工作,所以我假设这也是您的问题。

    【讨论】:

    • 感谢您的回复,我的soap请求标头中已经有SessionCreateRQ了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 2018-10-10
    • 2017-08-11
    • 1970-01-01
    相关资源
    最近更新 更多