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

+ 0 - 14
helper/refill/api/mh/gy_normal/API.MD

@@ -1,14 +0,0 @@
-智信LT
-账号:zhixinltong
-密码:schoi_78
-地址:https://admin.xyzshops.cn/merchant/#/login
-
-
-下单:https://www.xyzshops.cn/mobile/index.php
-余额:https://www.xyzshops.cn/mobile/index.php
-查询:https://www.xyzshops.cn/mobile/index.php
-
-商户id:
-10503
-密钥:beaf87f87c6bcb8a98b853c207ca9aef
-

+ 15 - 23
helper/refill/api/mh/gy_normal/RefillCallBack.php

@@ -1,18 +1,15 @@
 <?php
-
 namespace refill\gy_normal;
 
 require_once(BASE_HELPER_RAPI_PATH . '/gy_normal/config.php');
-
 use refill;
-
 class RefillCallBack implements refill\IRefillCallBack
 {
     public function verify($params): bool
     {
         $input = $params;
         unset($input['sign']);
-        $sign = config::sign($input,config::notify_keys);
+        $sign = config::sign($input);
         if ($params['sign'] == $sign) {
             return true;
         } else {
@@ -20,32 +17,27 @@ class RefillCallBack implements refill\IRefillCallBack
         }
     }
 
-    //[$order_id, $success, $can_try, $need_handle, $official_sn]
-    public function notify($params): array
+    public function notify($params)
     {
+        $status = $params['state'];
         $order_sn = $params['order_sn'];
-        $ch_trade_no = $params['trade_no'];
-        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
-
+        $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
         if (empty($order_info)) {
-            return [false, false, false, false, ''];
+            return [false, false, false,false];
         }
-
         $order_id = $order_info['order_id'];
-        $official_sn = $params['official_sn'] ?? '';
-
-        //订单状态 SUCCESS表示充值成功,CANCEL表示充值失败订单取消.
-        $status = $params['state'];
-        if ($status == 'SUCCESS') {
-            Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no, 'official_sn' => $official_sn]);
-            return [$order_id, true, false, true, $official_sn];
+        if ($status === 'SUCCESS') {
+            $data['ch_trade_no'] = $params['trade_no'];
+            $data['official_sn'] = strtolower($params['official_sn']) == 'null' ? '' : $params['official_sn'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
         }
-        elseif ($status == 'CANCEL') {
-            Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no]);
-            return [$order_id, false, true, true, ''];
+        elseif ($status === 'CANCEL') {
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['trade_no']]);
+            return [$order_id, false, true,true];
         }
         else {
-            return [$order_id, false, false, false, ''];
+            return [$order_id, false, false,false];
         }
     }
-}
+}

+ 46 - 66
helper/refill/api/mh/gy_normal/RefillPhone.php

@@ -14,99 +14,81 @@ class RefillPhone extends refill\IRefillPhone
         parent::__construct($cfgs);
     }
 
-    private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
+    private function req_params(int $phone, int $amount, string $order_sn)
     {
-        $input = [
-            'act'        => 'refill',
-            'amount'     => $amount,
-            'cardno'     => $phone,
-            'mchid'      => config::id,
-            'notifyurl'  => config::NOTIFY_URL,
-            'op'         => 'add',
-            'order_sn'   => $order_sn,
-        ];
-
-        $params =  config::gen_params($input,config::add_keys);
-        return  $params;
+        $params['act'] = 'refill';
+        $params['op'] = 'add';
+        $params['mchid'] = config::MCH_ID;
+        $params['cardno'] = $phone;
+        $params['amount'] = $amount;
+        $params['order_sn'] = $order_sn;
+        $params['notifyurl'] = config::NOTIFY_URL;
+        return $params;
     }
 
-    //[$state, $errmsg, $neterr]
-    public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
     {
-        $params = $this->add_params($card_no, $amount, $params['order_sn'], $card_type);
-        if(empty($params)) {
-            return [false, '提单参数不符合', false];
-        }
+        $params = $this->req_params($card_no, $amount, $params['order_sn']);
+        $sign = config::sign($params);
+        $params['sign'] = $sign;
 
-        $resp = http_request(config::ORDER_URL, $params, 'POST', false, [], $net_errno);
+        $resp = http_request(config::ORDER_URL, $params , 'POST' , false , [] , $net_errno);
         if (empty($resp)) {
             return [false, '系统错误', true];
         }
         else
         {
             Log::record($resp, Log::DEBUG);
-            $resp = json_decode($resp, true);
+            $resp = json_decode($resp ,true);
             if (empty($resp)) {
                 return [false, '系统错误', true];
             } elseif ($resp['code'] === 200) {
-                return [true, $resp['order_sn'], false];  //好像没有这个sn!!!
+                return [true, '', false];
             } else {
                 return [false, $resp['message'], false];
             }
         }
     }
 
