瀏覽代碼

zy by_online

xiaoyu 1 年之前
父節點
當前提交
de684fa5f0

+ 1 - 1
helper/refill/api/xyz/by_online/RefillPhone.php

@@ -239,4 +239,4 @@ class RefillPhone extends refill\IRefillPhone
             }
         }
     }
-}
+}

+ 11 - 10
helper/refill/api/zy/by_online/RefillCallBack.php

@@ -29,16 +29,17 @@ class RefillCallBack implements refill\IRefillCallBack
             return [false, false, false, false];
         }
         $order_id = $order_info['order_id'];
+        return [$order_id, false, false, false];
 
-        if ($status === 7) {
-            $data['official_sn'] = strtolower($params['charge_id']) == 'null' ? '' : $params['charge_id'];
-            Model('refill_order')->edit($order_id, $data);
-            QueueClient::async_push("QueryRefund", ['order_id' => $order_id], 3600);
-            return [$order_id, true, false, true];
-        } elseif (in_array($status, [3, 4, 6], true)) {
-            return [$order_id, false, true, true];
-        } else {
-            return [$order_id, false, false, false];
-        }
+//        if ($status === 7) {
+//            $data['official_sn'] = strtolower($params['charge_id']) == 'null' ? '' : $params['charge_id'];
+//            Model('refill_order')->edit($order_id, $data);
+//            QueueClient::async_push("QueryRefund", ['order_id' => $order_id], 3600);
+//            return [$order_id, true, false, true];
+//        } elseif (in_array($status, [3, 4, 6], true)) {
+//            return [$order_id, false, true, true];
+//        } else {
+//            return [$order_id, false, false, false];
+//        }
     }
 }

+ 90 - 39
helper/refill/api/zy/by_online/RefillPhone.php

@@ -3,6 +3,7 @@
 namespace refill\by_online;
 
 require_once(BASE_HELPER_RAPI_PATH . '/by_online/config.php');
+require_once(BASE_HELPER_RAPI_PATH . '/by_online/hnyd.php');
 
 use refill;
 use Log;
@@ -15,6 +16,11 @@ class RefillPhone extends refill\IRefillPhone
         parent::__construct($cfgs);
     }
 
+    public function callback()
+    {
+        return false;
+    }
+
     private function req_params(int $phone, int $amount, int $card_type, string $order_sn, $regin_no)
     {
         $params['appId'] = config::APP_ID;
@@ -38,10 +44,6 @@ class RefillPhone extends refill\IRefillPhone
             return [false, '省份获取错误', false];
         }
 
-        if($this->exist($card_no)) {
-            return [false, '今日已经提交过', false];
-        }
-
         $params = $this->req_params($card_no, $amount, $card_type, $params['order_sn'], $regin_no);
         $sign = config::sign($params);
         $params['sign'] = $sign;
