对于我的一生,我无法弄清楚为什么我无法访问此肥皂包中的任何属性(甚至无法弄清楚它们是什么)。我不能使用水星还给我的任何东西。我已经阅读了其他几个类似的问题,但没有运气。我相信这只是我无知的产物,但任何帮助将不胜感激。
$transactionInfo = new MercuryPaymentHandler($paymentID);
$returnValue = $transactionInfo->verifyPayment();
$xml = new SimpleXMLElement($returnValue);
var_dump(get_object_vars($xml));
返回:
array(0) { }
但是这个:
$transactionInfo = new MercuryPaymentHandler($paymentID);
$returnValue = $transactionInfo->verifyPayment();
$xml = new SimpleXMLElement($returnValue);
echo $xml->asXML();
返回:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<VerifyPaymentResponse xmlns="http://www.mercurypay.com/">
<VerifyPaymentResult>
<ResponseCode>0</ResponseCode>
<Status>Approved</Status>
<StatusMessage>AP</StatusMessage>
<DisplayMessage>Your transaction has been approved.</DisplayMessage>
<AvsResult/>
<CvvResult>M</CvvResult>
<AuthCode>000027</AuthCode>
<Token>ItIu8ayb9ZyMcBjHUkyHS0krnFVf6esnfs6tULuAo2giERIQACMQAgyc</Token>
<RefNo>0028</RefNo>
<Invoice>48</Invoice>
<AcqRefData>KbMCC2110080622 </AcqRefData>
<CardType>M/C</CardType><MaskedAccount>xxxxxxxx6781</MaskedAccount>
<Amount>7</Amount>
<TaxAmount>0</TaxAmount>
<TransPostTime>2012-06-22T21:10:08.65</TransPostTime>
<CardholderName>Test-User</CardholderName>
<AVSAddress/>
<AVSZip/>
<TranType>Sale</TranType>
<PaymentIDExpired>true</PaymentIDExpired>
<CustomerCode/>
<Memo>Mighty Wash 2.0</Memo>
<AuthAmount>7</AuthAmount>
<VoiceAuthCode/>
<ProcessData>|00|600550672000</ProcessData>
<OperatorID/>
<TerminalName/>
</VerifyPaymentResult>
</VerifyPaymentResponse>
</soap:Body>
</soap:Envelope>
什么给?
更新
我从来没有用PHP的原生类来解决这个问题,但是使用CakePHP的XML类很容易。
问题是,在内部,SimpleXMLElement
不是作为普通对象存储的。基本上,您必须知道要访问哪些属性,并且它从其内部结构中动态组成结果。在您的情况下,您可以使用如下内容:http://php.net/manual/en/simplexmlelement.xpath.php(请参阅示例)来有效地提取数据。另外,为了严格回答您的问题,您可以使用以下内容:http://www.php.net/manual/en/simplexmlelement.attributes.php
- 你不能转储 SimpleXMLElement
- SimpleXMLElement背后的思想是,您应该能够分层访问每个节点。所以它基本上是RootNode->FirstChildNode->FirstChildNodeOfTheFirstChildNode->AndSoOn
- 默认情况下,如果将 SimpleXMLElement 与字符串或变量连接起来,则会调用 __toString() 方法。