Bladeren bron

add to local

stanley-king 4 jaren geleden
bovenliggende
commit
21690c901f
5 gewijzigde bestanden met toevoegingen van 36 en 45 verwijderingen
  1. 6 4
      helper/refill/RefillFactory.php
  2. 9 2
      helper/request_helper.php
  3. 0 3
      mobile/control/merchant.php
  4. 11 0
      mobile/control/refill.php
  5. 10 36
      test/TestRefill.php

+ 6 - 4
helper/refill/RefillFactory.php

@@ -63,11 +63,13 @@ class RefillFactory
     private function combine_goods($configs)
     {
         $result = [];
-        foreach ($configs as $cfg) {
-            $card_types = $cfg['card_type'];
-            $amounts = $cfg['amount'];
+        foreach ($configs as $cfg)
+        {
+            $card_types = $cfg['card_type'] ?? [];
+            $amounts = $cfg['amount'] ?? [];
 
-            foreach ($card_types as $type) {
+            foreach ($card_types as $type)
+            {
                 if (array_key_exists($type, $result)) {
                     $item = $result[$type];
                 } else {

+ 9 - 2
helper/request_helper.php

@@ -295,11 +295,15 @@ class request_helper
 
     static private function parse_formurl($squery,$method)
     {
+        if(empty($squery)) return;
+
         $params = preg_split('/&/', $squery);
         if ($method == 'get' || $method == 'post')
         {
             foreach ($params as $pair)
             {
+                if(empty($pair)) continue;
+
                 $kv = explode('=', $pair);
                 $count = count($kv);
                 if($count === 1) {
@@ -313,8 +317,11 @@ class request_helper
                 else {
                     continue;
                 }
-                $_GET[$key] = $val;
-                $_POST[$key] = $val;
+
+                if(!empty($key)) {
+                    $_GET[$key] = $val;
+                    $_POST[$key] = $val;
+                }
 
                 Log::record("{$key}:{$val}",Log::DEBUG);
             }

+ 0 - 3
mobile/control/merchant.php

@@ -18,9 +18,6 @@ class merchantControl
         }
 
         $ips = unserialize($mchinfo['ip_white_list']);
-        foreach ($ips as $ip) {
-            Log::record("IP:{$ip}",Log::DEBUG);
-        }
 
         if(!empty($ips)) {
             $addr = $_SERVER['REMOTE_ADDR'];

+ 11 - 0
mobile/control/refill.php

@@ -17,6 +17,17 @@ class refillControl extends merchantControl
     public function goodsOp()
     {
         $result = refill\RefillFactory::instance()->goods();
+
+        $sorter = function (array $items) {
+            $ret = [];
+            foreach ($items as $key => $val) {
+                sort($val);
+                $ret[$key] = $val;
+            }
+            return $ret;
+        };
+
+        $result = $sorter($result);
         return self::outsuccess($result);
     }
 

+ 10 - 36
test/TestRefill.php

@@ -17,11 +17,13 @@ require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 const LocalTest = 1;
 const NetTest = 2;
 
-const CurrentTest = NetTest;
+const CurrentTest = LocalTest;
 
 class TestRefill extends TestCase
 {
     private $mReqHost = '';
+    private $mKey='';
+    private $mMchid = 0;
 
     public function __construct(?string $name = null, array $data = [], $dataName = '')
     {
@@ -29,9 +31,13 @@ class TestRefill extends TestCase
 
         if(CurrentTest == LocalTest) {
             $this->mReqHost = BASE_SITE_URL;
+            $this->mMchid = 1;
+            $this->mKey = '1ff02223b771c0414468c8892151c602';
         }
         else {
             $this->mReqHost = 'https://www.xyzshops.cn';
+            $this->mMchid = 1092;
+            $this->mKey = '210fe406954220f56085997d6a4c5b80';
         }
     }
 
@@ -193,42 +199,10 @@ class TestRefill extends TestCase
         }
     }
 
-    public function testAddPhoe()
-    {
-        $phones = [//13911129867,
-            18500608333,
-            18510683168,
-            18513846008,
-            18518237398];
-        $amount = 10;
-
-        for ($i = 0; $i < 3; $i++)
-        {
-            foreach ($phones as $phone) {
-                $url = $this->mReqHost . "/mobile/index.php";
-                $params = ['mchid' => 1092,
-                    'cardno' => $phone,
-                    'amount' => $amount,
-                    "act"=>"refill",
-                    "op"=>"add",
-                    'order_sn' => $this->make_sn(),
-                    'notifyurl'=> $this->mReqHost . "/mobile/refill_xyz.php"];
-
-                $resp = $this->send_md5($url,$params);
-                Log::record($resp,Log::DEBUG);
-            }
-        }
-    }
-
     public function testGoods()
     {
-        //        $req_url = 'https://www.xyzshops.cn/mobile/index.php';
-        //        $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
-
-        $req_url = BASE_SITE_URL . '/mobile/index.php';
-        $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
-
-        $params = ['mchid' => 1,
+        $req_url = $this->mReqHost . '/mobile/index.php';
+        $params = ['mchid' => $this->mMchid,
             "act"=>"refill",
             "op"=>"goods"];
 
@@ -348,7 +322,7 @@ class TestRefill extends TestCase
     private function send_md5($url,$params)
     {
         $body = $this->body($params);
-        $body .= "&key=210fe406954220f56085997d6a4c5b80";
+        $body .= "&key={$this->mKey}";
         $params['sign'] = md5($body);
 
         $resp = http_request($url,$params,'POST');