Php 如何过滤来自curlhttppost请求的XML响应
请求的响应:Php 如何过滤来自curlhttppost请求的XML响应,php,xml,curl,soap,Php,Xml,Curl,Soap,请求的响应: <?xml version="1.0" encoding="UTF-8"?> <soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:header> <soap-env:body> <ipgapi:ipgapiorderresponse xmlns:ipgapi="http
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:header>
<soap-env:body>
<ipgapi:ipgapiorderresponse xmlns:ipgapi="http://ipg-online.com/ipgapi/schemas/ipgapi" xmlns:a1="http://ipg-online.com/ipgapi/schemas/a1" xmlns:v1="http://ipg-online.com/ipgapi/schemas/v1">
<ipgapi:approvalcode>Y:761862:4515799310:PPXP:0037</ipgapi:approvalcode>
<ipgapi:avsresponse>PPX</ipgapi:avsresponse>
<ipgapi:brand>VISA</ipgapi:brand>
<ipgapi:country>GBR</ipgapi:country>
<ipgapi:commercialserviceprovider>BOSMS</ipgapi:commercialserviceprovider>
<ipgapi:orderid>A-966025d3-81a2-453a-820e-bb145e8390d1</ipgapi:orderid>
<ipgapi:ipgtransactionid>84515799310</ipgapi:ipgtransactionid>
<ipgapi:paymenttype>CREDITCARD</ipgapi:paymenttype>
<ipgapi:processorapprovalcode>761862</ipgapi:processorapprovalcode>
<ipgapi:processorccvresponse>P</ipgapi:processorccvresponse>
<ipgapi:processorreferencenumber>761862</ipgapi:processorreferencenumber>
<ipgapi:processorresponsecode>00</ipgapi:processorresponsecode>
<ipgapi:processorresponsemessage>AUTH CODE:761862</ipgapi:processorresponsemessage>
<ipgapi:tdate>1521047872</ipgapi:tdate>
<ipgapi:tdateformatted>2018.03.14 18:17:52 (CET)</ipgapi:tdateformatted>
<ipgapi:terminalid>21400371</ipgapi:terminalid>
<ipgapi:transactionresult>APPROVED</ipgapi:transactionresult>
<ipgapi:transactiontime>1521047872</ipgapi:transactiontime>
</ipgapi:ipgapiorderresponse>
</soap-env:body>
</soap-env:header>
</soap-env:envelope>
有人能帮我找出这出了什么问题吗 使用print_r()使用SimpleXMLElement的代码>通常不会提供任何有用的内容。相反,您应该使用输出原始XML的asXML()
$xml = simplexml_load_string($responseXML);
echo $xml->asXML();
给
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:header>
<soap-env:body>
...
因此,$bodyData
是
元素,因此使用最后一行访问该元素的每个部分。您可以使用元素名(减去名称空间前缀ipgapi,因为前面的children()
调用会处理这个问题)。那条线输出
Y:761862:4515799310:PPXP:0037
双引号和单引号。基本的东西,看看代码highlighting@RiggsFolly-抱歉,我的错误,我按submit而没有修复单引号:此函数可能返回布尔值FALSE,但也可能返回计算结果为FALSE的非布尔值。有关更多信息,请阅读布尔值部分。使用===运算符测试此函数的返回值。那么如何获取XML中的各个值呢?您好,访问数据不是这样工作的。不过,$xml->asXML()的第一个示例仍然有效。
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:header>
<soap-env:body>
...
$xml = simplexml_load_string($responseXML);
$body = $xml->xpath("//soap-env:body");
$bodyData = $body[0]->children("ipgapi", true);
echo $bodyData->ipgapiorderresponse->approvalcode;
Y:761862:4515799310:PPXP:0037