瀏覽代碼

xyz guanbang

haru haru 2 年之前
父節點
當前提交
04fc30757e

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

@@ -6043,6 +6043,51 @@ $chizeng_yi_phone = ['name' => 'chizeng_yi', 'store_id' => 228, 'qualitys' => '1
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$guanbang_phone = ['name' => 'guanbang', 'store_id' => 229, 'qualitys' => '2',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 7902, 'price' => 9.98, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7902, 'price' => 9.98, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7902, 'price' => 9.98, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 7903, 'price' => 19.96, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7903, 'price' => 19.96, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7903, 'price' => 19.96, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+        30 => [
+            ['goods_id' => 7904, 'price' => 30.36, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7904, 'price' => 29.94, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7904, 'price' => 29.94, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 7905, 'price' => 50.4, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7905, 'price' => 50.25, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7905, 'price' => 49.9, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 7906, 'price' => 100.15, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7906, 'price' => 100.15, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7906, 'price' => 100.15, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 7907, 'price' => 200.3, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7907, 'price' => 200.3, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7907, 'price' => 200.3, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 7908, 'price' => 300.45, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7908, 'price' => 300.45, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7908, 'price' => 300.45, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 7909, 'price' => 500.75, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7909, 'price' => 500.75, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7909, 'price' => 500.75, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -6229,6 +6274,7 @@ $phone_providers = [
     ['name' => 'bodian', 'cfg' => $bodian_phone],
     ['name' => 'yuke', 'cfg' => $yuke_phone],
     ['name' => 'chizeng_yi', 'cfg' => $chizeng_yi_phone],
+    ['name' => 'guanbang', 'cfg' => $guanbang_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

+ 55 - 0
helper/refill/api/xyz/guanbang/RefillCallBack.php

@@ -0,0 +1,55 @@
+<?php
+
+
+namespace refill\guanbang;
+
+require_once(BASE_HELPER_RAPI_PATH . '/guanbang/config.php');
+
+
+use refill;
+use Log;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        unset($input['voucher']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $str = implode('', $params);
+        $str .= config::KEY;
+        return strtoupper(md5($str));
+    }
+
+    public function notify($params)
+    {
+        $status = $params['state'];
+        $order_sn = $params['user_order'];
+        $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'];
+
+        if ($status === 'success') {
+            $data['official_sn'] = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 'failed') {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 137 - 0
helper/refill/api/xyz/guanbang/RefillPhone.php

@@ -0,0 +1,137 @@
+<?php
+
+namespace refill\guanbang;
+
+require_once(BASE_HELPER_RAPI_PATH . '/guanbang/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $card_type, int $amount, string $order_sn)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['create_time'] = date("YmdHis");
+        $params['buy_type'] = 1;
+        $params['account'] = $phone;
+        $params['product_id'] = config::PRODUCT[$card_type][$amount];
+        $params['amount'] = $amount;
+        $params['user_order'] = $order_sn;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $params = $this->req_params($card_no, $card_type, $amount, $order_sn);
+
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = https_request(config::ORDER_URL, $params, 'POST', false, 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['status'] === '0') {
+                return [true, $resp['order_id'], false];
+            } elseif (in_array($resp['status'], config::ERRCODES, true)) {
+                return [false, $resp['msg'], false];
+            } elseif (in_array($resp['status'], ['110', '113', '-999'], true)) {
+                $net_errno = "HTTP-{$resp['status']}";
+                return [false, $resp['msg'], true];
+            } else {
+                $net_errno = "HTTP-998";
+                return [false, $resp['msg'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['create_time'] = date("YmdHis");
+        $params['user_order'] = $refill_info['order_sn'];
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+        $resp = https_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            }
+            elseif ($resp['status'] === '0')
+            {
+                $status = $resp['state'];
+                if ($status === 'success') {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $updata['official_sn'] = $resp['voucher'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                } elseif ($status === 'failed') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 'untreated') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['userid'] = config::USER_ID;
+        $params['create_time'] = date("YmdHis");
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['status'] === '0') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $str = implode('', $params);
+        $str .= config::KEY;
+        return strtoupper(md5($str));
+    }
+}

+ 26 - 0
helper/refill/api/xyz/guanbang/account.txt

@@ -0,0 +1,26 @@
+客户端入口:http://47.104.129.40:80/
+下单接口:http://47.104.129.40:80/recharge/buy.do
+订单查询:http://47.104.129.40:80/recharge/query.do
+余额查询:http://47.104.129.40:80/user/balance.do
+帐号:BJyezi2
+密码:BJyezi2
+用户编号:57756
+秘钥:F6CBED52E5BE
+
+20003	全国移动30元
+20004	全国移动50元
+20005	全国移动100元
+20006	全国移动200元
+20007	全国移动300元
+20008	全国移动500元
+
+20012	全国联通50元
+20013	全国联通100元
+20014	全国联通200元
+20015	全国联通300元
+20016	全国联通500元
+
+20021	全国电信100元
+20022	全国电信200元
+20023	全国电信300元
+20024	全国电信500元

+ 42 - 0
helper/refill/api/xyz/guanbang/config.php

@@ -0,0 +1,42 @@
+<?php
+
+
+namespace refill\guanbang;
+
+use mtopcard;
+
+class config
+{
+    //回调地址需上游配置
+    const ORDER_URL = 'http://47.104.129.40:80/recharge/buy.do';
+    const QUERY_URL = 'http://47.104.129.40:80/recharge/query.do';
+    const BALANCE_URL = 'http://47.104.129.40:80/user/balance.do';
+    const USER_ID = '57756';
+    const KEY = 'F6CBED52E5BE';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_guanbang.php";
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+    const PRODUCT = [
+        mtopcard\ChinaMobileCard => [
+            30  => 20003,
+            50  => 20004,
+            100 => 20005,
+            200 => 20006,
+            300 => 20007,
+            500 => 20008
+        ],
+        mtopcard\ChinaUnicomCard => [
+            50  => 20012,
+            100 => 20013,
+            200 => 20014,
+            300 => 20015,
+            500 => 20016
+        ],
+        mtopcard\ChinaTelecomCard => [
+            100 => 20021,
+            200 => 20022,
+            300 => 20023,
+            500 => 20024
+        ],
+    ];
+    const ERRCODES = ['101', '102', '103', '104', '105', '106', '107', '108', '109', '100', '112', '115', '116', '117', '118', '119', '120'];
+}

二進制
helper/refill/api/xyz/guanbang/互联网增值业务接口文档(技术文档).pdf


+ 4 - 0
mobile/callback/refill_guanbang.php

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

+ 14 - 0
test/TestRefill.php

@@ -2333,6 +2333,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testGuanbang()
+    {
+//        $provider = $this->getProvider('guanbang');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 30, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '82791653469520046484']);
+
+        $body = ' {"userid":"57756","order_id":"22052517052557756af95c9977","account":"15811535608","amount":"30","price":"30.36","state":"failed","user_order":"82791653469520046484","sign":"941BE8B6FF2ABB832A1848DD2758121F","voucher":""}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('guanbang','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);