Parcourir la source

fix url parse

stanley-king il y a 4 ans
Parent
commit
ee56c65b74
3 fichiers modifiés avec 72 ajouts et 12 suppressions
  1. 19 6
      helper/fcgi_server.php
  2. 20 6
      helper/request_helper.php
  3. 33 0
      test/TestRefill.php

+ 19 - 6
helper/fcgi_server.php

@@ -48,13 +48,26 @@ class fcgi_server
         if(count($ops) == 2)
         {
             $squery = $ops[1];
-            $params = preg_split('/&|=/', $squery);
-
-            for ($i = 0; $i < count($params); ++$i) {
-                $key = $params[$i];
-                $val = $params[++$i];
+            $params = preg_split('/&/', $squery);
+            foreach ($params as $pair)
+            {
+                $kv = explode('=', $pair);
+                $count = count($kv);
+                if($count === 1) {
+                    $key = $kv[0];
+                    $val = "";
+                }
+                elseif($count === 2) {
+                    $key = $kv[0];
+                    $val = urldecode($kv[1]);
+                }
+                else {
+                    continue;
+                }
                 $_GET[$key] = $val;
                 $_POST[$key] = $val;
+
+                Log::record("{$key}:{$val}",Log::DEBUG);
             }
         }
     }
@@ -99,7 +112,7 @@ class fcgi_server
             try
             {
                 Log::start_sql_log();
-                $this->parase_requri();
+//                $this->parase_requri();
                 init_request();
                 init_cookie($_SERVER['HTTP_COOKIE']);
                 $file = request_helper::script_file();

+ 20 - 6
helper/request_helper.php

@@ -272,14 +272,28 @@ class request_helper
         }
 
         Log::record("content={$squery}",Log::DEBUG);
-        $params = preg_split('/&|=/', $squery);
+        $params = preg_split('/&/', $squery);
         if ($method == 'get' || $method == 'post')
         {
-            for ($i = 0; $i < count($params); ++$i) {
-                $key = $params[$i];
-                $val = $params[++$i];
-                $_GET[$key] =  urldecode($val);
-                $_POST[$key] = urldecode($val);
+            foreach ($params as $pair)
+            {
+                $kv = explode('=', $pair);
+                $count = count($kv);
+                if($count === 1) {
+                    $key = $kv[0];
+                    $val = "";
+                }
+                elseif($count === 2) {
+                    $key = $kv[0];
+                    $val = urldecode($kv[1]);
+                }
+                else {
+                    continue;
+                }
+                $_GET[$key] = $val;
+                $_POST[$key] = $val;
+
+                Log::record("{$key}:{$val}",Log::DEBUG);
             }
         }
     }

+ 33 - 0
test/TestRefill.php

@@ -65,6 +65,39 @@ class TestRefill extends TestCase
         $ret = refill\RefillFactory::instance()->notify('beixt',$params);
     }
 
+    public function testSuhxVerify()
+    {
+        $data = 'onlystr=190661874318128632&sign=9eb60765c356341fd41c9bec6526f46a&amt=1000&notifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php&jdno&cardtype=Sinoepc&batchid=25940&cardno=1000111100012304048&orgid=1590993600&status=2';
+        $url = "http://192.168.1.220/mobile/refill_suhc.php?" . $data;
+
+        $resp = http_request($url);
+    }
+
+    public function testUrl()
+    {
+        $data = 'onlystr=190661874318128632&sign=9eb60765c356341fd41c9bec6526f46a&amt=1000&notifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php&jdno&cardtype=Sinoepc&batchid=25940&cardno=1000111100012304048&orgid=1590993600&status=2';
+
+        $params = preg_split('/&/', $data);
+        foreach ($params as $pair)
+        {
+            $kv = explode('=', $pair);
+            $count = count($kv);
+            if($count === 1) {
+                $key = $kv[0];
+                $val = "";
+            }
+            elseif($count === 2) {
+                $key = $kv[0];
+                $val = $kv[1];
+            }
+            else {
+                continue;
+            }
+
+            Log::record("{$key}:{$val}",Log::DEBUG);
+        }
+    }
+
     public function testAddoil()
     {
         $url = $this->mReqHost . "/mobile/index.php";