我在为Amadeus e-Power服务设置AuthenticationSoapHeader
时遇到问题。我使用的是SoapClient中内置的PHP。
WSDL: https://staging-ws.epower.amadeus.com/ws_usitcolours/EpowerService.asmx?WSDL
我为进行测试而制作的基础班:
class AmadeusSoapClient
{
private $_client;
private $_config = [
'wsdl' => 'https://staging-ws.epower.amadeus.com/ws_usitcolours/EpowerService.asmx?WSDL',
'namespace' => 'https://epowerv5.amadeus.com.tr/WS',
'auth' => [
'username' => '...',
'password' => '...'
],
'debug' => true
];
// Construct
public function __construct()
{
// Client
$this->_client = new \SoapClient($this->_config['wsdl'], [
'trace' => $this->_config['debug']
]);
// Headers
$headers = [
// Auth
new \SoapHeader($this->_config['namespace'], 'AuthenticationSoapHeader', [
'WSUserName' => $this->_config['auth']['username'],
'WSPassword' => $this->_config['auth']['password']
]),
];
// Set headers
$this->_client->__setSoapHeaders($headers);
}
// Request: CurrencyConversion
public function currencyConversion($fromCurrency = 'BGN', $toCurrency = 'EUR', $amount = 1.00)
{
$method = 'CurrencyConversion';
$params = [
'OTA_CurrencyConversionRQ' => [
'_' => '',
'FromCurrency' => $fromCurrency,
'ToCurrency' => $toCurrency,
'Amount' => $amount,
],
];
try {
return $this->_client->__call($method, [$params]);
} catch (\Exception $e) {
// ...
}
}
}
示例用法:
$client = new \AmadeusSoapClient();
$client->currencyConversion();
收到错误:
stdClass Object
(
[OTA_CurrencyConversionRS] => stdClass Object
(
[Errors] => stdClass Object
(
[Error] => Array
(
[0] => stdClass Object
(
[_] =>
[Type] => EpowerInternalError
[ErrorCode] => EPW.0000
[ShortText] => User Name is required
[Code] => A001
[NodeList] => EPower
[BreakFlow] =>
)
[1] => stdClass Object
(
[_] =>
[Type] => EpowerInternalError
[ErrorCode] => EPW.0000
[ShortText] => Password is required
[Code] => A001
[NodeList] => EPower
[BreakFlow] =>
)
)
)
)
)
无论我使用__setSopHeaders
设置标题还是使用__call
方法传递标题,都始终将其忽略。还有其他设置方法吗? >
对不需要身份验证的方法的请求正常运行。
答案 0 :(得分:0)
问题出在geom_errobar(aes(ymin = i - se, ymax = i + se))
内置的PHP与Amadeus的.NET服务器之间的SSL通信中。
无论我如何设置(强制)Soap以使用SSL,都无法建立SSL连接,我始终会收到SoapClient
错误。
遗憾的是,我没有更多的空闲时间进行进一步调查,因此我决定切换到cURL。 这是我做的简单课程。希望它能对某人有所帮助!
https connection must be used
从\ Helpers \ ArrayToXml开始,它只是 Spatie 的简单类,它将PHP Array转换为XML。 来源:https://github.com/spatie/array-to-xml
请求上述类生成的XML:
class AmadeusClient
{
private $_config = [
'wsdl' => 'https://staging-ws.epower.amadeus.com/ws_usitcolours/EpowerService.asmx?WSDL',
'namespace' => 'http://epowerv5.amadeus.com.tr/WS',
'auth' => [
'username' => '...',
'password' => '...'
],
'sessionCookieName' => 'ASP.NET_SessionId',
'debug' => true
];
public function testCall()
{
$fromCurrency = 'BGN';
$toCurrency = 'USD';
$amount = 15.00;
$result = $this->currencyConversionRequest($fromCurrency, $toCurrency, $amount);
echo '<pre>';
var_dump($result);
exit;
}
// Request: Currency conversion
public function currencyConversionRequest($fromCurrency = 'BGN', $toCurrency = 'EUR', $amount = 1.00)
{
$method = 'CurrencyConversion';
$params = [
'OTA_CurrencyConversionRQ' => [
'_attributes' => [
'FromCurrency' => $fromCurrency,
'ToCurrency' => $toCurrency,
'Amount' => $amount,
]
],
];
$result = $this->sendRequest($method, $params);
if (isset($result->Body->CurrencyConversionResponse->OTA_CurrencyConversionRS->Success)) {
$array = (array) $result->Body->CurrencyConversionResponse->OTA_CurrencyConversionRS->attributes();
if (!empty($array['@attributes'])) {
return $array['@attributes'];
}
}
return false;
}
public function sendRequest($method, $params)
{
$body = \Helpers\ArrayToXml::convert($params, [
'rootElementName' => $method,
'_attributes' => [
'xmlns' => $this->_config['namespace']
]
]);
$requestBody = '
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthenticationSoapHeader xmlns="'. $this->_config['namespace'] .'">
<WSUserName>'. $this->_config['auth']['username'] .'</WSUserName>
<WSPassword>'. $this->_config['auth']['password'] .'</WSPassword>
</AuthenticationSoapHeader>
</soap:Header>
<soap:Body>
'. str_replace('<?xml version="1.0"?>', '', $body) .'
</soap:Body>
</soap:Envelope>
';
$headers = [
'Content-type: text/xml; charset=utf-8',
'Accept: text/xml',
'Cache-Control: no-cache',
'Pragma: no-cache',
'SOAPAction: '. $this->_config['namespace'] .'/'. $method,
'Content-length: '. mb_strlen($requestBody),
];
$ch = curl_init($this->_config['wsdl']);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$cleanXml = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $output);
return simplexml_load_string($cleanXml);
}
}
回复:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthenticationSoapHeader xmlns="http://epowerv5.amadeus.com.tr/WS">
<WSUserName>...</WSUserName>
<WSPassword>...</WSPassword>
</AuthenticationSoapHeader>
</soap:Header>
<soap:Body>
<CurrencyConversion xmlns="http://epowerv5.amadeus.com.tr/WS">
<OTA_CurrencyConversionRQ FromCurrency="BGN" ToCurrency="USD" Amount="15"/>
</CurrencyConversion>
</soap:Body>
</soap:Envelope>