浏览代码

椰子快充 鑫小面额

赵明 5 月之前
父节点
当前提交
1c62cd0f59

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

@@ -11389,6 +11389,35 @@ $jiahu_phone = ['name' => 'jiahu', 'store_id' => 418, 'qualitys' => '2',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$xinbao_small_phone = ['name' => 'xinbao_small', 'store_id' => 419, 'qualitys' => '2',
+    'amount' => [
+        10 => [
+            ['goods_id' => 9304, 'price' => 9.8, 'quality' => 2, 'card_type' => 'chinamobile'],
+        ],
+        20 => [
+            ['goods_id' => 9305, 'price' => 19.6, 'quality' => 2, 'card_type' => 'chinamobile'],
+        ],
+        30 => [
+            ['goods_id' => 9306, 'price' => 29.4, 'quality' => 2, 'card_type' => 'chinamobile'],
+        ],
+//        50 => [
+//            ['goods_id' => 9307, 'price' => 50, 'quality' => 2, 'card_type' => 'chinamobile'],
+//        ],
+//        100 => [
+//            ['goods_id' => 9308, 'price' => 100, 'quality' => 2, 'card_type' => 'chinamobile'],
+//        ],
+//        200 => [
+//            ['goods_id' => 9309, 'price' => 200, 'quality' => 2, 'card_type' => 'chinamobile'],
+//        ],
+//        300 => [
+//            ['goods_id' => 9310, 'price' => 300, 'quality' => 2, 'card_type' => 'chinamobile'],
+//        ],
+//        500 => [
+//            ['goods_id' => 9311, 'price' => 500, 'quality' => 2, 'card_type' => 'chinamobile'],
+//        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_p hone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -11722,6 +11751,7 @@ $phone_providers = [
     ['name' => 'zhongtuo_sec', 'cfg' => $zhongtuo_sec_phone],
     ['name' => 'jinmiaoli_sec', 'cfg' => $jinmiaoli_sec_phone],
     ['name' => 'jiahu', 'cfg' => $jiahu_phone],
+    ['name' => 'xinbao_small', 'cfg' => $xinbao_small_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 25 - 0
helper/refill/api/xyz/xinbao_small/API.MD

@@ -0,0 +1,25 @@
+## 鑫小面额
+
+### 正式环境:
+- 话费下单地址:http://101.37.158.170:16188/plat/api/hf/submitorder
+- 查询地址:http://101.37.158.170:16188/plat/api/queryorder
+- 查询余额地址:http://101.37.158.170:16188/plat/api/querybalance
+
+- 客户端地址:http://101.37.158.170:16188/plat/login
+- 账号:fqxe
+- 密码:123456
+- 客户ID:100076
+- 密钥:748341b186d742b7ba99f8a2cb684ea4
+
+### 对接文档地址:
+> https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+
+### 店铺账号
+- xinbao_small
+- xinbao_small67890
+
+### 产品编码
+客户 名称 编码 产品类型
+福清小额 全国移动30元 1000030 话费
+福清小额 全国移动20元 1000020 话费
+福清小额 全国移动10元 1000010 话费

+ 52 - 0
helper/refill/api/xyz/xinbao_small/RefillCallBack.php

@@ -0,0 +1,52 @@
+<?php
+namespace refill\xinbao_small;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xinbao_small/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['szVerifyString'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nDemo={$params['nDemo']}&fSalePrice={$params['fSalePrice']}";
+        $content .= "&nFlag={$params['nFlag']}&szKey={$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['nFlag']);
+        $order_sn = $params['szOrderId'];
+        $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 === 2) {
+            $official_sn = strtolower($params['szRtnMsg']) == 'null' ? '' : $params['szRtnMsg'];
+
+            $data['official_sn'] = $official_sn;
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true, $official_sn];
+        }
+        elseif ($status === 3) {
+            return [$order_id, false, true, true, ''];
+        }
+        else {
+            return [$order_id, false, false, false, ''];
+        }
+    }
+}

+ 146 - 0
helper/refill/api/xyz/xinbao_small/RefillPhone.php

@@ -0,0 +1,146 @@
+<?php
+
+namespace refill\xinbao_small;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xinbao_small/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 $amount, int $card_type, string $order_sn)
+    {
+        $params['szAgentId'] = config::USER_ID;
+        $params['szOrderId'] = $order_sn;
+        $params['szPhoneNum'] = $phone;
+        $params['nMoney'] = $amount;
+        $params['nSortType'] = config::operator[$card_type];
+        $params['szProductId'] = config::Product[$card_type][$amount];
+        $params['nProductClass'] = 1;
+        $params['nProductType'] = 1;
+        $params['szTimeStamp'] = date("Y-m-d H:i:s");
+        $params['szNotifyUrl'] = config::NOTIFY_URL;
+        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, $amount, $card_type, $order_sn);
+
+        $sign = $this->sign($params);
+        $params['szVerifyString'] = $sign;
+
+        $resp = http_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);
+
+            $nRtn = $resp['nRtn'];
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($nRtn === 0) {
+                return [true, '', false];
+            } elseif (in_array($nRtn, config::ERR_NOS, true)) {
+                return [false, $resp['szRtnCode'], false];
+            } elseif (in_array($nRtn, [2050, 999], true)) {
+                $net_errno = "HTTP-{$nRtn}";
+                return [false, $resp['szRtnCode'], true];
+            } else {
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resp['szRtnCode'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['szAgentId'] = config::USER_ID;
+        $params['szOrderId'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "szAgentId={$params['szAgentId']}&szOrderId={$params['szOrderId']}&szKey={$key}";
+        $params['szVerifyString'] = md5($content);
+
+        $resp = http_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, '网络错误', ''];
+            }
+
+            $official_sn = '';
+
+            $status = $resp['nRtn'];
+            if ($status === 5012) {
+                $official_sn = $resp['szRtnMsg'];
+
+                $updata['official_sn'] = $official_sn;
+                Model('refill_order')->edit($refill_info['order_id'], $updata);
+                $order_state = ORDER_STATE_SUCCESS;
+            } elseif ($status === 5013) {
+                $order_state = ORDER_STATE_CANCEL;
+            } elseif (in_array($status, [5011,5019],true)) {
+                $order_state = ORDER_STATE_SEND;
+            } elseif ($status === 5005 && (time() - $refill_info['commit_time'] > 300)) {
+                $order_state = ORDER_STATE_NOEXIST;
+            } else {
+                return [false, $resp['szRtnMsg'], ''];
+            }
+
+            return [true, $order_state, $official_sn];
+        }
+    }
+
+    public function balance()
+    {
+        $params['szAgentId'] = config::USER_ID;
+        $key = config::KEY;
+        $content = "szAgentId={$params['szAgentId']}&szKey={$key}";
+        $params['szVerifyString'] = md5($content);
+
+        $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['nRtn'] === 0) {
+                return [true, $resp['fBalance']];
+            } else {
+                return [false, $resp['szRtnCode']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nMoney={$params['nMoney']}&nSortType={$params['nSortType']}";
+        $content .= "&nProductClass={$params['nProductClass']}&nProductType={$params['nProductType']}&szTimeStamp={$params['szTimeStamp']}&szKey={$key}";
+        return md5($content);
+    }
+}

