Browse Source

sunguidong

zhangguidong 2 years ago
parent
commit
0b89dfbe84
2 changed files with 15 additions and 2 deletions
  1. 10 1
      app/common.php
  2. 5 1
      app/pay/controller/Pay.php

+ 10 - 1
app/common.php

@@ -590,7 +590,16 @@ function table($table = '')
 {
 	return config('database.connections.prefix') . $table;
 }
-
+function xml_parser($str){
+    $xml_parser = xml_parser_create();
+    if(!xml_parse($xml_parser,$str,true)){
+        xml_parser_free($xml_parser);
+        return false;
+    }
+    else {
+        return true;
+    }
+}
 /**
  * 获取图片的真实路径
  *

+ 5 - 1
app/pay/controller/Pay.php

@@ -28,7 +28,11 @@ class Pay extends Controller
 	public function VipPayNotify()
 	{
         $data = file_get_contents('php://input');
-        $jsonXml = json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA));
+        $is_xml =  xml_parser($data);
+        $jsonXml = $data;
+        if($is_xml) {
+            $jsonXml = json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA));
+        }
         $data = json_decode($jsonXml, true);
 
         file_put_contents('pay_notifiy_log.log', $jsonXml);