xiaoyu 1 год назад
Родитель
Сommit
dd041d7958

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

@@ -8987,6 +8987,51 @@ $guoyyantyd_phone = ['name' => 'guoyyantyd', 'store_id' => 329, 'qualitys' => '3
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$tianchen_sec_phone = ['name' => 'tianchen_sec', 'store_id' => 330, 'qualitys' => '2',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 8684, 'price' => 10.24, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8684, 'price' => 10.09, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8684, 'price' => 10.23, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 8685, 'price' => 20.48, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8685, 'price' => 20.1, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8685, 'price' => 20.26, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+//        30 => [
+//            ['goods_id' => 8686, 'price' => 30.105, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8686, 'price' => 30.135, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8686, 'price' => 30.135, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+        50 => [
+//            ['goods_id' => 8687, 'price' => 50.175, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8687, 'price' => 50.075, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8687, 'price' => 50.3, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 8688, 'price' => 100.2, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8688, 'price' => 100.15, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8688, 'price' => 100.3, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 8689, 'price' => 200.4, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8689, 'price' => 200.3, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8689, 'price' => 200.6, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 8690, 'price' => 300.6, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8690, 'price' => 300.45, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8690, 'price' => 300.9, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 8691, 'price' => 501, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8691, 'price' => 501, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8691, 'price' => 501.5, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -9263,6 +9308,7 @@ $phone_providers = [
     ['name' => 'huiyuan', 'cfg' => $huiyuan_phone],
     ['name' => 'by_online_kami', 'cfg' => $by_online_kami_phone],
     ['name' => 'guoyyantyd', 'cfg' => $guoyyantyd_phone],
+    ['name' => 'tianchen_sec', 'cfg' => $tianchen_sec_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 10 - 0
helper/refill/api/xyz/tianchen_sec/API信息.txt

@@ -0,0 +1,10 @@
+对接文档:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+ID:100322
+秘钥:53b13cd2fbb144799c644c0f8aca4219
+登录网址:http://47.114.98.104:10081/plat/index
+登录账号:THGYQG
+初始密码:123456
+
+提交地址:http://47.114.98.104:10081/plat/api/old/submitorder
+查询地址:http://47.114.98.104:10081/plat/api/old/queryorder
+查询余额地址:http://47.114.98.104:10081/plat/api/old/queryBalance

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

@@ -0,0 +1,50 @@
+<?php
+namespace refill\tianchen_sec;
+
+require_once(BASE_HELPER_RAPI_PATH . '/tianchen_sec/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) {
+            $data['official_sn'] = strtolower($params['szRtnMsg']) == 'null' ? '' : $params['szRtnMsg'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 3) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 141 - 0
helper/refill/api/xyz/tianchen_sec/RefillPhone.php

@@ -0,0 +1,141 @@
+<?php
+
+namespace refill\tianchen_sec;
+
+require_once(BASE_HELPER_RAPI_PATH . '/tianchen_sec/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['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, '网络错误'];
+            }
+
+            $status = $resp['nRtn'];
+            if ($status === 5012) {
+                $updata['official_sn'] = $resp['szRtnMsg'];
+                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];
+        }
+    }
+
+    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);
+    }
+}

+ 25 - 0
helper/refill/api/xyz/tianchen_sec/config.php

@@ -0,0 +1,25 @@
+<?php
+namespace refill\tianchen_sec;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://47.114.98.104:10081/plat/api/old/submitorder';
+    const QUERY_URL= 'http://47.114.98.104:10081/plat/api/old/queryorder';
+    const BALANCE_URL = 'http://47.114.98.104:10081/plat/api/old/queryBalance';
+
+    const USER_ID= '100322';
+    const KEY = '53b13cd2fbb144799c644c0f8aca4219';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_tianchen_sec.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
+    ];
+}

+ 4 - 0
mobile/callback/refill_tianchen_sec.php

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

+ 14 - 0
test/TestRefill.php

@@ -3432,6 +3432,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testTianchen_sec()
+    {
+//        $provider = $this->getProvider('tianchen_sec');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(18500608333, 5, 50, ['order_sn' => $this->make_sn(), 'regin_no' => 1]);
+//        $resp = $provider->query(['order_sn' => '18681685500032499039']);
+
+        $body = '{"szOrderId":"18681685500032499039","fSalePrice":"50.075","szAgentId":"100322","nFlag":"2","szVerifyString":"254e4e82e7bac8728e45f428bdb96cf8","szPhoneNum":"18500608333","szRtnMsg":"100101246122305311027173950243","nDemo":"50"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('tianchen_sec', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);