stanley-king 1 年之前
父節點
當前提交
be8abceef5

+ 4 - 7
helper/refill/api/mh/dixin_normal/RefillPhone.php

@@ -19,16 +19,13 @@ class RefillPhone extends refill\IRefillPhone
     {
         $oper_getter = function ($card_type)
         {
-            if($card_type == mtopcard\ChinaMobileCard) {
+            if ($card_type == mtopcard\ChinaMobileCard) {
                 return 'YD';
-            }
-            elseif($card_type == mtopcard\ChinaUnicomCard) {
+            } elseif ($card_type == mtopcard\ChinaUnicomCard) {
                 return 'LT';
-            }
-            elseif($card_type == mtopcard\ChinaTelecomCard) {
+            } elseif ($card_type == mtopcard\ChinaTelecomCard) {
                 return 'DX';
-            }
-            else {
+            } else {
                 return false;
             }
         };

+ 2 - 1
helper/refill/api/mh/seven_kami/ReadMe.MD

@@ -4,7 +4,8 @@
 下单地址:http://42.193.245.133:5001/plat/api/old/submitorder
 查单地址:http://42.193.245.133:5001/plat/api/old/queryorder
 余额地址:http://42.193.245.133:5001/plat/api/old/queryBalance
-接口文档:https://docs.qq.com/doc/DZW5jTWdHZFVIYnZp?_t=1639711707120   话费
+接口文档:https://docs.qq.com/doc/DZW5jTWdHZFVIYnZp?_t=1639711707120 
+话费
 
 
 账号15652921127  密码是 a123456

+ 5 - 6
helper/refill/api/mh/seven_kami/RefillCallBack.php

@@ -16,8 +16,6 @@ class RefillCallBack implements refill\IRefillCallBack
             Log::record('seven_kami\RefillCallBack::verify fail',Log::DEBUG);
             return false;
         }
-
-        return false;
     }
 
     //[$order_id, $success, $can_try, $need_handle, $official_sn]
@@ -33,11 +31,12 @@ class RefillCallBack implements refill\IRefillCallBack
         $order_id = $order_info['order_id'];
 
         $code = intval($params['nFlag']);
