Browse Source

yl xinhengyang_fs

xiaoyu 2 years ago
parent
commit
5507a9cc63

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

@@ -7004,6 +7004,19 @@ $yuewen_phone = ['name' => 'yuewen', 'store_id' => 260, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$xinhengyang_fs_phone = ['name' => 'xinhengyang_fs', 'store_id' => 262, 'qualitys' => '1',
+    'amount' => [
+//        10 => [['goods_id' => 8170, 'price' => 9.5, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        20 => [['goods_id' => 8171, 'price' => 19, 'quality' => 1, 'card_type' => 'chinatelecom']],
+        30 => [['goods_id' => 8172, 'price' => 28.5, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+        50 => [['goods_id' => 8173, 'price' => 47.5, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+        100 => [['goods_id' => 8174, 'price' => 95, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+        200 => [['goods_id' => 8175, 'price' => 190, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+//        300 => [['goods_id' => 8176, 'price' => 285, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        500 => [['goods_id' => 8177, 'price' => 475, 'quality' => 1, 'card_type' => 'chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -7224,6 +7237,7 @@ $phone_providers = [
     ['name' => 'hanwei', 'cfg' => $hanwei_phone],
     ['name' => 'hanwei_fs', 'cfg' => $hanwei_fs_phone],
     ['name' => 'yuewen', 'cfg' => $yuewen_phone],
+    ['name' => 'xinhengyang_fs', 'cfg' => $xinhengyang_fs_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 50 - 0
helper/refill/api/yl/xinhengyang_fs/RefillCallBack.php

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

+ 161 - 0
helper/refill/api/yl/xinhengyang_fs/RefillPhone.php

@@ -0,0 +1,161 @@
+<?php
+
+namespace refill\xinhengyang_fs;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xinhengyang_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'] = '';
+        $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);
+
+        $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);
+    }
+}

+ 9 - 0
helper/refill/api/yl/xinhengyang_fs/api.txt

@@ -0,0 +1,9 @@
+ID: 200105
+账户:XHYyelinfs  密码:123456(默认密码请及时修改)
+密钥:d46e556ddd694d659b279a44f5189c6a
+客户端地址:http://121.43.140.47:10186/plat/index
+话费下单地址:http://121.43.140.47:10186/plat/api/old/submitorder
+查询地址:http://121.43.140.47:10186/plat/api/old/queryorder
+查询余额地址:http://121.43.140.47:10186/plat/api/old/queryBalance
+
+对接文档地址:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ

+ 48 - 0
helper/refill/api/yl/xinhengyang_fs/config.php

@@ -0,0 +1,48 @@
+<?php
+
+
+namespace refill\xinhengyang_fs;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://121.43.140.47:10186/plat/api/old/submitorder';
+    const QUERY_URL= 'http://121.43.140.47:10186/plat/api/old/queryorder';
+    const BALANCE_URL = 'http://121.43.140.47:10186/plat/api/old/queryBalance';
+
+    const USER_ID= '200105';
+    const KEY = 'd46e556ddd694d659b279a44f5189c6a';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_xinhengyang_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
+    ];
+
+    //key格式 卡类型-面值-regin_no
+    const Price = [
+        //移动
+        "4-30-24" => 27.75, "4-50-24" => 46.25, "4-100-24" => 92.5, "4-200-24" => 185,//贵州 24
+        "4-50-23" => 47.35, "4-100-23" => 94.7, "4-200-23" => 189.4,//四川 23
+        "4-50-25" => 47.4, "4-100-25" => 94.8, "4-200-25" => 189.6,//云南 25
+        "4-50-10" => 48.1, "4-100-10" => 96.2, "4-200-10" => 192.4,//江苏 10
+        "4-50-13" => 46.85, "4-100-13" => 93.7, "4-200-13" => 187.4,//福建 13
+        "4-50-3" => 46.9, "4-100-3" => 93.8, "4-200-3" => 187.6,//河北 3
+        "4-50-20" => 47.45, "4-100-20" => 94.9, "4-200-20" => 189.8,//广西 20
+
+        //电信
+        "6-30-23" => 28.02, "6-50-23" => 46.7, "6-100-23" => 93.4, "6-200-23" => 186.8,//四川 23
+        "6-30-13" => 28.05, "6-50-13" => 46.75, "6-100-13" => 93.5, "6-200-13" => 187,//福建 13
+        "6-30-10" => 28.35, "6-50-10" => 47.25, "6-100-10" => 94.5, "6-200-10" => 189,//江苏 10
+        "6-30-2" => 28.05, "6-50-2" => 46.75, "6-100-2" => 93.5, "6-200-2" => 187,//天津 2
+        "6-30-18" => 28.05, "6-50-18" => 46.75, "6-100-18" => 93.5, "6-200-18" => 187,//湖南 18
+        "6-30-12" => 28.35, "6-50-12" => 47.25, "6-100-12" => 94.5, "6-200-12" => 189,//安徽 12
+    ];
+
+}

+ 6 - 0
test/TestRefillYl.php

@@ -956,4 +956,10 @@ class TestRefillYl extends TestCase
         $ret = $provider->verify($params);
         $resp = $provider->notify($params);
     }
+
+    public function testXinhengyang_fs()
+    {
+        $provider = $this->getProvider('xinhengyang_fs');
+        $resp = $provider->balance();
+    }
 }