xiaoyu 2 éve
szülő
commit
8e8823fa62

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

@@ -8097,6 +8097,19 @@ $jiaqi_phone = ['name' => 'jiaqi', 'store_id' => 297, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$jiaqi_fs_phone = ['name' => 'jiaqi_fs', 'store_id' => 298, 'qualitys' => '1',
+    'amount' => [
+//        10 => [['goods_id' => 8455, 'price' => 9.5, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        20 => [['goods_id' => 8456, 'price' => 19, 'quality' => 1, 'card_type' => 'chinatelecom']],
+        30 => [['goods_id' => 8457, 'price' => 28.5, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+        50 => [['goods_id' => 8458, 'price' => 47.5, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+        100 => [['goods_id' => 8459, 'price' => 95, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+        200 => [['goods_id' => 8460, 'price' => 190, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+//        300 => [['goods_id' => 8461, 'price' => 285, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        500 => [['goods_id' => 8462, '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],
@@ -8348,6 +8361,7 @@ $phone_providers = [
     ['name' => 'chuangyu_ylyw', 'cfg' => $chuangyu_ylyw_phone],
     ['name' => 'lechong_high_sec', 'cfg' => $lechong_high_sec_phone],
     ['name' => 'jiaqi', 'cfg' => $jiaqi_phone],
+    ['name' => 'jiaqi_fs', 'cfg' => $jiaqi_fs_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

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

@@ -0,0 +1,50 @@
+<?php
+namespace refill\jiaqi_fs;
+
+require_once(BASE_HELPER_RAPI_PATH . '/jiaqi_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/xyz/jiaqi_fs/RefillPhone.php

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

+ 36 - 0
helper/refill/api/xyz/jiaqi_fs/api.txt

@@ -0,0 +1,36 @@
+正式环境:
+话费下单地址:http://47.97.90.81:1008/plat/api/hf/submitorder
+查询地址:http://47.97.90.81:1008/plat/api/queryorder
+查询余额地址:http://47.97.90.81:1008/plat/api/querybalance
+
+客户端地址:http://47.97.90.81:1008/plat/login
+账号:yzfs01
+密码:123456
+ID   :   200006
+秘钥:596624835c58414fb867968104efd529
+
+对接文档地址:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+
+广西移动50元	1450050
+广西移动100元	1450100
+广西移动200元	1450200
+
+广东电信30元	3440030
+广东电信50元	3440050
+广东电信100元	3440100
+广东电信200元	3440200
+
+江苏电信30元	3320030
+江苏电信50元	3320050
+江苏电信100元	3320100
+江苏电信200元	3320200
+
+福建电信30元	3350030
+福建电信50元	3350050
+福建电信100元	3350100
+福建电信200元	3350200
+
+四川电信30元	3510030
+四川电信50元	3510050
+四川电信100元	3510100
+四川电信200元	3510200

+ 82 - 0
helper/refill/api/xyz/jiaqi_fs/config.php

@@ -0,0 +1,82 @@
+<?php
+
+
+namespace refill\jiaqi_fs;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://47.97.90.81:1008/plat/api/hf/submitorder';
+    const QUERY_URL= 'http://47.97.90.81:1008/plat/api/queryorder';
+    const BALANCE_URL = 'http://47.97.90.81:1008/plat/api/querybalance';
+
+    const USER_ID= '200006';
+    const KEY = '596624835c58414fb867968104efd529';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_jiaqi_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 => [
+            //广西
+            20 => [
+                50  => 1450050,
+                100 => 1450100,
+                200 => 1450200,
+            ],
+
+        ],
+        mtopcard\ChinaTelecomCard => [
+            //广东
+            19 => [
+                30  => 3440030,
+                50  => 3440050,
+                100 => 3440100,
+                200 => 3440200,
+            ],
+            //江苏
+            10 => [
+                30  => 3320030,
+                50  => 3320050,
+                100 => 3320100,
+                200 => 3320200,
+            ],
+            //福建
+            13 => [
+                30  => 3350030,
+                50  => 3350050,
+                100 => 3350100,
+                200 => 3350200,
+            ],
+            //四川
+            23 => [
+                30  => 3510030,
+                50  => 3510050,
+                100 => 3510100,
+                200 => 3510200,
+            ],
+        ],
+    ];
+
+    //key格式 卡类型-面值-regin_no
+    const Price = [
+        //移动
+        "4-50-20" => 47, "4-100-20" => 94, "4-200-20" => 188,//广西 20
+
+        //电信
+        "6-30-19" => 28.2, "6-50-19" => 47, "6-100-19" => 94, "6-200-19" => 188,//广东 19
+        "6-30-10" => 28.2, "6-50-10" => 47, "6-100-10" => 94, "6-200-10" => 188,//江苏 10
+        "6-30-13" => 27.78, "6-50-13" => 46.3, "6-100-13" => 92.6, "6-200-13" => 185.2,//福建 13
+        "6-30-23" => 27.9, "6-50-23" => 46.5, "6-100-23" => 93, "6-200-23" => 186,//四川 23
+    ];
+
+}

+ 4 - 0
mobile/callback/refill_jiaqi_fs.php

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

+ 6 - 0
test/TestRefill.php

@@ -3136,6 +3136,12 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testJiaqi_fs()
+    {
+        $provider = $this->getProvider('jiaqi_fs');
+        $resp = $provider->balance();
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);