浏览代码

椰子 智信快充

lowkeyman 5 月之前
父节点
当前提交
8efe1f4c9f

+ 46 - 0
data/config/xyz/refill.ini.php

@@ -11418,6 +11418,51 @@ $xinbao_small_phone = ['name' => 'xinbao_small', 'store_id' => 419, 'qualitys' =
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$zhixin_phone = ['name' => 'zhixin', 'store_id' => 420, 'qualitys' => '2',
+    'amount' => [
+        10 => [
+            ['goods_id' => 9312, 'price' => 10.9,  'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9312, 'price' => 10.09,  'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9312, 'price' => 10.26,  'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        20 => [
+            ['goods_id' => 9313, 'price' => 20.98,  'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9313, 'price' => 20.09,  'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9313, 'price' => 20.32,  'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        30 => [
+            ['goods_id' => 9314, 'price' => 31.14,  'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9314, 'price' => 30.105,  'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9314, 'price' => 30.33,  'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        50 => [
+            ['goods_id' => 9315, 'price' => 50.4,  'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9315, 'price' => 50.05,  'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9315, 'price' => 50.35,  'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        100 => [
+            ['goods_id' => 9316, 'price' => 100.15, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9316, 'price' => 100.1,  'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9316, 'price' => 100.25, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 9317, 'price' => 200.3,  'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9317, 'price' => 200.2,  'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9317, 'price' => 200.5,  'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        300 => [
+            ['goods_id' => 9318, 'price' => 300.45, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9318, 'price' => 300.3, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9318, 'price' => 300.75,  'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        500 => [
+            ['goods_id' => 9319, 'price' => 500.75, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9319, 'price' => 500.25, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9319, 'price' => 501.25,  'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_p hone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -11752,6 +11797,7 @@ $phone_providers = [
     ['name' => 'jinmiaoli_sec', 'cfg' => $jinmiaoli_sec_phone],
     ['name' => 'jiahu', 'cfg' => $jiahu_phone],
     ['name' => 'xinbao_small', 'cfg' => $xinbao_small_phone],
+    ['name' => 'zhixin', 'cfg' => $zhixin_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 27 - 0
helper/refill/api/xyz/zhixin/API.MD

@@ -0,0 +1,27 @@
+## 智信快充
+话费
+
+- 4.1 余额查询:http://balance.julives.com:9080/zxpaycore/v2/balance
+- 4.2 订单查询:http://query.julives.com:9080/zxpaycore/v2/query
+- 4.3 订单预检查:http://api.julives.com:9080/zxpaycore/v2/check
+- 4.4 订单受理:http://api.julives.com:9080/zxpaycore/v2/recharge
+
+### 开户信息
+- 游来有旺(北京)科技有限责任公司
+- 商户编号:101103740
+- 商户名称:游来有旺全国话费①
+
+- 证书密钥:cQsxiOGykz7dFcS9XwhGpLUIpNWoKKcy
+
+### 店铺 
+- id:420
+- 店铺账号:zhixin
+- 密   码:zhixin67890
+
+-------------------------------------------------------------------------------------
+智信科技平台API接口文档地址:
+https://docs.qq.com/doc/DZWNBSWFsRU1pTU9q
+-------------------------------------------------------------------------------------
+后台地址:http://mgr.julives.com/mgr/  
+管理平台账号:ylyw  
+密码:sc@DlRz6p5  

+ 51 - 0
helper/refill/api/xyz/zhixin/RefillCallBack.php

@@ -0,0 +1,51 @@
+<?php
+namespace refill\zhixin;
+
+require_once(BASE_HELPER_RAPI_PATH . '/zhixin/config.php');
+use refill;
+use Log;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = config::cbsign($params,config::callback_keys);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            Log::record('zhixin_fast\RefillCallBack::verify fail',Log::DEBUG);
+            return false;
+        }
+    }
+
+    //[$order_id, $success, $can_try, $need_handle, $official_sn]
+    public function notify($params): array
+    {
+        $order_sn = $params['client_order_no'];
+        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
+
+        if (empty($order_info)) {
+            return [false, false, false, false, ''];
+        }
+
+        $order_id = $order_info['order_id'];
+        $recharge_status = intval($params['recharge_status']);
+
+        if ($recharge_status === 2) {
+            $official_sn = $params['elecardID'] ?? '';
+            $ch_trade_no = $params['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 ($recharge_status === 6) {
+            $ch_trade_no = $params['up_order_no'] ?? '';
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no]);
+
+            return [$order_id, false, true, true, ''];
+        }
+        else{
+            return [$order_id, false, false, false, ''];
+        }
+    }
+}

+ 189 - 0
helper/refill/api/xyz/zhixin/RefillPhone.php

@@ -0,0 +1,189 @@
+<?php
+
+namespace refill\zhixin;
+
+require_once(BASE_HELPER_RAPI_PATH . '/zhixin/config.php');
+
+use mtopcard;
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
+    {
+        $cp_getter = function ($card_type)
+        {
+            if ($card_type == mtopcard\ChinaMobileCard) {
+                return "01";
+            } elseif ($card_type == mtopcard\ChinaUnicomCard) {
+                return "03";
+            } elseif ($card_type == mtopcard\ChinaTelecomCard) {
+                return "02";
+            } else {
+                return false;
+            }
+        };
+
+        $cp = $cp_getter($card_type);
+        if ($cp === false) {
+            return [];
+        }
+
+        $params = [
+            'mrch_no' => config::MRCH_NO,
+            'request_time' => date('YmdHis'),
+            'client_order_no' => $order_sn,
+            'product_type' => 1,
+            'phone_no' => "$phone",
+            'cp' => $cp,
+            'city_code' => "",
+            'recharge_amount' => $amount * 100,
+            'recharge_type' => 0,
+            'recharge_desc' => "",
+            'notify_url' => config::NOTIFY_URL,
+        ];
+
+        $params['sign'] = config::sign($params);
+        return $params;
+    }
+
+    //[$state, $errmsg, $neterr]
+    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)) {
+            return [false, '提单参数不符合', false];
+        }
+
+        $resp = http_post_data(config::ORDER_URL, json_encode($params), config::ExtHeaders);
+        if (empty($resp)) {
+            return [false, '网络错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            }
+
+            $nRtn = intval($resp['code']);
+            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])) {
+                $net_errno = "HTTP-$nRtn";
+                return [false, "重复订单号", true];
+            } else {
+                $net_errno = "HTTP-998";
+                return [false, "其他异常", true];
+            }
+        }
+    }
+
+    private function query_params($refill_info)
+    {
+        $params = [
+            'mrch_no' => config::MRCH_NO,
+            'request_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);
+
+        if (empty($resp)) {
+            return [false, '系统错误', ''];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+
+            if (empty($resp)) {
+                return [false, '系统错误', ''];
+            }
+
+            $official_sn = '';
+            $nRtn = intval($resp['code']);
+            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;
+                }
+                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;
+                }
+                else {
+                    $order_state = ORDER_STATE_SEND;
+                }
+            }
+            elseif ($nRtn == 626 && (time() - $refill_info['commit_time'] >= 600)) {
+                $order_state = ORDER_STATE_NOEXIST;
+            }
+            else {
+                return [false, '其他,或网络错误', ''];
+            }
+
+            return [true, $order_state, $official_sn];
+        }
+    }
+
+    private function balance_params()
+    {
+        $params = [
+            '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);
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        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'])];
+            } else {
+                return [false, '其它,失败'];
+            }
+        }
+    }
+}