+ 39 - 0
helper/refill/api/xyz/xinbao_small/config.php

@@ -0,0 +1,39 @@
+<?php
+
+
+namespace refill\xinbao_small;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://101.37.158.170:16188/plat/api/hf/submitorder';
+    const QUERY_URL= 'http://101.37.158.170:16188/plat/api/queryorder';
+    const BALANCE_URL = 'http://101.37.158.170:16188/plat/api/querybalance';
+
+    const USER_ID= '100076';
+    const KEY = '748341b186d742b7ba99f8a2cb684ea4';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_xinbao_small.php";
+
+    const operator = [
+        mtopcard\ChinaMobileCard  => 1,
+        mtopcard\ChinaUnicomCard  => 2,
+        mtopcard\ChinaTelecomCard => 3
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+
+    const ERR_NOS = [
+        1000,1001,1003,1004,2001,2002,2003,2020,2021,1006,2030,3003
+    ];
+
+    const Product = [
+        mtopcard\ChinaMobileCard => [
+            10 => 1000010,
+            20 => 1000020,
+            30 => 1000030,
+        ],
+        mtopcard\ChinaUnicomCard => [
+        ],
+        mtopcard\ChinaTelecomCard => [
+        ],
+    ];
+}

+ 4 - 0
mobile/callback/refill_xinbao_small.php

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

+ 6 - 0
test/TestRefill.php

@@ -6249,6 +6249,12 @@ class TestRefill extends TestCase
         $provider = $this->getProvider('jiahu');
         $resp = $provider->balance();
     }
+
+    public function testxinbao_small()
+    {
+        $provider = $this->getProvider('xinbao_small');
+        $resp = $provider->balance();
+    }
 }