浏览代码

xyz guochuang_nation_sec

xiaoyu 2 年之前
父节点
当前提交
7b3235e9c2

+ 50 - 0
helper/refill/api/xyz/guochuang_nation_sec/RefillCallBack.php

@@ -0,0 +1,50 @@
+<?php
+
+
+namespace refill\guochuang_nation_sec;
+
+require_once(BASE_HELPER_RAPI_PATH . '/guochuang_nation_sec/config.php');
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::ApiKey;
+        $content = "{$params['body']}&ts={$params['ts']}&key={$key}";
+        return strtoupper(md5($content));
+    }
+
+    public function notify($params)
+    {
+        $params = json_decode($params['body'], true);
+        $status = $params['status'];
+        $order_sn = $params['outerId'];
+        $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 === 'SUCCESS') {
+            $data['official_sn'] = strtolower($params['evidence']) == 'null' ? '' : $params['evidence'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 'FAIL') {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 196 - 0
helper/refill/api/xyz/guochuang_nation_sec/RefillPhone.php

@@ -0,0 +1,196 @@
+<?php
+
+namespace refill\guochuang_nation_sec;
+
+require_once(BASE_HELPER_RAPI_PATH . '/guochuang_nation_sec/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function none_support($card_no)
+    {
+        return strpos($card_no, '148') === 0;
+    }
+
+    private function add_params(int $phone, int $amount, int $card_type, string $order_sn,$regin_no)
+    {
+        $params['phone'] = $phone;
+        $params['phoneType'] = config::operator[$card_type];
+        $params['money'] = $amount;
+        $params['outerId'] = $order_sn;
+        $params['callBackUrl'] = config::NOTIFY_URL;
+        $params['speed'] = 0;
+        $params['provId'] = config::ProvinceMap[$regin_no];
+
+        if(empty($params['provId'])) {
+            return false;
+        }
+        else {
+            return $params;
+        }
+    }
+
+    private function form_uri($params, $service)
+    {
+        $get_params['service'] = $service;
+        $get_params['userId'] = config::UserId;
+        $get_params['ts'] = $this->getMillisecond();
+
+        $sign = $this->sign($params,$get_params);
+        $get_params['sign'] = $sign;
+
+        $url = config::API_URL;
+        $uri = $url . (strpos($url, '?') ? '&' : '?') . (is_array($get_params) ? http_build_query($get_params) : $get_params);
+
+        return $uri;
+    }
+
+    public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
+    {
+        $order_sn = $input['order_sn'];
+        $regin_no = $input['regin_no'] ?? -1;
+        if($regin_no <= 0) {
+            return [false, '省份获取错误', false];
+        }
+        if($this->none_support($card_no)) {
+            return [false, '不支持物联网卡号', false];
+        }
+
+        $params = $this->add_params($card_no, $amount, $card_type, $order_sn,$regin_no);
+        if($params === false) {
+            return [false, '省份信息错误', false];
+        }
+
+        $uri = $this->form_uri($params,'order.phone.charge');
+        $resp = http_request($uri, $params, 'POST', false, [], $net_errno);
+
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+
+            $resp = json_decode($resp ,true);
+            $code = $resp['code'];
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($code === 'SUCCESS') {
+                return [true, $resp['id'], false];
+            } elseif (in_array($code, config::ORDER_ERR_CODE)) {
+                return [false, $code, false];
+            } elseif (in_array($code, ['SYSTEM_ERROR', 'ORDER_ID_EXIST'])) {
+                $net_errno = "HTTP-{$code}";
+                return [false, $code, true];
+            } else {
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $code, true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        //上游单号,可以为空,但需参与签名
+        $params['id'] = '';
+        $params['outerId'] = $refill_info['order_sn'];
+
+        $uri = $this->form_uri($params,'order.status.query');
+        $resp = http_request($uri, $params, 'POST');
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            $code = $resp['code'];
+            if (empty($resp))
+            {
+                return [false, '系统错误'];
+            }
+            elseif ($code === 'SUCCESS')
+            {
+                $status = $resp['status'];
+
+                if ($status === 'SUCCESS') {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $save['official_sn'] = strtolower($resp['evidence']) == 'null' ? '' : $resp['evidence'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                } elseif ($status === 'FAIL') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 'PROCESSING') {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($status === 'ORDER_NOT_EXIST' && (time() - $refill_info['commit_time'] >= 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $code];
+                }
+
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, "code={$code}"];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $uri = $this->form_uri([],'user.balance.query');
+        $resp = http_request($uri, [], 'POST');
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            } elseif ($resp['code'] === 'SUCCESS') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['code']];
+            }
+        }
+    }
+
+    private function sign($params,$get_params)
+    {
+        $userId = config::UserId;
+        $api_key = config::ApiKey;
+        $content = "service={$get_params['service']}&userId={$userId}&ts={$get_params['ts']}&";
+        if(!empty($params))
+        {
+            foreach ($params as $key => $value){
+                $content .= "{$key}={$value}&";
+            }
+            $content = rtrim($content, '&');
+        }
+
+        $content .= "&key={$api_key}";
+        return strtoupper(md5($content));
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function getMillisecond()
+    {
+        $cur = microtime (true);
+        $cur = intval($cur * 1000);
+        return $cur;
+    }
+}

+ 8 - 0
helper/refill/api/xyz/guochuang_nation_sec/api.txt

@@ -0,0 +1,8 @@
+国研方略全国1:
+gyflqg18888
+Z1JlaW5JZ2ZXVVNL
+
+客户端后台:http://39.98.190.175:13131
+
+gyflqg18888
+123456

+ 62 - 0
helper/refill/api/xyz/guochuang_nation_sec/config.php

@@ -0,0 +1,62 @@
+<?php
+
+
+namespace refill\guochuang_nation_sec;
+
+use mtopcard;
+
+class config
+{
+    const API_URL = 'http://39.98.30.44:34341/hbgc/zz003';
+
+    const UserId = 'gyflqg18888';
+    const ApiKey = 'Z1JlaW5JZ2ZXVVNL';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_guochuang_nation_sec.php";
+    const operator = [
+        mtopcard\ChinaMobileCard => 11,
+        mtopcard\ChinaUnicomCard => 21,
+        mtopcard\ChinaTelecomCard => 31
+    ];
+    //key值为regin_no,value为上游省份id
+
+    //系统省份变化 -> 国创省份编号 转换表
+    const ProvinceMap = [
+        1	=> 1,  //'北京',
+        2	=> 2,  //'天津',
+        3	=> 10, //'河北',
+        4	=> 12, //'山西',
+        5	=> 5,  //'内蒙古',
+        6	=> 8,  //'辽宁',
+        7	=> 7,  //'吉林',
+        8	=> 6,  //'黑龙江',
+        9	=> 3,  //'上海',
+        10	=> 20, //'江苏',
+        11	=> 21, //'浙江',
+        12	=> 18, //'安徽',
+        13	=> 22, //'福建',
+        14	=> 19, //'江西',
+        15	=> 11, //'山东',
+        16	=> 9,  //'河南',
+        17	=> 14, //'湖北',
+        18	=> 13, //'湖南',
+        19	=> 15, //'广东',
+        20	=> 16, //'广西',
+        21	=> 17, //'海南',
+        22	=> 4,  //'重庆',
+        23	=> 28, //'四川',
+        24	=> 27, //'贵州',
+        25	=> 26, //'云南',
+        26	=> 31, //'西藏',
+        27	=> 23, //'陕西',
+        28	=> 24, //'甘肃',
+        29	=> 29, //'青海',
+        30	=> 25, //'宁夏',
+        31	=> 30  //'新疆'
+    ];
+
+    const ORDER_ERR_CODE = [
+        'PARAM_EMPTY', 'PARAM_ERROR', 'PARAM_TS_TIMEOUT', 'USER_NOT_EXISTS', 'USER_AUTH_NOT_ENOUGH',
+        'IP_DENY', 'SIGN_ERROR', 'SYSTEM_ERROR_DB', 'BALANCE_NOT_ENOUGH',
+        'ORDER_PRICE_ERROR', 'ORDER_NOT_SUPPORT_ACCOUNT', 'ORDER_NOT_SUPPORT_CHANNEL', 'DENY_ACCOUNT'
+    ];
+}

二进制
helper/refill/api/xyz/guochuang_nation_sec/接口使用说明V2.0.20200427.pdf


二进制
helper/refill/api/xyz/guochuang_nation_sec/接口签名补充说明.docx


+ 7 - 0
mobile/callback/refill_guochuang_nation_sec.php

@@ -0,0 +1,7 @@
+<?php
+
+$content = $_SERVER['post_content'];
+$_POST['body'] = $content;
+refill\util::push_notify('guochuang_nation_sec',$_POST);
+
+echo json_encode(['code' => 'SUCCESS']);

+ 6 - 0
test/TestRefill.php

@@ -3006,6 +3006,12 @@ class TestRefill extends TestCase
         $resp = $provider->balance();
     }
 
+    public function testGuochuang_nation_sec()
+    {
+        $provider = $this->getProvider('guochuang_nation_sec');
+        $resp = $provider->balance();
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);