-        if ($code === 2) {//成功
-            Model('refill_order')->edit($order_id, ['official_sn' => $params['szRtnMsg']]);
-            return [$order_id, true, false, true, ''];
+        if ($code === 2) {
+            $official_sn = $params['szRtnMsg'] ?? '';
+            Model('refill_order')->edit($order_id, ['official_sn' => $official_sn]);
+            return [$order_id, true, false, true, $official_sn];
         }
-        elseif ($code === 3) {//失败
+        elseif ($code === 3) {
             return [$order_id, false, true, true, ''];
         }
         else {

+ 25 - 40
helper/refill/api/mh/seven_kami/RefillPhone.php

@@ -17,28 +17,30 @@ class RefillPhone extends refill\IRefillPhone
 
     private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
     {
-        $nSortType = function ($card_type)
+        $nSortType_getter = function ($card_type)
         {
-            if($card_type == mtopcard\ChinaMobileCard) {
+            if ($card_type == mtopcard\ChinaMobileCard) {
                 return 1;
-            }
-            elseif($card_type == mtopcard\ChinaUnicomCard) {
+            } elseif ($card_type == mtopcard\ChinaUnicomCard) {
                 return 2;
-            }
-            elseif($card_type == mtopcard\ChinaTelecomCard) {
+            } elseif ($card_type == mtopcard\ChinaTelecomCard) {
                 return 3;
-            }
-            else {
+            } else {
                 return false;
             }
         };
 
+        $nSortType = $nSortType_getter($card_type);
+        if($nSortType === false) {
+            return [];
+        }
+
         $params = [
             'szAgentId' => config::szAgentId,
             'szOrderId' => $order_sn,
             'szPhoneNum'=> "$phone",
             'nMoney' => $amount,
-            'nSortType' => $nSortType($card_type),
+            'nSortType' => $nSortType,
             'nProductClass' => 1,
             'nProductType' =>"1",
             'szTimeStamp'=> date("Y-m-d H:i:s"),
@@ -46,9 +48,10 @@ class RefillPhone extends refill\IRefillPhone
         ];
 
         $params['szVerifyString'] = config::sign($params,config::add_keys);
-
         return $params;
     }
+
+    //[$state, $errmsg, $neterr]
     public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
     {
         $params = $this->add_params($card_no, $amount, $params['order_sn'], $card_type);
@@ -57,7 +60,6 @@ class RefillPhone extends refill\IRefillPhone
         }
 
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false , [] , $net_errno);
-
         if (empty($resp)) {
             return [false, '网络错误', true];
         }
@@ -73,12 +75,12 @@ class RefillPhone extends refill\IRefillPhone
             $nRtn = $resp['nRtn'];
             if ($nRtn === 0) {      //下单成功
                 return [true, $resp['szOrderId'], false];
-            } elseif (in_array($nRtn, config::ERRCODES, true)) { //下单错误
+            } elseif (in_array($nRtn, config::ERRCODES, true)) {
                 return [false, config::ERRMSG[$nRtn], false];
-            } elseif (in_array($nRtn, [2050, 999] )) { //下单异常
+            } elseif (in_array($nRtn, [2050, 999])) { //下单异常
                 $net_errno = "HTTP-$nRtn";
                 return [false, config::ERRMSG[$nRtn], true];
-            }else {
+            } else {
                 $net_errno = "HTTP-998";
                 return [false, "其他异常", true];
             }
@@ -116,26 +118,22 @@ class RefillPhone extends refill\IRefillPhone
             $official_sn = '';
 
             $nRtn = intval($resp['nRtn']);
-            if($nRtn === 5012)//充值成功
-            {
+            if ($nRtn === 5012) {
                 $updata['official_sn'] = $resp['szRtnMsg'];
                 Model('refill_order')->edit($refill_info['szOrderId'], $updata);
                 $order_state = ORDER_STATE_SUCCESS;
             }
-            elseif($nRtn === 5011 or $nRtn === 5019)//充值中
-            {
-                $order_state = ORDER_STATE_SEND;
+            elseif($nRtn === 5013) {
+                $order_state = ORDER_STATE_CANCEL;
             }
-            elseif($nRtn === 5001 or $nRtn === 5002 or $nRtn === 5003 or $nRtn === 5004 or $nRtn === 999)//不处理订单
-            {
+            elseif (in_array($nRtn, [999, 5001, 5002, 5003, 5004, 5011, 5019])) {
                 $order_state = ORDER_STATE_SEND;
             }
-            elseif($nRtn === 5005 and (time() - $refill_info['commit_time'] >= 300))//订单可能不存在
-            {
+            elseif($nRtn === 5005 and (time() - $refill_info['commit_time'] >= 300)) {
                 $order_state = ORDER_STATE_NOEXIST;
             }
             else {
-                return [false, '其他,或网络错误'];
+                return [false, '其他,或网络错误', ''];
             }
 
             return [true, $order_state, $official_sn];
@@ -145,18 +143,10 @@ class RefillPhone extends refill\IRefillPhone
     private function balance_params()
     {
         $params = [
-            'szAgentId' => config::szAgentId,
-            'szFormat' => 'JSON',
+            'szAgentId' => config::szAgentId
         ];
 
-        $signer = function ($params)
-        {
-            $body = "szAgentId={$params['szAgentId']}&"."szKey=".config::szKey;
-
-            return strtolower(md5($body));
-        };
-
-        $params['szVerifyString'] = $signer($params);
+        $params['szVerifyString'] = config::sign($params, config::balance_keys);
         return $params;
     }
     public function balance(): array
@@ -174,13 +164,8 @@ class RefillPhone extends refill\IRefillPhone
             if (empty($resp)) {
                 return [false, '系统错误'];
             } elseif ($resp['nRtn'] === 0) {
-                return [true, ncPriceFormat($resp['fBalance']+$resp['fCredit'])];
+                return [true, ncPriceFormat($resp['fBalance'] + $resp['fCredit'])];
             } else {
-                switch($resp['nRtn']){
-                    case 1 : return [false, '请求失败'];
-                    case 5002 : return [false, '查询频繁'];
-                    case 999 : return [false, '系统异常'];
-                }
                 return [false, '其它,失败'];
             }
         }

+ 17 - 28
helper/refill/api/mh/seven_kami/config.php

@@ -6,23 +6,19 @@ class config
     const szAgentId = '200493';
     const szKey = 'f7bcc5362458979d0ff146db426404f3';
 
-    const ORDER_URL = 'http://42.193.245.133:5001/plat/api/old/submitorder';
-    const QUERY_URL = 'http://42.193.245.133:5001/plat/api/old/queryorder';
+    const ORDER_URL   = 'http://42.193.245.133:5001/plat/api/old/submitorder';
+    const QUERY_URL   = 'http://42.193.245.133:5001/plat/api/old/queryorder';
     const BALANCE_URL = 'http://42.193.245.133:5001/plat/api/old/queryBalance';
+    const NOTIFY_URL  = BASE_SITE_URL . "/racc/callback/mh/seven_kami.php";
 
-    const NOTIFY_URL = BASE_SITE_URL . "/racc/callback/mh/seven_kami.php";
-
-    public const add_keys = ['szAgentId', 'szOrderId', 'szPhoneNum', 'nMoney',
-        'nSortType','nProductClass','nProductType','szTimeStamp','szKey'];
-    public const callback_keys = ['szAgentId', 'szOrderId', 'szPhoneNum', 'nDemo',
-        'fSalePrice','nFlag','szKey'];
+    public const add_keys = ['szAgentId', 'szOrderId', 'szPhoneNum', 'nMoney', 'nSortType', 'nProductClass', 'nProductType', 'szTimeStamp', 'szKey'];
     public const query_keys = ['szAgentId', 'szOrderId', 'szKey'];
+    public const balance_keys = ['szAgentId', 'szKey'];
+    public const callback_keys = ['szAgentId', 'szOrderId', 'szPhoneNum', 'nDemo', 'fSalePrice', 'nFlag', 'szKey'];
 
+    public const ERRCODES = [1000, 1001, 1003, 1004, 1023, 1024, 1025, 1026, 2001, 2002, 2003, 2020, 2021, 2025, 2026, 1006, 2030, 3003];
 
-    const ERRCODES = [1000, 1001, 1003, 1004, 1023, 1024, 1025, 1026, 2001, 2002,
-        2003, 2020, 2021, 2025, 2026, 1006, 2030, 3003];
-
-    const ERRMSG = [
+    public const ERRMSG = [
         1000 => '系统接口维护',
         1001 => 'szTimeStamp参数时间格式错误',
         1003 => 'szTimeStamp时间参数与我方收到订单的时间晚于1分钟以上',
@@ -42,32 +38,25 @@ class config
         2030 => '卡资源不足或产品没有配置或关闭',
         3003 => '订单已存在',
         2050 => '下单异常',
-        999  => '系统异常'
+        999 => '系统异常'
     ];
 
     public static function sign($params,$keys)
     {
-        $str = '';
-        $num = count($keys);
+        $items = [];
         foreach ($keys as $key)
         {
-            $str .= $key;
-            if($key == 'szKey') {
-                $str .= "=";
-                $str .= config::szKey;
-            }
-            else {
+            if ($key == 'szKey') {
+                $item = "szKey=" . config::szKey;
+            } else {
                 $val = $params[$key] ?? '';
-                $str .= "=";
-                $str .= $val;
+                $item = "$key=$val";
             }
 
-            $num --;
-            if($num > 0) {
-                $str .= "&";
-            }
+            $items[] = $item;
         }
 
-        return strtolower(md5($str));
+        $signStr = implode('&', $items);
+        return strtolower(md5($signStr));
     }
 }

+ 6 - 3
racc/callback/mh/seven_kami.php

@@ -1,5 +1,8 @@
 <?php
+
 $content = $_SERVER['post_content'];
-Log::record("seven_kami content=$content",Log::DEBUG);
-refill\util::push_notify('seven_kami',$_POST);
-echo ('ok');
+Log::record("seven_kami content=$content", Log::DEBUG);
+
+refill\util::push_notify('seven_kami', $_POST);
+
+echo('ok');