Php 处理SOAP响应

Php 处理SOAP响应,php,soap,Php,Soap,我正试图处理来自First Data全球网关的SOAP响应。我以前使用过SoapClient,但是没有wsdl,公司说他们不提供wsdl 我尝试过其他各种方法,例如基于这里和PHP手册中的示例的SimpleXMLElement,但我无法让任何方法起作用。我怀疑名称空间是我问题的一部分。有人能给我一个类似的建议吗?或者给我举一个类似的例子——我在谷歌的努力到目前为止都是徒劳的 使用PHP5 部分SOAP响应(去掉前面的所有HTML头内容)如下所示: <SOAP-ENV:Envelope xm

我正试图处理来自First Data全球网关的SOAP响应。我以前使用过SoapClient,但是没有wsdl,公司说他们不提供wsdl

我尝试过其他各种方法,例如基于这里和PHP手册中的示例的SimpleXMLElement,但我无法让任何方法起作用。我怀疑名称空间是我问题的一部分。有人能给我一个类似的建议吗?或者给我举一个类似的例子——我在谷歌的努力到目前为止都是徒劳的

使用PHP5

部分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-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>

2012年11月29日星期四17:03:18
SGS-005005:重复交易。
A-e833606a-5197-45d6-b990-81e52df41274
...
我还需要能够确定是否发出了SOAP故障信号。其XML格式如下所示:

<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-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>

SOAP-ENV:客户端
商品感受
cvc模式有效:值“9999185.00”对于模式“([1-9]([0-9]{0,3}”)?[0-9](\.[0-9]{1,2}”)对于类型“\\[0-9]{1,2}”)无效。
cvc type.3.1.3:元素“v1:ChargeTotal”的值“9999185.00”无效。

使用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;
输出

2012年11月29日星期四17:03:18
SGS-005005:重复交易

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

谢谢-这正是我所需要的-我没有见过这样引用两个名称空间的示例。如果我得到有效的响应,该示例会运行得很好,但是当发出soap错误信号时,我发现了额外的“皱纹”。在这种情况下,当然没有第二个名称空间,我也无法找到一个简单的方法来确定是否存在fault元素及其内容。你有什么建议吗?用一个soap错误响应的例子更新这个问题,我来看看。完成-非常感谢你看这个。有了Soap客户端,一切看起来都简单多了。好吧——我现在明白了——我遗漏的是“孩子”的三倍(这是一个词吗?)。这看起来很奇怪。非常感谢。