Jelajahi Sumber

xyz youhe_fs

xiaoyu 2 tahun lalu
induk
melakukan
0b05af290c

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

@@ -7247,6 +7247,19 @@ $bier_phone = ['name' => 'bier', 'store_id' => 267, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$youhe_fs_phone = ['name' => 'youhe_fs', 'store_id' => 268, 'qualitys' => '1',
+    'amount' => [
+//        10 => [['goods_id' => 8231, 'price' => 9.6, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        20 => [['goods_id' => 8232, 'price' => 19.2, 'quality' => 1, 'card_type' => 'chinatelecom']],
+        30 => [['goods_id' => 8233, 'price' => 28.8, 'quality' => 1, 'card_type' => 'chinatelecom']],
+        50 => [['goods_id' => 8234, 'price' => 48, 'quality' => 1, 'card_type' => 'chinatelecom']],
+        100 => [['goods_id' => 8235, 'price' => 96, 'quality' => 1, 'card_type' => 'chinatelecom']],
+        200 => [['goods_id' => 8236, 'price' => 192, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        300 => [['goods_id' => 8237, 'price' => 288, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        500 => [['goods_id' => 8238, 'price' => 480, 'quality' => 1, 'card_type' => 'chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -7471,6 +7484,7 @@ $phone_providers = [
     ['name' => 'qianqian_fs_gd', 'cfg' => $qianqian_fs_gd_phone],
     ['name' => 'meixu_kami', 'cfg' => $meixu_kami_phone],
     ['name' => 'bier', 'cfg' => $bier_phone],
+    ['name' => 'youhe_fs', 'cfg' => $youhe_fs_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

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

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

+ 164 - 0
helper/refill/api/xyz/youhe_fs/RefillPhone.php

@@ -0,0 +1,164 @@
+<?php
+
+namespace refill\youhe_fs;
+
+require_once(BASE_HELPER_RAPI_PATH . '/youhe_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, '网络错误'];
+            }
+
+            $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);
+    }
+}

+ 30 - 0
helper/refill/api/xyz/youhe_fs/api.txt

@@ -0,0 +1,30 @@
+正式API id :200064
+正式API 密钥:c4eace522e51459eb52ad030826bb2c7
+
+登陆地址:http://118.31.168.250:10186/plat/index
+账户名:yzdxf
+初始密码(建议首次登陆之后修改):wRI1RBWZDTBDoXpE
+
+接口IP:118.31.168.250
+
+话费下单地址:http://118.31.168.250:10186/plat/api/old/submitorder
+查询地址:http://118.31.168.250:10186/plat/api/old/queryorder
+查询余额地址:http://118.31.168.250:10186/plat/api/old/queryBalance
+
+对接文档地址:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+
+
+山东电信30元     3370030
+山东电信50元     3370050
+山东电信100元    3370100
+山东电信200元    3370200
+
+四川电信30元     3510030
+四川电信50元     3510050
+四川电信100元    3510100
+四川电信200元    3510200
+
+云南电信30元     3530030
+云南电信50元     3530050
+云南电信100元    3530100
+云南电信200元    3530200

+ 68 - 0
helper/refill/api/xyz/youhe_fs/config.php

@@ -0,0 +1,68 @@
+<?php
+
+
+namespace refill\youhe_fs;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://118.31.168.250:10186/plat/api/old/submitorder';
+    const QUERY_URL= 'http://118.31.168.250:10186/plat/api/old/queryorder';
+    const BALANCE_URL = 'http://118.31.168.250:10186/plat/api/old/queryBalance';
+
+    const USER_ID= '200064';
+    const KEY = 'c4eace522e51459eb52ad030826bb2c7';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_youhe_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 => [
+
+        ],
+        mtopcard\ChinaTelecomCard => [
+            //山东
+            15 => [
+                30  => 3370030,
+                50  => 3370050,
+                100 => 3370100,
+                200 => 3370200,
+            ],
+            //四川
+            23 => [
+                30  => 3510030,
+                50  => 3510050,
+                100 => 3510100,
+                200 => 3510200,
+            ],
+            //云南
+            25 => [
+                30  => 3530030,
+                50  => 3530050,
+                100 => 3530100,
+                200 => 3530200,
+            ],
+        ],
+    ];
+
+    //key格式 卡类型-面值-regin_no
+    const Price = [
+        //移动
+
+        //电信
+        "6-30-15" => 28.05, "6-50-15" => 46.75, "6-100-15" => 93.5, "6-200-15" => 187,//山东 15
+        "6-30-23" => 28.05, "6-50-23" => 46.75, "6-100-23" => 93.5, "6-200-23" => 187,//四川 23
+        "6-30-25" => 28.05, "6-50-25" => 46.75, "6-100-25" => 93.5, "6-200-25" => 187,//云南 25
+    ];
+
+}

+ 4 - 0
mobile/callback/refill_youhe_fs.php

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

+ 14 - 0
test/TestRefill.php

@@ -2811,6 +2811,20 @@ class TestRefill extends TestCase
         $resp = $provider->balance();
     }
 
+    public function testYouhe_fs()
+    {
+//        $provider = $this->getProvider('youhe_fs');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(18074608795, 6, 30, ['order_sn' => $this->make_sn(), 'regin_no' => 15]);
+//        $resp = $provider->query(['order_sn' => '42791668653632383737']);
+
+        $body = '{"szOrderId":"42791668653632383737","fSalePrice":"28.05","szAgentId":"200064","nFlag":"3","szVerifyString":"245107428fad62725a98e4f5022de830","szPhoneNum":"18074608795","szRtnMsg":"","nDemo":"30"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('youhe_fs', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);