stanley-king před 1 rokem
rodič
revize
934d51630b

+ 15 - 6
helper/refill/api/mh/zhixin_fast/RefillCallBack.php

@@ -27,15 +27,24 @@ class RefillCallBack implements refill\IRefillCallBack
         if (empty($order_info)) {
             return [false, false, false, false, ''];
         }
+
         $order_id = $order_info['order_id'];
-        $code = intval($params['recharge_status']);
-        if ($code === 2) {
-            $official_sn = $params['elecardID'] ?? '';
-            Model('refill_order')->edit($order_id, ['official_sn' => $official_sn]);
+        $recharge_status = intval($params['recharge_status']);
+
+        if ($recharge_status === 2) {
+            $official_sn = $resp['data']['elecardID']   ?? '';
+            $ch_trade_no = $resp['data']['up_order_no'] ?? '';
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no,'official_sn' => $official_sn]);
+
             return [$order_id, true, false, true, $official_sn];
-        } elseif ($code === 6) {
+        }
+        elseif ($recharge_status === 6) {
+            $ch_trade_no = $resp['data']['up_order_no'] ?? '';
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no]);
+
             return [$order_id, false, true, true, ''];
-        } else{
+        }
+        else{
             return [$order_id, false, false, false, ''];
         }
     }

+ 48 - 35
helper/refill/api/mh/zhixin_fast/RefillPhone.php

@@ -17,7 +17,7 @@ class RefillPhone extends refill\IRefillPhone
 
     private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
     {
-        $nSortType_getter = function ($card_type)
+        $cp_getter = function ($card_type)
         {
             if ($card_type == mtopcard\ChinaMobileCard) {
                 return "01";
@@ -30,20 +30,20 @@ class RefillPhone extends refill\IRefillPhone
             }
         };
 
-        $nSortType = $nSortType_getter($card_type);
-        if($nSortType === false) {
+        $cp = $cp_getter($card_type);
+        if ($cp === false) {
             return [];
         }
 
         $params = [
-            'mrch_no' => config::szAgentId,
+            'mrch_no' => config::MRCH_NO,
             'request_time' => date('YmdHis'),
             'client_order_no' => $order_sn,
             'product_type' => 1,
-            'phone_no'=> "$phone",
-            'cp' => $nSortType,
+            'phone_no' => "$phone",
+            'cp' => $cp,
             'city_code' => "",
-            'recharge_amount' => $amount*100,
+            'recharge_amount' => $amount * 100,
             'recharge_type' => 0,
             'recharge_desc' => "",
             'notify_url' => config::NOTIFY_URL,
@@ -57,11 +57,11 @@ class RefillPhone extends refill\IRefillPhone
     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);
-        if(empty($params)) {
+        if (empty($params)) {
             return [false, '提单参数不符合', false];
         }
-        $resp = http_post_data(config::ORDER_URL, json_encode($params) , config::ExtHeaders);
 
+        $resp = http_post_data(config::ORDER_URL, json_encode($params), config::ExtHeaders);
         if (empty($resp)) {
             return [false, '网络错误', true];
         }
@@ -75,16 +75,16 @@ class RefillPhone extends refill\IRefillPhone
             }
 
             $nRtn = intval($resp['code']);
-            if ($nRtn === 2) {      //下单成功
+            if ($nRtn === 2) {
                 return [true, $resp['data']['up_order_no'], false];
             } elseif (in_array($nRtn, config::ERRCODES, true)) {
                 return [false, config::ERRMSG[$nRtn], false];
-            } elseif (in_array($nRtn, [625])) { //下单存疑,人工核实
+            } elseif (in_array($nRtn, [625])) {
                 $net_errno = "HTTP-$nRtn";
-                return [false, "重复订单号", true];
+                return [false, $net_errno, true];
             } else {
                 $net_errno = "HTTP-998";
-                return [false, "其他异常", true];
+                return [false, $net_errno, true];
             }
         }
     }
@@ -92,20 +92,20 @@ class RefillPhone extends refill\IRefillPhone
     private function query_params($refill_info)
     {
         $params = [
-            'mrch_no' => config::szAgentId,
+            'mrch_no' => config::MRCH_NO,
             'request_time' => date('YmdHis'),
-            'client_order_no'   => $refill_info['order_sn'],
-            'order_time'   => date('YmdHis')
+            'client_order_no' => $refill_info['order_sn'],
+            'order_time' => date('YmdHis')
         ];
-
         $params['sign'] = config::sign($params);
+
         return $params;
     }
 
     public function query($refill_info): array
     {
         $params = $this->query_params($refill_info);
-        $resp = http_post_data(config::QUERY_URL, json_encode($params) , config::ExtHeaders);
+        $resp = http_post_data(config::QUERY_URL, json_encode($params), config::ExtHeaders);
 
         if (empty($resp)) {
             return [false, '系统错误', ''];
@@ -114,28 +114,42 @@ class RefillPhone extends refill\IRefillPhone
         {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp, true);
+
             if (empty($resp)) {
                 return [false, '系统错误', ''];
             }
+
             $official_sn = '';
             $nRtn = intval($resp['code']);
-            if ($nRtn === 2) {
-                if($resp['data']['recharge_status']=="1")//交易中
-                {
-                    $order_state = ORDER_STATE_SEND;
-                }elseif ($resp['data']['recharge_status']=="2") //交易成功
-                {
-                    $official_sn = $resp['data']['elecardID'] ?? '';
-                    Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => ($resp['data']['elecardID'] ?? '')]);
+            if ($nRtn === 2)
+            {
+                $order_id = $refill_info['order_id'];
+                $recharge_status = $resp['data']['recharge_status'];
+
+                if ($recharge_status == "2") {
+                    $official_sn = $resp['data']['elecardID']   ?? '';
+                    $ch_trade_no = $resp['data']['up_order_no'] ?? '';
+                    Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no,'official_sn' => $official_sn]);
+
                     $order_state = ORDER_STATE_SUCCESS;
-                }else{//交易失败
+                }
+                elseif($recharge_status == "6") {
+                    $ch_trade_no = $resp['data']['up_order_no'] ?? '';
+                    Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no]);
+
                     $order_state = ORDER_STATE_CANCEL;
                 }
