php – 处理SOAP响应

我正在尝试从First Data的全局网关处理SOAP响应.我之前使用过SoapClient,但没有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>

使用Code先生的答案,我能够从非故障响应中检索数据.但是我需要确定我正在处理什么类型的数据包并从这两种类型中提取数据.只要他们提供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;

输出

Thu Nov 29 17:03:18 2012
SGS-005005: Duplicate transaction.

Codepad Demo

编辑: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...';
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...