我正在尝试处理来自 First Data 的全球网关的 SOAP 响应。我以前使用过 SoapClient,但没有 wsdl - 并且该公司表示他们不提供 wsdl。
我尝试了各种其他方法,例如基于此处和 PHP 手册中找到的示例的 SimpleXMLElement,但我无法获得任何效果。我怀疑命名空间是我的问题的一部分。任何人都可以建议一种方法或给我指出一个类似的例子吗?迄今为止,我在谷歌上的努力一直没有结果。
使用 PHP 5。
部分 SOAP 响应(去掉其前面的所有 HTML 标头内容)如下所示:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<fdggwsapi:FDGGWSApiOrderResponse xmlns:fdggwsapi="http://secure.linkpt.net/fdggwsapi/schemas_us/fdggwsapi">
<fdggwsapi:CommercialServiceProvider/>
<fdggwsapi:TransactionTime>Thu Nov 29 17:03:18 2012</fdggwsapi:TransactionTime>
<fdggwsapi:TransactionID/>
<fdggwsapi:ProcessorReferenceNumber/>
<fdggwsapi:ProcessorResponseMessage/>
<fdggwsapi:ErrorMessage>SGS-005005: Duplicate transaction.</fdggwsapi:ErrorMessage>
<fdggwsapi:OrderId>A-e833606a-5197-45d6-b990-81e52df41274</fdggwsapi:OrderId>
...
<snip>
我还需要能够确定是否发出了 SOAP 错误信号。 XML 看起来像这样:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:FaultX>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">MerchantException</faultstring>
<detail>
cvc-pattern-valid: Value '9999185.00' is not facet-valid with respect to pattern '([1-9]([0-9]{0,3}))?[0-9](\.[0-9]{1,2})?' for type '#AnonType_ChargeTotalAmount'.
cvc-type.3.1.3: The value '9999185.00' of element 'v1:ChargeTotal' is not valid.
</detail>
</SOAP-ENV:FaultX>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
使用代码先生的答案,我已经能够从非故障响应中检索数据。但我需要确定我正在处理什么类型的数据包并从这两种类型中提取数据。如果他们能提供 wsdl,那就容易多了!
您的响应可以使用 SimpleXML 进行解析,下面是一个示例。请注意,我将命名空间 URL 传递给children()
来访问元素。
$obj = simplexml_load_string($xml);
$response = $obj->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://secure.linkpt.net/fdggwsapi/schemas_us/fdggwsapi')->FDGGWSApiOrderResponse;
echo $response->TransactionTime . "\n";
echo $response->ErrorMessage;
Outputs
2012 年 11 月 29 日星期四 17:03:18
SGS-005005:重复交易。
键盘演示 http://codepad.org/cxFViIPF
编辑:SoapFault 响应可以如下解析。它输出故障字符串和详细信息,或“未发现故障”:
if($obj->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://schemas.xmlsoap.org/soap/envelope/') && isset($obj->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://schemas.xmlsoap.org/soap/envelope/')->children()->faultcode))
{
$fault = $obj->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://schemas.xmlsoap.org/soap/envelope/')->children();
// soap fault
echo $fault->faultstring;
echo $fault->detail;
}
else
{
echo 'No fault found, do normal parsing...';
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)