+ 57 - 0
helper/refill/api/xyz/zhixin/config.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace refill\zhixin;
+class config
+{
+    const MRCH_NO = '101103740';
+    const SECRET_KEY = 'cQsxiOGykz7dFcS9XwhGpLUIpNWoKKcy';
+
+    const ORDER_URL   = 'http://api.julives.com:9080/zxpaycore/v2/recharge';
+    const QUERY_URL   = 'http://query.julives.com:9080/zxpaycore/v2/query';
+    const BALANCE_URL = 'http://balance.julives.com:9080/zxpaycore/v2/balance';
+    const NOTIFY_URL  = BASE_SITE_URL . "/mobile/callback/refill_zhixin.php";
+
+    public const ERRCODES = [600,602,603,606,622,623,624,615,637,751];
+
+    const ExtHeaders = ['Content-Type: application/json;charset=UTF-8'];
+    const callback_keys = ['client_order_no', 'deduction_amount', 'elecardID', 'phone_no', 'product_type', 'recharge_status', 'up_order_no'];
+
+    public const ERRMSG = [
+        600 => '商户禁用,接口已关闭',
+        602 => '订单提交失败,未充值',
+        603 => '参数校验错误',
+        606 => '数据签名错误',
+        622 => '商户不存在',
+        623 => '通道维护',
+        624 => '产品未配置',
+        615 => '号码归属地未配置',
+        637 => '流量充值未配置',
+        751 => 'IP地址限制',
+    ];
+
+    public static function sign($params)
+    {
+        ksort($params);
+
+        $body = "";
+        foreach ($params as $k => $v) {
+            $item = "$k" . "$v";
+            $body .= $item;
+        }
+        $body .= config::SECRET_KEY;
+
+        return strtolower(md5($body));
+    }
+
+    public static function cbsign($params,$keys)
+    {
+        $body = "";
+        foreach ($keys as $key) {
+            $val = $params[$key] ?? '';
+            $body .= "$key" . "$val";
+        }
+
+        $body .= config::SECRET_KEY;
+        return strtolower(md5($body));
+    }
+}

二进制
helper/refill/api/xyz/zhixin/price.png


+ 7 - 0
mobile/callback/refill_zhixin.php

@@ -0,0 +1,7 @@
+<?php
+
+$data = json_encode($_POST);
+Log::record("zhixin data=$data",Log::DEBUG);
+
+refill\util::push_notify('zhixin',$_POST);
+echo ('SUCCESS');

+ 6 - 0
test/TestRefill.php

@@ -6261,6 +6261,12 @@ class TestRefill extends TestCase
         $provider = $this->getProvider('yuankun');
         $resp = $provider->balance();
     }
+
+    public function testzhixin()
+    {
+        $provider = $this->getProvider('zhixin');
+        $resp = $provider->balance();
+    }
 }