-    public function query($refill_info): array
+    public function query($refill_info)
     {
-        $input = [
-            'act'       => 'refill',
-            'mchid'     => config::id,
-            'op'        => 'query',
-            'order_sn'  => $refill_info['order_sn']
-        ];
-        $params = config::gen_params($input,config::query_keys);
+        $params['act'] = 'refill';
+        $params['op'] = 'query';
+        $params['mchid'] = config::MCH_ID;
+        $params['order_sn'] = $refill_info['order_sn'];
+        $params['sign'] = config::sign($params);
 
-        $resp = http_request(config::QUERY_URL, $params , 'POST');
+        $resp = http_request(config::ORDER_URL, $params , 'POST');
         if (empty($resp)) {
-            return [false, '系统错误', ''];
+            return [false, '系统错误'];
         }
         else
         {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp, true);
             if (empty($resp)) {
-                return [false, '系统错误', ''];
+                return [false, '系统错误'];
             }
-
-            $code = intval($resp['code']);
-            if ($code === 200)
+            elseif ($resp['code'] === 200)
             {
-                $val = $resp['datas'];
-                $status = intval($val['order_state']);
-                $official_sn = intval($val['official_sn']);
-
-                //订单状态
-                //      0,订单已经取消,充值失败会取消订单。
-                //     10,新订单
-                //     20,已经支付
-                //     30,正在处理
-                //     40,充值成功
-                //     50,排队中
-                if ($status == '40') {
-                    Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['trade_no'],'official_sn' => $official_sn]);
+                $data = $resp['datas'];
+                if ($data['order_state'] == '40') {
+                    $save['ch_trade_no'] = $data['trade_no'];
+                    $save['official_sn'] = strtolower($resp['official_sn']) == 'null' ? '' : $resp['official_sn'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
                     $order_state = ORDER_STATE_SUCCESS;
-                }
-                elseif ($status == '0') {
-                    Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['trade_no']]);
+                } elseif ($data['order_state'] === '0') {
+                    Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $data['trade_no']]);
                     $order_state = ORDER_STATE_CANCEL;
-                }
-                else {
+                } elseif (in_array($data['order_state'], ['10', '20', '30', '50'], true)) {
                     $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['message']];
                 }
-                return [true, $order_state, $official_sn];
+                return [true, $order_state];
             }
-            elseif($code === 202 and (time() - $refill_info['commit_time']) >= 300) {
-                return [true, ORDER_STATE_NOEXIST, ''];
+            elseif ($resp['code'] === 202 && (time() - $refill_info['commit_time'] >= 300)) {
+                return [true, ORDER_STATE_NOEXIST];
             }
             else {
                 return [false, $resp['message']];
@@ -114,16 +96,14 @@ class RefillPhone extends refill\IRefillPhone
         }
     }
 
-    public function balance(): array
+    public function balance()
     {
-        $input = [
-            'act'   => 'refill',
-            'mchid' => config::id,
-            'op'    => 'balance',
-        ];
-        $params = config::gen_params($input,config::balance_keys);
+        $params['act'] = 'refill';
+        $params['op'] = 'balance';
+        $params['mchid'] = config::MCH_ID;
+        $params['sign'] = config::sign($params);
 
-        $resp = http_request(config::BALANCE_URL, $params , 'POST');
+        $resp = http_request(config::ORDER_URL, $params , 'POST');
         if (empty($resp)) {
             return [false, '系统错误'];
         }
@@ -134,7 +114,7 @@ class RefillPhone extends refill\IRefillPhone
             if (empty($resp)) {
                 return [false, '系统错误'];
             } elseif ($resp['code'] === 200) {
-                return [true, ncPriceFormat($resp['datas']['balance']+$resp['datas']['credit'])];
+                return [true, $resp['datas']['balance']];
             } else {
                 return [false, $resp['message']];
             }

+ 7 - 0
helper/refill/api/mh/gy_normal/api.txt

@@ -0,0 +1,7 @@
+https://ylweb.xyzshops.cn/merchant/#/login
+
+yezidianxin03
+yezidx03
+
+10311
+b7a2ad26ca0dc2e13599a8f7c529677d

+ 30 - 34
helper/refill/api/mh/gy_normal/config.php

@@ -3,50 +3,46 @@
 namespace refill\gy_normal;
 
 class config
-{   public const id = '10503';
-    public const szKey = 'beaf87f87c6bcb8a98b853c207ca9aef';
+{
+    public const MCH_ID = 10503;
+    public const KEY = 'beaf87f87c6bcb8a98b853c207ca9aef';
 
     public const ORDER_URL = 'https://www.xyzshops.cn/mobile/index.php';
-    public const QUERY_URL = 'https://www.xyzshops.cn/mobile/index.php';
-    public const BALANCE_URL = 'https://www.xyzshops.cn/mobile/index.php';
     public const NOTIFY_URL = BASE_SITE_URL . "/racc/callback/mh/gy_normal.php";
 
 
-    public const add_keys = ['act', 'amount', 'cardno', 'mchid', 'notifyurl' ,'op', 'order_sn'];
-    public const query_keys = ['act', 'mchid', 'op', 'order_sn'];
-    public const balance_keys = ['act', 'mchid', 'op'];
-    public const notify_keys = ['amount', 'cardno', 'card_name', 'idcard', 'mchid', 'message', 'official_sn', 'order_sn', 'state', 'trade_no'];
-
-    public static function sign($params, $keys): string
+    public static function sign($params)
     {
-        $str = '';
-        $num = count($keys);
-        foreach ($keys as $key)
+        $empty_checker = function ($value)
+        {
+            if (!isset($value))
+                return true;
+            if ($value === null)
+                return true;
+            if (trim($value) === "")
+                return true;
+
+            return false;
+        };
+
+        ksort($params);
+
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v)
         {
-            $num --;
-            if($params[$key] != null && $params[$key] != ''){
-                $str .= $key;
-                $str .= "=";
-                $str .= urlencode($params[$key]);
-
-                if($num > 0) {
-                    $str .= "&";
+            if (false === $empty_checker($v) && "@" != substr($v, 0, 1))
+            {
+                if ($i == 0) {
+                    $body .= "$k" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "$k" . "=" . urlencode($v);
                 }
+                $i++;
             }
         }
 
-        $str .= "&key=".config::szKey;
-
-        return md5($str);
-    }
-
-    public static function gen_params($params,$keys)
-    {
-        $params['sign'] = config::sign($params,$keys);
-        return $params;
-    }
-    public static function time_stamp ()
-    {
-        return date('YmdHis', time());
+        $body .= "&key=".config::KEY;
+        return md5($body);
     }
 }