@@ -59,6 +61,7 @@ class RefillPhone extends refill\IRefillPhone
             if (empty($resp)) {
                 return [false, '系统错误', true];
             } elseif ($resp['code'] === 1000) {
+                Model()->table('refill_order')->where(['order_sn' => $params['order_sn']])->update(['official_sn' => $resp['data']['charge_id']]);
                 return [true, $resp['data']['order_sn'], false];
             } else {
                 return [false, $resp['msg'], false];
@@ -71,44 +74,98 @@ class RefillPhone extends refill\IRefillPhone
         $params['appId'] = config::APP_ID;
         $params['version'] = '1.0';
         $params['merchantOrderNo'] = $refill_info['order_sn'];
+        $params['is_HN'] = 2;
         $sign = config::sign($params);
         $params['sign'] = $sign;
 
+        $charge_id = $refill_info['official_sn'];
         $resp = http_request(config::QUERY_URL, $params);
-
         if (empty($resp)) {
             return [false, '网络错误', ''];
         }
         else
         {
-            Log::record($resp, Log::DEBUG);
+            Log::record($resp,Log::DEBUG);
             $resp = json_decode($resp, true);
+
             if (empty($resp)) {
-                return [false, '网络错误'];
+                return [false, '网络错误', ''];
             }
-            elseif ($resp['code'] === 1000)
+            elseif($resp['code'] === 1000)
             {
-                $status = $resp['data']['order_status'];
-                if ($status === 7) {
-                    $updata['official_sn'] = $resp['data']['charge_id'];
-                    Model('refill_order')->edit($refill_info['order_id'], $updata);
-                    $order_state = ORDER_STATE_SUCCESS;
-                } elseif (in_array($status, [3, 4, 6], true)) {
-                    $order_state = ORDER_STATE_CANCEL;
-                } elseif (in_array($status, [0, 1, 2, 5], true)) {
-                    $order_state = ORDER_STATE_SEND;
-                } else {
-                    return [false, $status];
+                if(empty($resp['data'])) {
+                    return [false, '没有移动返回的原始数据', ''];
+                }
+                else
+                {
+                    ksort($resp);
+                    $response = new response($resp['data']);
+                    $record = $response->find_record($charge_id);
+                    if($record !== false)
+                    {
+                        if ($record->canceled()) {
+                            $order_state = ORDER_STATE_CANCEL;
+                        } elseif ($record->successed()) {
+                            $order_state = ORDER_STATE_SUCCESS;
+                            Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $record->trade_id()]);
+                        } else {
+                            $order_state = ORDER_STATE_SEND;
+                        }
+
+                        return [true, $order_state, $charge_id];
+                    }
+                    elseif(time() - $refill_info['commit_time'] >= 2700) {
+                        return [true, ORDER_STATE_NOEXIST, $charge_id];
+                    }
+                    else {
+                        return [false, '没有移动返回的原始数据', ''];
+                    }
                 }
-
-                return [true, $order_state];
             }
             else {
-                return [false, $resp['msg']];
+                return [false, $resp['msg'], ''];
             }
         }
     }
 
