haru haru 2 år sedan
förälder
incheckning
a4302376b7

+ 49 - 2
data/config/xyz/refill.ini.php

@@ -5736,7 +5736,7 @@ $donghong_high_phone = ['name' => 'donghong_high', 'store_id' => 222, 'qualitys'
 //        20 => [
 //            ['goods_id' => 7847, 'price' => 19.3, 'quality' => 1, 'card_type' => 'chinamobile'],
 //            ['goods_id' => 7847, 'price' => 19.04, 'quality' => 1, 'card_type' => 'chinaunicom'],
-//            ['goods_id' => 7847, 'price' => 19.04 'quality' => 1, 'card_type' => 'chinatelecom']
+//            ['goods_id' => 7847, 'price' => 19.04, 'quality' => 1, 'card_type' => 'chinatelecom']
 //        ],
         30 => [
             ['goods_id' => 7848, 'price' => 28.95, 'quality' => 1, 'card_type' => 'chinamobile'],
@@ -5781,7 +5781,7 @@ $donghong_normal_phone = ['name' => 'donghong_normal', 'store_id' => 223, 'quali
 //        20 => [
 //            ['goods_id' => 7855, 'price' => 19.24, 'quality' => 1, 'card_type' => 'chinamobile'],
 //            ['goods_id' => 7855, 'price' => 18.9, 'quality' => 1, 'card_type' => 'chinaunicom'],
-//            ['goods_id' => 7855, 'price' => 19 'quality' => 1, 'card_type' => 'chinatelecom']
+//            ['goods_id' => 7855, 'price' => 19, 'quality' => 1, 'card_type' => 'chinatelecom']
 //        ],
         30 => [
             ['goods_id' => 7856, 'price' => 28.86, 'quality' => 1, 'card_type' => 'chinamobile'],
@@ -5815,6 +5815,52 @@ $donghong_normal_phone = ['name' => 'donghong_normal', 'store_id' => 223, 'quali
 //        ]
     ],
     'official_sn' => true, 'refill_type' => 'api'];
+
+$tongmai_phone = ['name' => 'tongmai', 'store_id' => 224, 'qualitys' => '2',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 7862, 'price' => 9.95, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7862, 'price' => 9.98, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7862, 'price' => 9.97, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 7863, 'price' => 19.9, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7863, 'price' => 19.96, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7863, 'price' => 19.94, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+        30 => [
+            ['goods_id' => 7864, 'price' => 29.85, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7864, 'price' => 29.94, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7864, 'price' => 29.91, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 7865, 'price' => 49.75, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7865, 'price' => 49.9, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7865, 'price' => 49.85, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 7866, 'price' => 99.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7866, 'price' => 99.8, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7866, 'price' => 99.7, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 7867, 'price' => 199, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7867, 'price' => 199.6, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7867, 'price' => 199.4, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 7868, 'price' => 298.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7868, 'price' => 299.4, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7868, 'price' => 299.1, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 7869, 'price' => 497.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7869, 'price' => 499, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7869, 'price' => 498.5, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -5996,6 +6042,7 @@ $phone_providers = [
     ['name' => 'chending_tax', 'cfg' => $chending_tax_phone],
     ['name' => 'donghong_high', 'cfg' => $donghong_high_phone],
     ['name' => 'donghong_normal', 'cfg' => $donghong_normal_phone],
+    ['name' => 'tongmai', 'cfg' => $tongmai_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

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

@@ -0,0 +1,50 @@
+<?php
+namespace refill\tongmai;
+
+require_once(BASE_HELPER_RAPI_PATH . '/tongmai/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')->getOrderInfo(['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];
+        }
+    }
+}

+ 144 - 0
helper/refill/api/xyz/tongmai/RefillPhone.php

@@ -0,0 +1,144 @@
+<?php
+
+namespace refill\tongmai;
+
+require_once(BASE_HELPER_RAPI_PATH . '/tongmai/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['szProductId'] = config::PRODUCT[$card_type][$amount];
+        $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);
+        if(empty($params['szProductId'])) {
+            return [false, '商品编号错误', false];
+        }
+        $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);
+    }
+}

+ 39 - 0
helper/refill/api/xyz/tongmai/api.txt

@@ -0,0 +1,39 @@
+尊敬的用户:北京椰子
+
+正式环境:
+话费下单地址:http://47.111.15.203:10186/plat/api/old/submitorder
+查询地址:http://47.111.15.203:10186/plat/api/old/queryorder
+查询余额地址:http://47.111.15.203:10186/plat/api/old/queryBalance
+
+正式ID:200010
+秘钥:53f5570a38f54004b3b75886456968cb
+
+对接文档地址:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+前端查单地址:http://47.111.15.203:10186/plat/index
+账号:18500608333   密码(初始密码)123456
+
+移动:
+1000030 话费 全国移动30元
+1000050 话费 全国移动50元
+1000100 话费 全国移动100元
+1000200 话费 全国移动200元
+1000300 话费 全国移动300元
+1000500 话费 全国移动500元
+
+
+联通:
+2000030 话费 全国联通30元
+2000050 话费 全国联通50元
+2000100 话费 全国联通100元
+2000200 话费 全国联通200元
+2000300 话费 全国联通300元
+2000500 话费 全国联通500元
+
+电信:
+3000030 话费 全国电信30元
+3000050 话费 全国电信50元
+3000100 话费 全国电信100元
+3000200 话费 全国电信200元
+3000300 话费 全国电信300元
+3000500 话费 全国电信500元
+

+ 54 - 0
helper/refill/api/xyz/tongmai/config.php

@@ -0,0 +1,54 @@
+<?php
+
+
+namespace refill\tongmai;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://47.111.15.203:10186/plat/api/old/submitorder';
+    const QUERY_URL= 'http://47.111.15.203:10186/plat/api/old/queryorder';
+    const BALANCE_URL = 'http://47.111.15.203:10186/plat/api/old/queryBalance';
+
+    const USER_ID= '200010';
+    const KEY = '53f5570a38f54004b3b75886456968cb';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_tongmai.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  => [
+            30   => 1000030,
+            50   => 1000050,
+            100  => 1000100,
+            200  => 1000200,
+            300  => 1000300,
+            500  => 1000500,
+        ],
+        mtopcard\ChinaUnicomCard  => [
+            30   => 2000030,
+            50   => 2000050,
+            100  => 2000100,
+            200  => 2000200,
+            300  => 2000300,
+            500  => 2000500,
+        ],
+        mtopcard\ChinaTelecomCard => [
+            30   => 3000030,
+            50   => 3000050,
+            100  => 3000100,
+            200  => 3000200,
+            300  => 3000300,
+            500  => 3000500,
+        ]
+    ];
+}

+ 4 - 0
mobile/callback/refill_tongmai.php

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

+ 14 - 0
test/TestRefill.php

@@ -2258,6 +2258,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testTongmai()
+    {
+//        $provider = $this->getProvider('tongmai');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(13699279618, 4, 50, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '14471652858448773887']);
+
+        $body = '{"szOrderId":"14471652858448773887","fSalePrice":"49.75","szAgentId":"200010","nFlag":"2","szVerifyString":"228ad25509b080bb728276d6176d9fea","szPhoneNum":"13699279618","szRtnMsg":"220518-443138774640458","nDemo":"50"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('tongmai','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);