-            } elseif($nRtn == 626 && (time() - $refill_info['commit_time'] >= 600)){
+                else {
+                    $order_state = ORDER_STATE_SEND;
+                }
+            }
+            elseif ($nRtn == 626 && (time() - $refill_info['commit_time'] >= 600)) {
                 $order_state = ORDER_STATE_NOEXIST;
-            } else{
+            }
+            else {
                 return [false, '其他,或网络错误', ''];
             }
+
             return [true, $order_state, $official_sn];
         }
     }
@@ -143,29 +157,28 @@ class RefillPhone extends refill\IRefillPhone
     private function balance_params()
     {
         $params = [
-            'mrch_no' => config::szAgentId,
+            'mrch_no' => config::MRCH_NO,
             'request_time' => date('YmdHis')
         ];
 
         $params['sign'] = config::sign($params);
         return $params;
     }
+
     public function balance(): array
     {
         $params = $this->balance_params();
-        $resp = http_post_data(config::BALANCE_URL, json_encode($params) , config::ExtHeaders);
+        $resp = http_post_data(config::BALANCE_URL, json_encode($params), config::ExtHeaders);
 
         if (empty($resp)) {
             return [false, '系统错误'];
-        }
-        else
-        {
+        } else {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp, true);
             if (empty($resp)) {
                 return [false, '系统错误'];
             } elseif (intval($resp['code']) === 2) {
-                return [true, ncPriceFormat($resp['data']['balance']+$resp['data']['credit'])];
+                return [true, ncPriceFormat($resp['data']['balance'] + $resp['data']['credit'])];
             } else {
                 return [false, '其它,失败'];
             }

+ 9 - 7
helper/refill/api/mh/zhixin_fast/config.php

@@ -3,8 +3,8 @@
 namespace refill\zhixin_fast;
 class config
 {
-    const szAgentId = '101103449';
-    const secret_key = '2Zg0QRxCmFSZEvtEmOH2q6pO8ZmqgAGk';
+    const MRCH_NO = '101103449';
+    const SECRET_KEY = '2Zg0QRxCmFSZEvtEmOH2q6pO8ZmqgAGk';
 
     const ORDER_URL   = 'http://api.julives.com:9080/zxpaycore/v2/recharge';
     const QUERY_URL   = 'http://query.julives.com:9080/zxpaycore/v2/query';
@@ -31,12 +31,14 @@ class config
     public static function sign($params)
     {
         ksort($params);
+
         $body = "";
-        foreach ($params as $k => $v)
-        {
-            $body .= "$k" . "$v";
+        foreach ($params as $k => $v) {
+            $item = "$k" . "$v";
+            $body .= $item;
         }
-        $body .= config::secret_key;
-        return md5($body);
+        $body .= config::SECRET_KEY;
+
+        return strtolower(md5($body));
     }
 }