我正在创建一个网站。在此网站上,我使用SOAP请求来获取响应。首先,我使用cURL发送请求,并得到响应。但是,当我尝试print_r XML响应时,它给了我-
SimpleXMLElement对象()
基本上我想做的是,我想逐行阅读这些XML。可以说我想获取ConversionId。
那么,我该怎么做?
这是我用来发送SOAP请求的函数。
public function authticate(){
$url = 'https://webservices.havail.sabre.com';
$tokengenheaders = array(
'Content-Type: text/xml'
);
$AuthData = '<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>ID45</eb:CPAId>
<eb:ConversationId>IdOfConversion</eb:ConversationId>
<eb:Service>SessionCreate</eb:Service>
<eb:Action>SessionCreate</eb:Action>
<eb:MessageData>
<eb:MessageId>MsgId</eb:MessageId>
<eb:Timestamp>2017-11-27T09: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>Kist</wsse:Username>
<wsse:Password>Kistlak</wsse:Password>
<Organization>FSG</Organization>
<Domain>SN</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="5H7D" />
</POS>
</SessionCreateRQ>
<ns:SessionCreateRQ xmlns:ns="http://www.opentravel.org/OTA/2002/11" />
</soap-env:Body>
</soap-env:Envelope>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://webservices.sabre.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $AuthData); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $tokengenheaders);
curl_setopt($ch, CURLOPT_VERBOSE, false);
$soaptoken = curl_exec($ch);
curl_close($ch);
//$xmlElement = new SimpleXMLElement($soaptoken, LIBXML_NOCDATA);
$xml = simplexml_load_string($soaptoken);
print_r ($xml) ; die();
return $soaptoken;
}
这是XML响应。
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<eb:MessageHeader
xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="1.0" soap-env:mustUnderstand="1">
<eb:From>
<eb:PartyId eb:type="URI"/>
</eb:From>
<eb:To>
<eb:PartyId eb:type="URI"/>
</eb:To>
<eb:CPAId>Id234</eb:CPAId>
<eb:ConversationId>ConversionId</eb:ConversationId>
<eb:Service eb:type="sabreXML">Session</eb:Service>
<eb:Action>SessionCreateRS</eb:Action>
<eb:MessageData>
<eb:MessageId>MsgId</eb:MessageId>
<eb:Timestamp>2019-03-11T09:27:32</eb:Timestamp>
<eb:RefToMessageId>MsgRef</eb:RefToMessageId>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">SecToken</wsse:BinarySecurityToken>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
<SessionCreateRS
xmlns="http://www.opentravel.org/OTA/2002/11" version="1" status="Approved">\t
<ConversationId>ConversionId</ConversationId>
</SessionCreateRS>
</soap-env:Body>
</soap-env:Envelope>
PHP数组响应。
[soap-env_Body] => Array
(
[stl19_GetReservationRS] => Array
(
[@attributes] => Array
(
[Version] => 1.19.0
)
[stl19_Reservation] => Array
(
[@attributes] => Array
(
[numberInParty] => 3
[numberOfInfants] => 1
[NumberInSegment] => 2
)
[stl19_BookingDetails] => Array
(
[stl19_RecordLocator] => XWYBFF
[stl19_CreationTimestamp] => 2019-03-05T02:22:00
[stl19_SystemCreationTimestamp] => 2019-03-05T02:22:00
[stl19_CreationAgentID] => AWS
[stl19_UpdateTimestamp] => 2019-03-05T02:22:06
[stl19_PNRSequence] => 2
[stl19_DivideSplitDetails] => Array
(
)
[stl19_EstimatedPurgeTimestamp] => 2019-08-12T00:00:00
[stl19_UpdateToken] => 3ea61cc7bab6c025877a7014fd52e44ca4a778bc80edab34
)
[stl19_POS] => Array
(
[@attributes] => Array
(
[AirExtras] => false
[InhibitCode] => U
)
[stl19_Source] => Array
(
[@attributes] => Array
(
[BookingSource] => 5H7D
[AgentSine] => AWS
[PseudoCityCode] => 5H7D
[ISOCountry] => LK
[AgentDutyCode] => *
[AirlineVendorID] => AA
[HomePseudoCityCode] => 5H7D
[PrimeHostID] => 1B
)
)
)
[stl19_PassengerReservation] => Array
(
[stl19_Passengers] => Array
(
)
[stl19_Segments] => Array
(
)
[stl19_TicketingInfo] => Array
(
)
[stl19_ItineraryPricing] => Array
(
)
)
[stl19_ReceivedFrom] => Array
(
)
[stl19_EmailAddresses] => Array
(
)
)
[or114_PriceQuote] => Array
(
[PriceQuoteInfo] => Array
(
[Reservation] => Array
(
[@attributes] => Array
(
[updateToken] => eNc:::h3/WwF9UlK9QLSrRp5hEXg==
)
)
[Summary] => Array
(
[NameAssociation] => Array
(
[0] => Array
(
[@attributes] => Array
(
[firstName] => RANGA MR
[lastName] => DASANAYAKA
[nameId] => 1
[nameNumber] => 1.1
)
[PriceQuote] => Array
(
[@attributes] => Array
(
[latestPQFlag] => true
[number] => 1
[pricingStatus] => AUTOPRICED
[pricingType] => S
[status] => A
[type] => PQ
)
[Indicators] => Array
(
[@attributes] => Array
(
[isExpired] => true
)
)
[Passenger] => Array
(
[@attributes] => Array
(
[passengerTypeCount] => 1
[requestedType] => ADT
[type] => ADT
)
)
[ItineraryType] => I
[ValidatingCarrier] => AI
[Amounts] => Array
(
[Total] => 25395
)
[LocalCreateDateTime] => 2019-03-05T13:52:00
)
)
[1] => Array
(
[@attributes] => Array
(
[firstName] => IRUSHA MSTR
[lastName] => HASANTHA
[nameId] => 2
[nameNumber] => 2.1
)
[PriceQuote] => Array
(
[@attributes] => Array
(
[latestPQFlag] => true
[number] => 2
[pricingStatus] => AUTOPRICED
[pricingType] => S
[status] => A
[type] => PQ
)
[Indicators] => Array
(
[@attributes] => Array
(
[isExpired] => true
)
)
[Passenger] => Array
(
[@attributes] => Array
(
[passengerTypeCount] => 1
[requestedType] => CNN
[type] => CNN
)
)
[ItineraryType] => I
[TicketDesignator] => CH25
[ValidatingCarrier] => AI
[Amounts] => Array
(
[Total] => 21695
)
[LocalCreateDateTime] => 2019-03-05T13:52:00
)
)
[2] => Array
(
[@attributes] => Array
(
[firstName] => KISALKA MSTR
[lastName] => I/1RAJAPAKSE
[nameId] => 3
[nameNumber] => 3.1
)
[PriceQuote] => Array
(
[@attributes] => Array
(
[latestPQFlag] => true
[number] => 3
[pricingStatus] => AUTOPRICED
[pricingType] => S
[status] => A
[type] => PQ
)
[Indicators] => Array
(
[@attributes] => Array
(
[isExpired] => true
)
)
[Passenger] => Array
(
[@attributes] => Array
(
[passengerTypeCount] => 1
[requestedType] => INF
[type] => INF
)
)
[ItineraryType] => I
[TicketDesignator] => IN90
[ValidatingCarrier] => AI
[Amounts] => Array
(
[Total] => 2008
)
[LocalCreateDateTime] => 2019-03-05T13:52:00
)
)
)
)