Browse Source

yunchonggong_yd

xiaoyu 3 years ago
parent
commit
afcaebdb43

+ 14 - 0
data/config/win/refill.ini.php

@@ -2277,6 +2277,19 @@ $sialan_tax_phone = ['name' => 'sialan_tax', 'store_id' => 119, 'qualitys' => '2
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$yunchonggong_yd_phone = ['name' => 'yunchonggong_yd', 'store_id' => 120, 'qualitys' => '1',
+    'amount' => [
+        10 => [['goods_id' => 7043, 'price' => 9.54, 'quality' => 1, 'card_type' => 'chinamobile']],
+        20 => [['goods_id' => 7044, 'price' => 19.08, 'quality' => 1, 'card_type' => 'chinamobile']],
+        30 => [['goods_id' => 7045, 'price' => 28.62, 'quality' => 1, 'card_type' => 'chinamobile']],
+        50 => [['goods_id' => 7046, 'price' => 47.7, 'quality' => 1, 'card_type' => 'chinamobile']],
+        100 => [['goods_id' => 7047, 'price' => 95.4, 'quality' => 1, 'card_type' => 'chinamobile']],
+        200 => [['goods_id' => 7048, 'price' => 190.8, 'quality' => 1, 'card_type' => 'chinamobile']],
+        300 => [['goods_id' => 7049, 'price' => 286.2, 'quality' => 1, 'card_type' => 'chinamobile']],
+        500 => [['goods_id' => 7050, 'price' => 477, 'quality' => 1, 'card_type' => 'chinamobile']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -2366,6 +2379,7 @@ $phone_providers = [
     ['name' => 'xianzhibb', 'cfg' => $xianzhibb_phone],
     ['name' => 'yikatong', 'cfg' => $yikatong_phone],
     ['name' => 'sialan_tax', 'cfg' => $sialan_tax_phone],
+    ['name' => 'yunchonggong_yd', 'cfg' => $yunchonggong_yd_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

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

@@ -2277,6 +2277,19 @@ $sialan_tax_phone = ['name' => 'sialan_tax', 'store_id' => 119, 'qualitys' => '2
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$yunchonggong_yd_phone = ['name' => 'yunchonggong_yd', 'store_id' => 120, 'qualitys' => '1',
+    'amount' => [
+        10 => [['goods_id' => 7043, 'price' => 9.54, 'quality' => 1, 'card_type' => 'chinamobile']],
+        20 => [['goods_id' => 7044, 'price' => 19.08, 'quality' => 1, 'card_type' => 'chinamobile']],
+        30 => [['goods_id' => 7045, 'price' => 28.62, 'quality' => 1, 'card_type' => 'chinamobile']],
+        50 => [['goods_id' => 7046, 'price' => 47.7, 'quality' => 1, 'card_type' => 'chinamobile']],
+        100 => [['goods_id' => 7047, 'price' => 95.4, 'quality' => 1, 'card_type' => 'chinamobile']],
+        200 => [['goods_id' => 7048, 'price' => 190.8, 'quality' => 1, 'card_type' => 'chinamobile']],
+        300 => [['goods_id' => 7049, 'price' => 286.2, 'quality' => 1, 'card_type' => 'chinamobile']],
+        500 => [['goods_id' => 7050, 'price' => 477, 'quality' => 1, 'card_type' => 'chinamobile']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -2366,6 +2379,7 @@ $phone_providers = [
     ['name' => 'xianzhibb', 'cfg' => $xianzhibb_phone],
     ['name' => 'yikatong', 'cfg' => $yikatong_phone],
     ['name' => 'sialan_tax', 'cfg' => $sialan_tax_phone],
+    ['name' => 'yunchonggong_yd', 'cfg' => $yunchonggong_yd_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 14 - 0
data/config/xyzadm/refill.ini.php

@@ -2277,6 +2277,19 @@ $sialan_tax_phone = ['name' => 'sialan_tax', 'store_id' => 119, 'qualitys' => '2
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$yunchonggong_yd_phone = ['name' => 'yunchonggong_yd', 'store_id' => 120, 'qualitys' => '1',
+    'amount' => [
+        10 => [['goods_id' => 7043, 'price' => 9.54, 'quality' => 1, 'card_type' => 'chinamobile']],
+        20 => [['goods_id' => 7044, 'price' => 19.08, 'quality' => 1, 'card_type' => 'chinamobile']],
+        30 => [['goods_id' => 7045, 'price' => 28.62, 'quality' => 1, 'card_type' => 'chinamobile']],
+        50 => [['goods_id' => 7046, 'price' => 47.7, 'quality' => 1, 'card_type' => 'chinamobile']],
+        100 => [['goods_id' => 7047, 'price' => 95.4, 'quality' => 1, 'card_type' => 'chinamobile']],
+        200 => [['goods_id' => 7048, 'price' => 190.8, 'quality' => 1, 'card_type' => 'chinamobile']],
+        300 => [['goods_id' => 7049, 'price' => 286.2, 'quality' => 1, 'card_type' => 'chinamobile']],
+        500 => [['goods_id' => 7050, 'price' => 477, 'quality' => 1, 'card_type' => 'chinamobile']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -2366,6 +2379,7 @@ $phone_providers = [
     ['name' => 'xianzhibb', 'cfg' => $xianzhibb_phone],
     ['name' => 'yikatong', 'cfg' => $yikatong_phone],
     ['name' => 'sialan_tax', 'cfg' => $sialan_tax_phone],
+    ['name' => 'yunchonggong_yd', 'cfg' => $yunchonggong_yd_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

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

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

+ 138 - 0
helper/refill/api/xyz/yunchonggong_yd/RefillPhone.php

@@ -0,0 +1,138 @@
+<?php
+
+namespace refill\yunchonggong_yd;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yunchonggong_yd/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 = intval($resp['nRtn']);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($nRtn === 0) {
+                return [true, '', false];
+            } elseif (in_array($nRtn, config::ERR_NOS)) {
+                return [false, $resp['szRtnCode'], false];
+            } elseif (in_array($nRtn, [2050, 999])) {
+                $net_errno = "HTTP-{$nRtn}";
+                return [false, $resp['szRtnCode'], false];
+            } else {
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resp['szRtnCode'], false];
+            }
+        }
+    }
+
+    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 = intval($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])) {
+                $order_state = ORDER_STATE_SEND;
+            } elseif ($status === 5005 && (time() - $refill_info['commit_time'] >= 300)) {
+                $order_state = ORDER_STATE_NOEXIST;
+            } else {
+                return [false, $status];
+            }
+            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);
+    }
+}

+ 12 - 0
helper/refill/api/xyz/yunchonggong_yd/api.txt

@@ -0,0 +1,12 @@
+正式环境:
+话费下单地址:http://47.98.253.40:10186/plat/api/old/submitorder
+查询地址:http://47.98.253.40:10186/plat/api/old/queryorder
+查询余额地址:http://47.98.253.40:10186/plat/api/old/queryBalance
+
+测试ID:   200043
+秘钥: 028a435cc21f42f39a4bb2d74bba2a34
+账号  gaoye
+密码 123456
+
+对接文档地址:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+客户端地址:http://47.98.253.40:10186/plat/index

+ 27 - 0
helper/refill/api/xyz/yunchonggong_yd/config.php

@@ -0,0 +1,27 @@
+<?php
+
+
+namespace refill\yunchonggong_yd;
+
+use mtopcard;
+class config
+{
+    //954
+    const ORDER_URL = 'http://47.98.253.40:10186/plat/api/old/submitorder';
+    const QUERY_URL= 'http://47.98.253.40:10186/plat/api/old/queryorder';
+    const BALANCE_URL= 'http://47.98.253.40:10186/plat/api/old/queryBalance';
+
+    const USER_ID= '200043';
+    const KEY = '028a435cc21f42f39a4bb2d74bba2a34';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_yunchonggong_yd.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_yunchonggong_yd.php

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

+ 17 - 0
test/TestRefill.php

@@ -896,6 +896,23 @@ class TestRefill extends TestCase
         $resp = $providers->notify($params);
     }
 
+    public function testYunchonggong_yd()
+    {
+        $providers = $this->getProvider('yunchonggong_yd');
+        for ($i = 1; $i <= 5; $i++) {
+            $resp = $providers->add(13699279618, 4, 50, ['order_sn' => $this->make_sn()]);
+        }
+//        $resp = $providers->query(['order_sn' => '34061631002071526340']);
+
+//        $resp = $providers->balance();
+
+//        $body = '{"szOrderId":"34061631002071526340","fSalePrice":"47.7","szAgentId":"200043","nFlag":"3","szVerifyString":"48a7329c13af06b5be1d2fdad706b22e","szPhoneNum":"13699279618","szRtnMsg":"","nDemo":"50"}';
+//        $params = json_decode($body, true);
+//        $providers = $this->getProvider('yunchonggong_yd','RefillCallBack');
+//        $ret = $providers->verify($params);
+//        $resp = $providers->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $providers = new refill\amingjd\RefillPhone([]);