瀏覽代碼

zhongst_doubi

xiaoyu 2 年之前
父節點
當前提交
d677297ab7

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

@@ -8411,6 +8411,13 @@ $tianrui_third = ['name' => 'tianrui', 'store_id' => 293, 'qualitys' => '1',
         100 => [['goods_id' => 8429, 'price' => 99, 'quality' => 1, 'card_type' => 'third']],
     ],
     'official_sn' => true, 'refill_type' => 'api'];
+
+$zhongst_doubi_third = ['name' => 'zhongst_doubi', 'store_id' => 296, 'qualitys' => '1',
+    'amount' => [
+        100 => [['goods_id' => 8446, 'price' => 99, 'quality' => 1, 'card_type' => 'third']],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $third_providers = [
     ['name' => 'lingzhthird', 'cfg' => $lingzhthird],
     ['name' => 'jumithird', 'cfg' => $jumithird],
@@ -8424,6 +8431,7 @@ $third_providers = [
     ['name' => 'chending_df', 'cfg' => $chending_df],
     ['name' => 'gdsinopec', 'cfg' => $gdsinopec],
     ['name' => 'tianrui', 'cfg' => $tianrui_third],
+    ['name' => 'zhongst_doubi', 'cfg' => $zhongst_doubi_third],
 ];
 $config['third_providers'] = $third_providers;
 

+ 2 - 2
helper/refill/api/xyz/tianrui/RefillPhone.php

@@ -43,10 +43,10 @@ class RefillPhone extends refill\IRefillThird
         $goods_id = intval($params['goods_id']);
         $quantity = intval($params['quantity']);
 
-        $product_code = $this->getProductCode($goods_id, $params['product_code'], $quantity);
+        $product_code = $this->getProductCode($goods_id, $params['product_code']);
         Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]);
 
-        $params = $this->req_params($card_no, $amount, $order_sn, $product_code);
+        $params = $this->req_params($card_no, $order_sn, $product_code, $quantity);
         if(empty($params['itemId'])) {
             return [false, '商品编号错误', false];
         }

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

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

+ 176 - 0
helper/refill/api/xyz/zhongst_doubi/RefillPhone.php

@@ -0,0 +1,176 @@
+<?php
+
+namespace refill\zhongst_doubi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/zhongst_doubi/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillThird
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params($phone, int $amount, string $order_sn, $product_code)
+    {
+        $params['szAgentId'] = config::USER_ID;
+        $params['szOrderId'] = $order_sn;
+        $params['szPhoneNum'] = $phone;
+        $params['nMoney'] = $amount;
+        $params['nSortType'] = '1031';
+        $params['szProductId'] = $product_code;
+        $params['nProductClass'] = 1;
+        $params['nProductType'] = 1;
+        $params['szTimeStamp'] = date("Y-m-d H:i:s");
+        $params['szNotifyUrl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    private function getProductAmount($sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProduct(['system_code' => $sys_pcode]);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['refill_amount'];
+        }
+    }
+
+    private function getProductCode($goods_id, $sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProviderProduct($this->mStoreID,$goods_id,$sys_pcode);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['channel_code'];
+        }
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $goods_id = intval($params['goods_id']);
+
+        $product_code = $this->getProductCode($goods_id, $params['product_code']);
+        Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]);
+
+        $amount = $this->getProductAmount($params['product_code']);
+        if(empty($amount)) {
+            return [false, '产品未开启', false];
+        }
+        $params = $this->req_params($card_no, $amount, $order_sn, $product_code);
+        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);
+    }
+}

+ 33 - 0
helper/refill/api/xyz/zhongst_doubi/api.txt

@@ -0,0 +1,33 @@
+对接文档:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+
+权益提交地址 http://123.56.142.204:10186/plat/api/submitorder
+话费下单地址:http://123.56.142.204:10186/plat/api/old/submitorder
+查询地址:http://123.56.142.204:10186/plat/api/old/queryorder
+查询余额地址:http://123.56.142.204:10186/plat/api/old/queryBalance
+
+ID:200061
+秘钥:46a9e63c1ecb4fc19cad20929793716a
+后台地址:http://123.56.142.204:10186/plat/index
+
+账户:duoyiyou
+
+密码:123456
+
+
+ID    商品编码
+200061	快币5000	1158
+200061	快币1000	1157
+200061	快币500	1156
+200061	快币300	1155
+200061	快币200	1154
+200061	快币100	1153
+200061	快币30	1152
+
+200061	抖币20000	1150
+200061	抖币10000	1149
+200061	抖币5000	1148
+200061	抖币1598	1147
+200061	抖币518	1146
+200061	抖币298	1145
+200061	抖币98	1144
+200061	抖币30	1143

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

@@ -0,0 +1,27 @@
+<?php
+
+
+namespace refill\zhongst_doubi;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://123.56.142.204:10186/plat/api/submitorder';
+    const QUERY_URL= 'http://123.56.142.204:10186/plat/api/old/queryorder';
+    const BALANCE_URL = 'http://123.56.142.204:10186/plat/api/old/queryBalance';
+
+    const USER_ID= '200061';
+    const KEY = '46a9e63c1ecb4fc19cad20929793716a';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_zhongst_doubi.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_zhongst_doubi.php

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

+ 18 - 0
test/TestRefill.php

@@ -3104,6 +3104,24 @@ class TestRefill extends TestCase
         $resp = $provider->balance();
     }
 
+    public function testZhongst_doubi()
+    {
+//        $provider = $this->getProvider('zhongst_doubi');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(608168539, 7, 30, [
+//            'order_sn' => $this->make_sn(),
+//            'product_code' => 'XYZ100747',
+//            'goods_id' => '6978'
+//        ]);
+//        $resp = $provider->query(['order_sn' => '81061677051839860385']);
+
+        $body = '{"szOrderId":"81061677051839860385","fSalePrice":"29.85","szAgentId":"200061","nFlag":"2","szVerifyString":"d65a4e5d53a2e6d29f0288013baaa22b","szPhoneNum":"608168539","szRtnMsg":"","nDemo":"30"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('zhongst_doubi','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);