druzuz321103 2018-05-23 12:37 采纳率: 100%
浏览 26
已采纳

从支付结果中解析xml值

i am trying to parse the xml data from the result of my payment page, here is my code

$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>";

This code works fine and return the result as

my message is Unable to auth
my response code is 98

but when i am trying to get this result from the payment result page like this

$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>";

but this code is not returning the value from the xml, when the i print the $text, it show the xml output

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

can you any one help me with this

Thanks in advance

  • 写回答

1条回答 默认 最新

  • douju6542 2018-05-23 14:24
    关注
    $sXML = file_get_contents('xxxxxx');
    $oXML = new SimpleXMLElement($sXML);
    echo  $oXML->Error->Result->ResponseCode;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog