从支付结果中解析xml值

时间:2018-05-23 12:37:19

标签: php xml

我正在尝试从付款页面的结果中解析xml数据,这是我的代码

$text = '<?xml version="1.0" encoding="utf-8"?>
<Exception xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Error xsi:type="BBSException">
<Message>Unable to auth</Message>
<Result>
  <IssuerId>3</IssuerId>
  <ResponseCode>98</ResponseCode>
  <ResponseText>Transaction already processed</ResponseText>
  <ResponseSource>Netaxept</ResponseSource>
  <TransactionId>52ca86375c18468d8d7425c7a53459e1</TransactionId>
  <ExecutionTime>2018-05-23T14:16:48.6230323+02:00</ExecutionTime>
  <MerchantId>718374</MerchantId>
  <ExtraInfoOut>2030010</ExtraInfoOut>
  <MaskedPan />
  <MessageId>ccf05c6e0bd84e77862431ac22140d7c</MessageId>
</Result>
</Error>
</Exception>';

$xml = simplexml_load_string($text);
echo "my message is".$xml->Error->Message."<br>";
echo "my response code is".$xml->Error->Result->ResponseCode."<br>";

此代码正常工作并将结果返回为

my message is Unable to auth
my response code is 98

但是当我试图从付款结果页面获得此结果时

$text = file_get_contents("https://xxxx/xxxxx/xxxxxx");
$xml = simplexml_load_string($text);
echo "my message is".$xml->Error->Message."<br>";
echo "my response code is".$xml->Error->Result->ResponseCode."<br>";

但是这段代码没有从xml返回值,当我打印$ text时,它会显示xml输出

 <?xml version="1.0" encoding="utf-8"?>
<Exception xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Error xsi:type="BBSException">
<Message>Unable to auth</Message>
<Result>
  <IssuerId>3</IssuerId>
  <ResponseCode>98</ResponseCode>
  <ResponseText>Transaction already processed</ResponseText>
  <ResponseSource>Netaxept</ResponseSource>
  <TransactionId>52ca86375c18468d8d7425c7a53459e1</TransactionId>
  <ExecutionTime>2018-05-23T14:16:48.6230323+02:00</ExecutionTime>
  <MerchantId>718374</MerchantId>
  <ExtraInfoOut>2030010</ExtraInfoOut>
  <MaskedPan />
  <MessageId>ccf05c6e0bd84e77862431ac22140d7c</MessageId>
</Result>
</Error>
</Exception>

你能帮助我吗

提前致谢

1 个答案:

答案 0 :(得分:0)

{{1}}