0

我一直在尝试使用 simplexml 检索 ResponseCode、ResponseDescription、Amount 和 CardNumber,但它一直返回一个空字符串。

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
    <GetTransactionDataResponse xmlns="http://services.interswitchng.com/">
    <GetTransactionDataResult xmlns:a="http://schemas.datacontract.org/2004/07/WebPAY.Core.ServiceFramework.Contract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <ResponseCode xmlns="http://schemas.datacontract.org/2004/07/TechQuest.Framework.ServiceFramework.Contract">61</ResponseCode><ResponseDescription xmlns="http://schemas.datacontract.org/2004/07/TechQuest.Framework.ServiceFramework.Contract">Exceeds Withdrawal Limit</ResponseDescription>
    <a:Amount>10000000</a:Amount>
    <a:CardNumber>3386</a:CardNumber>
    <a:LeadBankCbnCode i:nil="true"/><a:LeadBankName i:nil="true"/>
    <a:MerchantReference i:nil="true"/><a:PaymentReference i:nil="true"/>
    <a:RetrievalReferenceNumber i:nil="true"/><a:SplitAccounts/>
    <a:TransactionDate>0001-01-01T00:00:00</a:TransactionDate>
    </GetTransactionDataResult>
    </GetTransactionDataResponse>
    </s:Body>
    </s:Envelope>
4

2 回答 2

0

如果您指的是肥皂响应,我会看看Nusoap,它是一个用于 PHP 的 Web 服务库,可以处理与 xml 之间的所有转换,从而非常容易使用 Web 服务。

我自己用过很多次。

于 2012-10-07T15:25:34.373 回答
0

如果您使用Interswitch支付系统,您应该会收到此信息。使用SoapClient代替,但如果您仍然需要解析它,那么:

$sxe = new SimpleXmlElement($xml);
$sxe->registerXPathNamespace('s', 'http://schemas.xmlsoap.org/soap/envelope/');
$sxe->registerXPathNamespace('a', 'http://schemas.datacontract.org/2004/07/WebPAY.Core.ServiceFramework.Contract');
$sxe->registerXPathNamespace('i', 'http://www.w3.org/2001/XMLSchema-instance');

$list = array();
$list['code'] = (string) $sxe->children("s", true)->Body->children()->GetTransactionDataResponse->GetTransactionDataResult->ResponseCode;
$list['desciption'] = (string)  $sxe->children("s", true)->Body->children()->GetTransactionDataResponse->GetTransactionDataResult->ResponseDescription;
$list['amount']  = (string)  $sxe->xpath('//a:Amount');
$list['amount'] = (string)  $list['amount'][0];
$list['card']  = $sxe->xpath('//a:CardNumber');
$list['card'] = (string) $list['card'][0];

echo "<pre>";
print_r($list);

输出

Array
(
    [code] => 61
    [desciption] => Exceeds Withdrawal Limit
    [amount] => A
    [card] => 3386
)

观看现场演示

于 2012-10-07T17:08:04.737 回答