瀏覽代碼

by_online_copy

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

+ 39 - 0
helper/refill/api/zy/by_online_copy/API信息.txt

@@ -0,0 +1,39 @@
+测试域名 http://commapitest.bjzykj.work
+正式域名 http://commapi.bjzykj.work
+
+APPid:8
+version 1.0 版本号 默认 1.0
+APPkey:Hfkobw838p6rw7Y
+
+
+1 北京
+2 天津
+3 上海
+4 重庆
+5 河北
+6 山西
+8 辽宁
+9 吉林
+10 黑龙江
+11 江苏
+12 浙江
+13 安徽
+14 福建
+15 江西
+16 山东
+17 河南
+18 湖北
+19 湖南
+20 广东
+21 甘肃
+22 四川
+23 贵州
+24 海南
+25 云南
+26 青海
+27 陕西
+28 广西
+29 西藏
+30 宁夏
+31 新疆
+32 内蒙古

+ 44 - 0
helper/refill/api/zy/by_online_copy/RefillCallBack.php

@@ -0,0 +1,44 @@
+<?php
+namespace refill\by_online_copy;
+
+require_once(BASE_HELPER_RAPI_PATH . '/by_online_copy/config.php');
+
+use refill;
+use QueueClient;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = config::sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['order_status']);
+        $order_sn = $params['merchantorder_no'];
+        $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false, false];
+        }
+        $order_id = $order_info['order_id'];
+
+        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];
+        }
+    }
+}

+ 248 - 0
helper/refill/api/zy/by_online_copy/RefillPhone.php

@@ -0,0 +1,248 @@
+<?php
+
+namespace refill\by_online_copy;
+
+require_once(BASE_HELPER_RAPI_PATH . '/by_online_copy/config.php');
+require_once(BASE_HELPER_RAPI_PATH . '/by_online_copy/hnyd.php');
+
+use refill;
+use Log;
+use Cache;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        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;
+        $params['version'] = '1.0';
+        $params['merchantOrderNo'] = $order_sn;
+        $params['productId'] = 1;
+        $params['account'] = "{$phone}";
+        $params['amt'] = $amount * 100;
+        $params['callbackUrl'] = config::NOTIFY_URL;
+        $params['provinceId'] = config::ProvinceMap[$regin_no];
+        $params['parameter'] = '';
+        $params['extra'] = '';
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
+    {
+        $regin_no = $params['regin_no'] ?? -1;
+        if ($regin_no <= 0) {
+            return [false, '省份获取错误', false];
+        }
+
+        $order_sn = $params['order_sn'];
+        $params = $this->req_params($card_no, $amount, $card_type, $params['order_sn'], $regin_no);
+        $sign = config::sign($params);
+        $params['sign'] = $sign;
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::ORDER_URL, $params, config::ExtHeaders, $net_errno);
+
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($resp['code'] === 1000) {
+                Model()->table('refill_order')->where(['order_sn' => $order_sn])->update(['official_sn' => $resp['data']['charge_id']]);
+                return [true, $resp['data']['order_sn'], false];
+            } elseif ($resp['code'] === 1001) {
+                $err = 998;
+                $net_errno = "HTTP-$err";
+                return [false, $resp['msg'], true];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $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);
+            $resp = json_decode($resp, true);
+
+            if (empty($resp)) {
+                return [false, '网络错误', ''];
+            }
+            elseif($resp['code'] === 1000)
+            {
+                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];
+                        return [true, ORDER_STATE_CANCEL, $charge_id];
+                    }
+                    else {
+                        return [false, '没有移动返回的原始数据', ''];
+                    }
+                }
+            }
+            else {
+                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;
+        $params['version'] = '1.0';
+        $sign = config::sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::BALANCE_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) {
+                return [true, $resp['data']['balance'] / 100];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function exist($card_no)
+    {
+        $ins = Cache::getInstance('cacheredis');
+        $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]);
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    //[是否需要返销,是否网络错误]
+    public function need_refund($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, true];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, true];
+            } 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];
+                }
+            } else {
+                return [false, false];
+            }
+        }
+    }
+}

+ 59 - 0
helper/refill/api/zy/by_online_copy/config.php

@@ -0,0 +1,59 @@
+<?php
+namespace refill\by_online_copy;
+
+class config
+{
+    const ORDER_URL = 'http://commapi.bjzykj.work/comm/recharge';
+    const QUERY_URL = 'http://commapi.bjzykj.work/comm/orderQuery';
+    const BALANCE_URL = 'http://commapi.bjzykj.work/comm/account';
+
+    const APP_ID = '8';
+    const APP_KEY = 'Hfkobw838p6rw7Y';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_by_online_copy.php";
+    const ExtHeaders = ['Content-Type: application/json'];
+
+    public static function sign($params)
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            $content .= "{$key}={$value}&";
+        }
+        $content .= config::APP_KEY;
+        return md5($content);
+    }
+
+    const ProvinceMap = [
+        1	=> 1,  //'北京',
+        2	=> 2,  //'天津',
+        3	=> 5, //'河北',
+        4	=> 6, //'山西',
+        5	=> 32,  //'内蒙古',
+        6	=> 8,  //'辽宁',
+        7	=> 9,  //'吉林',
+        8	=> 10,  //'黑龙江',
+        9	=> 3,  //'上海',
+        10	=> 11, //'江苏',
+        11	=> 12, //'浙江',
+        12	=> 13, //'安徽',
+        13	=> 14, //'福建',
+        14	=> 15, //'江西',
+        15	=> 16, //'山东',
+        16	=> 17,  //'河南',
+        17	=> 18, //'湖北',
+        18	=> 19, //'湖南',
+        19	=> 20, //'广东',
+        20	=> 28, //'广西',
+        21	=> 24, //'海南',
+        22	=> 4,  //'重庆',
+        23	=> 22, //'四川',
+        24	=> 23, //'贵州',
+        25	=> 25, //'云南',
+        26	=> 29, //'西藏',
+        27	=> 27, //'陕西',
+        28	=> 21, //'甘肃',
+        29	=> 26, //'青海',
+        30	=> 30, //'宁夏',
+        31	=> 31  //'新疆'
+    ];
+}

+ 117 - 0
helper/refill/api/zy/by_online_copy/hnyd.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace refill\by_online_copy;
+
+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);
+            }
+            elseif($chid === '1111111111') {
+                return new record($record);
+            }
+        }
+
+        return false;
+    }
+
+    public function record_count()
+    {
+        $count = intval($this->mResult['X_RECORDNUM'] ?? 0);
+        return $count;
+    }
+}

二進制
helper/refill/api/zy/by_online_copy/纸莺运营商数据管理平台对外接口.pdf


+ 4 - 0
mobile/callback/refill_by_online_copy.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('by_online_copy',$_POST);
+echo ('success');