Php 提出香皂请求
Php make soap request
我正在尝试向 Amadeus Web 服务发出 soap 请求。我有 xml 个带有 soap-header
的文件
<?xml version="1.0"?>
<soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<add:MessageID xmlns:add="http://www.w3.org/2005/08/addressing">dbbb6ca5-e5d4-7518-d84-f6f7c22ed752</add:MessageID>
<add:Action xmlns:add="http://www.w3.org/2005/08/addressing">http://webservices.amadeus.com/Hotel_MultiSingleAvailability_10.0</add:Action>
<add:To xmlns:add="http://www.w3.org/2005/08/addressing">https://nodeD1.test.webservices.amadeus.com/1ASIWOTANA8</add:To>
<link:TransactionFlowLink xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1"/>
<oas:Security xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<oas:UsernameToken xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" oas1:Id="UsernameToken-1">
<oas:Username>WSNA8OTA</oas:Username>
<oas:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"nonce</oas:Nonce>
<oas:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">pass</oas:Password>
<oas1:Created>2017-11-09T08:50:40.588Z</oas1:Created>
</oas:UsernameToken>
</oas:Security>
<AMA_SecurityHostedUser xmlns="http://xml.amadeus.com/2010/06/Security_v1">
<UserID POS_Type="1" PseudoCityCode="MIA1S38BL" AgentDutyCode="SU" RequestorType="U"/>
</AMA_SecurityHostedUser>
</soap:Header>
我的php代码
$params = [
'exceptions' => 0,
'soap_version' => SOAP_1_2,
'trace' => 1,
];
$soapvar = new \SoapVar($soapRequest, XSD_ANYXML);
$client = new SoapClient($wsdlFile", $params);
$result = $client->Hotel_MultiSingleAvailability($soapvar);
但是如果我打印最后一个请求,我会得到另一个 xml
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.opentravel.org/OTA/2003/05">
<env:Body>
<soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<add:MessageID xmlns:add="http://www.w3.org/2005/08/addressing">be4b7f20-c867-11e7-a815-83f383e012a5</add:MessageID>
<add:Action xmlns:add="http://www.w3.org/2005/08/addressing">http://webservices.amadeus.com/Hotel_MultiSingleAvailability_10.0</add:Action>
<add:To xmlns:add="http://www.w3.org/2005/08/addressing">https://nodeD1.test.webservices.amadeus.com/1ASIWOTANA8</add:To>
<link:TransactionFlowLink xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1"/>
<oas:Security xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<oas:UsernameToken xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" oas1:Id="UsernameToken-1">
<oas:Username>WSNA8OTA</oas:Username>
<oas:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">nonce</oas:Nonce>
<oas:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">pass</oas:Password>
<oas1:Created>2017-11-13T11:42:35:788Z</oas1:Created>
</oas:UsernameToken>
</oas:Security>
<AMA_SecurityHostedUser xmlns="http://xml.amadeus.com/2010/06/Security_v1">
<UserID POS_Type="1" PseudoCityCode="MIA1S38BL" AgentDutyCode="SU" RequestorType="U"/>
</AMA_SecurityHostedUser>
</soap:Header>
</env:Body>
</env:Envelope>
如何从我的请求中删除 env:body 和 env:envelope 并仅使用我的 xml 文件?
获取 soap:Header
及其子元素
// load full xml
$xml = simplexml_load_string($s);
// get all namespaces used in doc by seting true and register soap for xpath
$xml->registerXPathNamespace ('soap', $xml->getDocNamespaces(true)['soap']);
// get the part you want
$myxml = $xml->xpath('/env:Envelope/env:Body/soap:Header');
有一个 PHP 库可以为您做这件事,还有更多。它是一个库,可以在 PHP 中轻松访问 Amadeus 的 SOAP 界面,请查看:https://github.com/amabnl/amadeus-ws-client.
该库尚不支持酒店消息,但它会为您节省大量实施整个 SOAP header 业务的时间。也许您愿意为支持 Hotel_ 消息做出贡献?为此,请参阅 https://github.com/amabnl/amadeus-ws-client/issues/70
我正在尝试向 Amadeus Web 服务发出 soap 请求。我有 xml 个带有 soap-header
的文件<?xml version="1.0"?>
<soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<add:MessageID xmlns:add="http://www.w3.org/2005/08/addressing">dbbb6ca5-e5d4-7518-d84-f6f7c22ed752</add:MessageID>
<add:Action xmlns:add="http://www.w3.org/2005/08/addressing">http://webservices.amadeus.com/Hotel_MultiSingleAvailability_10.0</add:Action>
<add:To xmlns:add="http://www.w3.org/2005/08/addressing">https://nodeD1.test.webservices.amadeus.com/1ASIWOTANA8</add:To>
<link:TransactionFlowLink xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1"/>
<oas:Security xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<oas:UsernameToken xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" oas1:Id="UsernameToken-1">
<oas:Username>WSNA8OTA</oas:Username>
<oas:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"nonce</oas:Nonce>
<oas:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">pass</oas:Password>
<oas1:Created>2017-11-09T08:50:40.588Z</oas1:Created>
</oas:UsernameToken>
</oas:Security>
<AMA_SecurityHostedUser xmlns="http://xml.amadeus.com/2010/06/Security_v1">
<UserID POS_Type="1" PseudoCityCode="MIA1S38BL" AgentDutyCode="SU" RequestorType="U"/>
</AMA_SecurityHostedUser>
</soap:Header>
我的php代码
$params = [
'exceptions' => 0,
'soap_version' => SOAP_1_2,
'trace' => 1,
];
$soapvar = new \SoapVar($soapRequest, XSD_ANYXML);
$client = new SoapClient($wsdlFile", $params);
$result = $client->Hotel_MultiSingleAvailability($soapvar);
但是如果我打印最后一个请求,我会得到另一个 xml
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.opentravel.org/OTA/2003/05">
<env:Body>
<soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<add:MessageID xmlns:add="http://www.w3.org/2005/08/addressing">be4b7f20-c867-11e7-a815-83f383e012a5</add:MessageID>
<add:Action xmlns:add="http://www.w3.org/2005/08/addressing">http://webservices.amadeus.com/Hotel_MultiSingleAvailability_10.0</add:Action>
<add:To xmlns:add="http://www.w3.org/2005/08/addressing">https://nodeD1.test.webservices.amadeus.com/1ASIWOTANA8</add:To>
<link:TransactionFlowLink xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1"/>
<oas:Security xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<oas:UsernameToken xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" oas1:Id="UsernameToken-1">
<oas:Username>WSNA8OTA</oas:Username>
<oas:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">nonce</oas:Nonce>
<oas:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">pass</oas:Password>
<oas1:Created>2017-11-13T11:42:35:788Z</oas1:Created>
</oas:UsernameToken>
</oas:Security>
<AMA_SecurityHostedUser xmlns="http://xml.amadeus.com/2010/06/Security_v1">
<UserID POS_Type="1" PseudoCityCode="MIA1S38BL" AgentDutyCode="SU" RequestorType="U"/>
</AMA_SecurityHostedUser>
</soap:Header>
</env:Body>
</env:Envelope>
如何从我的请求中删除 env:body 和 env:envelope 并仅使用我的 xml 文件?
获取 soap:Header
及其子元素
// load full xml
$xml = simplexml_load_string($s);
// get all namespaces used in doc by seting true and register soap for xpath
$xml->registerXPathNamespace ('soap', $xml->getDocNamespaces(true)['soap']);
// get the part you want
$myxml = $xml->xpath('/env:Envelope/env:Body/soap:Header');
有一个 PHP 库可以为您做这件事,还有更多。它是一个库,可以在 PHP 中轻松访问 Amadeus 的 SOAP 界面,请查看:https://github.com/amabnl/amadeus-ws-client.
该库尚不支持酒店消息,但它会为您节省大量实施整个 SOAP header 业务的时间。也许您愿意为支持 Hotel_ 消息做出贡献?为此,请参阅 https://github.com/amabnl/amadeus-ws-client/issues/70