我无法将 SOAP 响应转换为 php 中的数组。
这是代码
$response = $client->__doRequest($xmlRequest,$location,$action,1);
这是 SOAP 响应。
<soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:body>
<searchflightavailability33response xmlns="http://FpwebBox.Fareportal.com/Gateway.asmx">
<searchflightavailability33result>
<Fareportal><FpSearch_AirLowFaresRS><CntKey>1777f5a7-7824-46ce-a0f8-33d5e6e96816</CntKey><Currency CurrencyCode="USD"/><OriginDestinationOptions><OutBoundOptions><OutBoundOption segmentid="9W7008V21Feb14"><FlightSegment etc....
</searchflightavailability33result>
</searchflightavailability33response>
</soap:body>
</soap:envelope>;
我使用以下方法转换为数组,但我得到空输出。
1.echo '<pre>';print_r($client__getLastResponse());
2.echo '<pre>';print_r($response->envelope->body->searchflightavailability33response);
3.echo '<pre>';print_r($client->SearchFlightAvailability33($response));
4.simplexml_load_string($response,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/");
5.echo '<pre>';print_r($client->SearchFlightAvailability33($response));
请给我建议。
使用前面的方法的组合可以轻松地将以下 SOAP 响应结构转换为数组。仅使用函数“simplexml_load_string”删除冒号“:”在某些情况下返回 null。
SOAP 响应
<S:Envelope
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:transaccionResponse
xmlns:ns2="http://ws.iatai.com/">
<respuestaTransaccion>
<idTransaccion>94567</idTransaccion>
<referencia>3958</referencia>
<idEstado>3</idEstado>
<nombreEstado>Declinada</nombreEstado>
<codigoRespuesta>202</codigoRespuesta>
<valor>93815.0</valor>
<iva>86815.0</iva>
<baseDevolucion>0.0</baseDevolucion>
<isoMoneda>COP</isoMoneda>
<fechaProcesamiento>24-07-2015 12:18:40 PM</fechaProcesamiento>
<mensaje>REJECT</mensaje>
<tarjetaRespuesta>
<idFranquicia>1</idFranquicia>
<nombreFranquicia>VISA</nombreFranquicia>
<numeroBin>411111</numeroBin>
<numeroProducto>1111</numeroProducto>
</tarjetaRespuesta>
<procesadorRespuesta>
<idProcesador>3</idProcesador>
</procesadorRespuesta>
</respuestaTransaccion>
</ns2:transaccionResponse>
</S:Body>
</S:Envelope>
PHP 转换:
$response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
$xml = new SimpleXMLElement($response);
$body = $xml->xpath('//SBody')[0];
$array = json_decode(json_encode((array)$body), TRUE);
print_r($array);
Result:
Array
(
[ns2transaccionResponse] => Array
(
[respuestaTransaccion] => Array
(
[idTransaccion] => 94567
[referencia] => 3958
[idEstado] => 3
[nombreEstado] => Declinada
[codigoRespuesta] => 202
[valor] => 93815.0
[iva] => 86815.0
[baseDevolucion] => 0.0
[isoMoneda] => COP
[fechaProcesamiento] => 24-07-2015 12:18:40 PM
[mensaje] => REJECT
[tarjetaRespuesta] => Array
(
[idFranquicia] => 1
[nombreFranquicia] => VISA
[numeroBin] => 411111
[numeroProducto] => 1111
)
[procesadorRespuesta] => Array
(
[idProcesador] => 3
)
)
)
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)