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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?