+//    public function query($refill_info)
+//    {
+//        $params['appId'] = config::APP_ID;
+//        $params['version'] = '1.0';
+//        $params['merchantOrderNo'] = $refill_info['order_sn'];
+//        $sign = config::sign($params);
+//        $params['sign'] = $sign;
+//
+//        $resp = http_request(config::QUERY_URL, $params);
+//
+//        if (empty($resp)) {
+//            return [false, '网络错误', ''];
+//        } else {
+//            Log::record($resp, Log::DEBUG);
+//            $resp = json_decode($resp, true);
+//            if (empty($resp)) {
+//                return [false, '网络错误'];
+//            } elseif ($resp['code'] === 1000) {
+//                $status = $resp['data']['order_status'];
+//                if ($status === 7) {
+//                    $updata['official_sn'] = $resp['data']['charge_id'];
+//                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+//                    $order_state = ORDER_STATE_SUCCESS;
+//                } elseif (in_array($status, [3, 4, 6], true)) {
+//                    $order_state = ORDER_STATE_CANCEL;
+//                } elseif (in_array($status, [0, 1, 2, 5], true)) {
+//                    $order_state = ORDER_STATE_SEND;
+//                } else {
+//                    return [false, $status];
+//                }
+//
+//                return [true, $order_state];
+//            } else {
+//                return [false, $resp['msg']];
+//            }
+//        }
+//    }
+
     public function balance()
     {
         $params['appId'] = config::APP_ID;
@@ -136,14 +193,14 @@ class RefillPhone extends refill\IRefillPhone
     private function exist($card_no)
     {
         $ins = Cache::getInstance('cacheredis');
-        $today = strtotime(date('Ymd',time()));
+        $today = strtotime(date('Ymd', time()));
 
         $name = "unique_tongfu_{$today}";
         $key = "$card_no";
 
-        $value = $ins->hget($name,'',$key);
-        if($value === false) {
-            $ins->hset($name, '', [$key=> 1]);
+        $value = $ins->hget($name, '', $key);
+        if ($value === false) {
+            $ins->hset($name, '', [$key => 1]);
             return false;
         } else {
             return true;
@@ -163,28 +220,22 @@ class RefillPhone extends refill\IRefillPhone
 
         if (empty($resp)) {
             return [false, true];
-        }
-        else
-        {
+        } else {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp, true);
             if (empty($resp)) {
                 return [false, true];
-            }
-            elseif ($resp['code'] === 1000)
-            {
+            } elseif ($resp['code'] === 1000) {
                 $status = $resp['data']['order_status'];
                 $succeed = $resp['data']['is_true'];
 
                 if ($status === 7 and $succeed === false) {
-                    return [true,false];
-                }
-                else {
-                    return [false,false];
+                    return [true, false];
+                } else {
+                    return [false, false];
                 }
-            }
-            else {
-                return [false,true];
+            } else {
+                return [false, false];
             }
         }
     }

+ 114 - 0
helper/refill/api/zy/by_online/hnyd.php

@@ -0,0 +1,114 @@
+<?php
+
+namespace refill\by_online;
+
+class record
+{
+    private $mRecord;
+    public function __construct($record)
+    {
+        $this->mRecord = $record;
+    }
+
+    public function charge_id() {
+        return trim($this->mRecord['CHARGE_ID']);
+    }
+
+    public function trade_id() {
+        return trim($this->mRecord['OUT_TRADE_ID']);
+    }
+
+    public function fee()
+    {
+        return intval($this->mRecord['RECV_FEE']);
+    }
+
+    public function charge_time()
+    {
+        if(empty($this->mRecord['RECV_TIME'])) {
+            return false;
+        } else {
+            return strtotime($this->mRecord['RECV_TIME']);
+        }
+    }
+
+    public function canceled()
+    {
+        $id = trim($this->mRecord['CANCEL_CHARGE_ID']);
+        if(empty($id)) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    public function successed()
+    {
+        $charge_time = $this->charge_time();
+        if(empty($this->charge_id()) or empty($this->trade_id()) or $this->fee() <= 0 or $charge_time=== false or $charge_time <= 0) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+}
+
+
+class response
+{
+    private $mResult;
+    private $mRecords = [];
+    private $respCode;
+    public function __construct($resp)
+    {
+        $this->respCode = intval($resp['respCode']);
+        $this->mResult = $resp['result'];
+        ksort($this->mResult);
+
+        if(isset($this->mResult['data']))
+        {
+            $items = $this->mResult['data'];
+            foreach ( $items as $item)
+            {
+                ksort($item);
+                $this->mRecords[] = $item;
+            }
+            unset($this->mResult['data']);
+        }
+        else
+        {
+            $keys = [ "MONTH", "RECV_FEE", "RECV_TIME", "BIND_SERIAL_NUMBER",
+                "OUT_TRADE_ID", "GROUP_ID", "CHARGE_ID", "CANCEL_CHARGE_ID",
+                "CANCEL_TAG", "CANCEL_TIME", "REMARK", "LOCAL_SN", "CUST_NAME"];
+
+            $item = [];
+            foreach ($keys as $key) {
+                $item[$key] = $this->mResult[$key] ?? "";
+            }
+            ksort($item);
+            $this->mRecords[] = $item;
+            foreach ($keys as $key) {
+                unset($this->mResult[$key]);
+            }
+        }
+    }
+
+    public function find_record($charge_id)
+    {
+        foreach ($this->mRecords as $record)
+        {
+            $chid = $record['CHARGE_ID'];
+            if($chid == $charge_id) {
+                return new record($record);
+            }
+        }
+
+        return false;
+    }
+
+    public function record_count()
+    {
+        $count = intval($this->mResult['X_RECORDNUM'] ?? 0);
+        return $count;
+    }
+}