Browse Source

xyz hanwei_fs

xiaoyu 2 years ago
parent
commit
5286e682e9

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

@@ -7470,6 +7470,20 @@ $hanwei_phone = ['name' => 'hanwei', 'store_id' => 277, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$hanwei_fs_phone = ['name' => 'hanwei_fs', 'store_id' => 279, 'qualitys' => '1',
+    'amount' => [
+//        10 => [['goods_id' => 8317, 'price' => 9.5, 'quality' => 1, 'card_type' => 'chinamobile']],
+//        20 => [['goods_id' => 8318, 'price' => 19, 'quality' => 1, 'card_type' => 'chinamobile']],
+        30 => [['goods_id' => 8319, 'price' => 28.5, 'quality' => 1, 'card_type' => 'chinamobile']],
+        50 => [['goods_id' => 8320, 'price' => 47.5, 'quality' => 1, 'card_type' => 'chinamobile']],
+        100 => [['goods_id' => 8321, 'price' => 95, 'quality' => 1, 'card_type' => 'chinamobile']],
+        200 => [['goods_id' => 8322, 'price' => 190, 'quality' => 1, 'card_type' => 'chinamobile']],
+//        300 => [['goods_id' => 8323, 'price' => 285, 'quality' => 1, 'card_type' => 'chinamobile']],
+//        500 => [['goods_id' => 8324, 'price' => 475, 'quality' => 1, 'card_type' => 'chinamobile']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -7704,6 +7718,7 @@ $phone_providers = [
     ['name' => 'yuewen_fs', 'cfg' => $yuewen_fs_phone],
     ['name' => 'bodian_dx', 'cfg' => $bodian_dx_phone],
     ['name' => 'hanwei', 'cfg' => $hanwei_phone],
+    ['name' => 'hanwei_fs', 'cfg' => $hanwei_fs_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

+ 51 - 0
helper/refill/api/xyz/hanwei_fs/RefillCallBack.php

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

+ 165 - 0
helper/refill/api/xyz/hanwei_fs/RefillPhone.php

@@ -0,0 +1,165 @@
+<?php
+
+namespace refill\hanwei_fs;
+
+require_once(BASE_HELPER_RAPI_PATH . '/hanwei_fs/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    public function goods($quality,int $amount,int $card_type,$regin_no,$other)
+    {
+        [$goods_id, $price] = parent::goods($quality,$amount,$card_type,$regin_no,$other);
+        if($goods_id <= 0) return [0,0];
+        $key = "{$card_type}-{$amount}-{$regin_no}";
+        $price = config::Price[$key];
+        if(empty($price)) {
+            Log::record("channel cannot find price where name={$this->mName}, goods_id = {$goods_id} card_type={$card_type} amount={$amount} regin_no={$regin_no}",Log::ERR);
+            return [0,0];
+        } else {
+            return [$goods_id,ncPriceFormat($price)];
+        }
+    }
+
+    private function req_params(int $phone, int $amount, int $card_type, string $order_sn, $regin_no)
+    {
+        $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][$regin_no][$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'];
+        $regin_no = $params['regin_no'] ?? -1;
+
+        if($regin_no <= 0) {
+            return [false, '省份获取错误', false];
+        }
+        $params = $this->req_params($card_no, $amount, $card_type, $order_sn, $regin_no);
+        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, '网络错误', ''];
+            }
+            $offical_sn = '';
+            $status = $resp['nRtn'];
+            if ($status === 5012) {
+                $offical_sn = $resp['szRtnMsg'];
+                $updata['official_sn'] = $offical_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'], $offical_sn];
+            }
+
+            return [true, $order_state, $offical_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);
+    }
+}

+ 35 - 0
helper/refill/api/xyz/hanwei_fs/api.txt

@@ -0,0 +1,35 @@
+后台:http://8.136.129.136:10181/plat/index
+账户:duoyiyoufs
+密码:123456
+ID:200047
+秘钥:d02432cef19e40239c10820ca7c27a1d
+
+提单地址:http://8.136.129.136:10181/plat/api/old/submitorder
+查单地址:http://8.136.129.136:10181/plat/api/old/queryorder
+余额查询地址:http://8.136.129.136:10181/plat/api/old/queryBalance
+对接文档地址:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+
+云南移动30元	1530030
+云南移动50元	1530050
+云南移动100元	1530100
+云南移动200元	1530200
+
+贵州移动30元	1520030
+贵州移动50元	1520050
+贵州移动100元	1520100
+贵州移动200元	1520200
+
+河南移动30元	1410030
+河南移动50元	1410050
+河南移动100元	1410100
+河南移动200元	1410200
+
+福建移动30元	1350030
+福建移动50元	1350050
+福建移动100元	1350100
+福建移动200元	1350200
+
+江苏移动30元	1320030
+江苏移动50元	1320050
+江苏移动100元	1320100
+江苏移动200元	1320200

+ 83 - 0
helper/refill/api/xyz/hanwei_fs/config.php

@@ -0,0 +1,83 @@
+<?php
+
+
+namespace refill\hanwei_fs;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://8.136.129.136:10181/plat/api/old/submitorder';
+    const QUERY_URL= 'http://8.136.129.136:10181/plat/api/old/queryorder';
+    const BALANCE_URL = 'http://8.136.129.136:10181/plat/api/old/queryBalance';
+
+    const USER_ID= '200047';
+    const KEY = 'd02432cef19e40239c10820ca7c27a1d';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_hanwei_fs.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 => [
+            //云南
+            25 => [
+                30  => 1530030,
+                50  => 1530050,
+                100 => 1530100,
+                200 => 1530200,
+            ],
+            //贵州
+            24 => [
+                30  => 1520030,
+                50  => 1520050,
+                100 => 1520100,
+                200 => 1520200,
+            ],
+            //河南
+            16 => [
+                30  => 1410030,
+                50  => 1410050,
+                100 => 1410100,
+                200 => 1410200,
+            ],
+            //福建
+            13 => [
+                30  => 1350030,
+                50  => 1350050,
+                100 => 1350100,
+                200 => 1350200,
+            ],
+            //江苏
+            10 => [
+                30  => 1320030,
+                50  => 1320050,
+                100 => 1320100,
+                200 => 1320200,
+            ],
+        ],
+        mtopcard\ChinaTelecomCard => [
+
+        ],
+    ];
+
+    //key格式 卡类型-面值-regin_no
+    const Price = [
+        //移动
+        "4-30-25" => 28.59, "4-50-25" => 47.65, "4-100-25" => 95.3, "4-200-25" => 190.6,//云南 25
+        "4-30-24" => 28.2, "4-50-24" => 47, "4-100-24" => 94, "4-200-24" => 188,//贵州 24
+        "4-30-16" => 28.65, "4-50-16" => 47.75, "4-100-16" => 95.5, "4-200-16" => 191,//河南 16
+        "4-30-13" => 28.26, "4-50-13" => 47.1, "4-100-13" => 94.2, "4-200-13" => 188.4,//福建 13
+        "4-30-10" => 28.65, "4-50-10" => 47.75, "4-100-10" => 95.5, "4-200-10" => 191,//江苏 10
+
+        //电信
+    ];
+
+}

+ 4 - 0
mobile/callback/refill_hanwei_fs.php

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

+ 14 - 0
test/TestRefill.php

@@ -2972,6 +2972,20 @@ class TestRefill extends TestCase
         $provider = $this->getProvider('jumi_sec', 'RefillCallBack');
     }
 
+    public function testHanwei_fs()
+    {
+//        $provider = $this->getProvider('hanwei_fs');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 30, ['order_sn' => $this->make_sn(), 'regin_no' => 25]);
+//        $resp = $provider->query(['order_sn' => '66021670294205137877']);
+
+        $body = '{"szOrderId":"66021670294205137877","fSalePrice":"28.59","szAgentId":"200047","nFlag":"3","szVerifyString":"7210c6fee2bb07ed382c1777b3ab4e09","szPhoneNum":"15811535608","szRtnMsg":"","nDemo":"30"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('hanwei_fs', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);