xiaoyu 2 gadi atpakaļ
vecāks
revīzija
d05ee26aa4

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

@@ -6005,6 +6005,19 @@ $guitong_phone = ['name' => 'guitong', 'store_id' => 210, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$gaobiao_phone = ['name' => 'gaobiao', 'store_id' => 224, 'qualitys' => '2',
+    'amount' => [
+        10 => [['goods_id' => 7882, 'price' => 9.99, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        20 => [['goods_id' => 7883, 'price' => 19.98, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [['goods_id' => 7884, 'price' => 29.97, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        50 => [['goods_id' => 7885, 'price' => 49.95, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        100 => [['goods_id' => 7886, 'price' => 99.9, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        200 => [['goods_id' => 7887, 'price' => 199.8, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        300 => [['goods_id' => 7888, 'price' => 299.7, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        500 => [['goods_id' => 7889, 'price' => 499.5, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -6190,6 +6203,7 @@ $phone_providers = [
     ['name' => 'yuke_lt', 'cfg' => $yuke_lt_phone],
     ['name' => 'yuke_dx', 'cfg' => $yuke_dx_phone],
     ['name' => 'guitong', 'cfg' => $guitong_phone],
+    ['name' => 'gaobiao', 'cfg' => $gaobiao_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

+ 48 - 0
helper/refill/api/yl/gaobiao/RefillCallBack.php

@@ -0,0 +1,48 @@
+<?php
+namespace refill\gaobiao;
+
+require_once(BASE_HELPER_RAPI_PATH . '/gaobiao/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content = "{$params['seqid']}{$params['orderid']}{$params['state']}{$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['state']);
+        $order_sn = $params['orderid'];
+        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false,false];
+        }
+        $order_id = $order_info['order_id'];
+
+        if ($status === 3) {
+            $data['official_sn'] = strtolower($params['certificateNo']) == 'null' ? '' : $params['certificateNo'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 4) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 148 - 0
helper/refill/api/yl/gaobiao/RefillPhone.php

@@ -0,0 +1,148 @@
+<?php
+
+namespace refill\gaobiao;
+
+require_once(BASE_HELPER_RAPI_PATH . '/gaobiao/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)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['orderid'] = $order_sn;
+        $params['number'] = $phone;
+        $params['norms'] = $amount;
+        $params['ot'] = 2;
+        $params['ut'] = 0;
+        $params['yt'] = config::operator[$card_type];
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
+
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'GET', false, config::ExtHeaders, $net_errno);
+
+        if (empty($resp)) {
+            return [false, '网络错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+
+            $state = $resp['state'];
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($state === 0) {
+                return [true, $resp['seqid'], false];
+            } elseif (in_array($state, [11, 19, 100], true)) {
+                $net_errno = "HTTP-{$state}";
+                return [false, $resp['desc'], true];
+            } else {
+                return [false, $resp['desc'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['seqid'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "{$params['userid']}{$params['seqid']}{$key}";
+        $params['sign'] = md5($content);
+
+        $resp = http_request(config::QUERY_URL, $params, 'GET', 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['state'];
+            if ($status === 3) {
+                $updata['official_sn'] = $resp['certificateNo'];
+                Model('refill_order')->edit($refill_info['order_id'], $updata);
+                $order_state = ORDER_STATE_SUCCESS;
+            } elseif ($status === 4) {
+                $order_state = ORDER_STATE_CANCEL;
+            } elseif ($status === 5) {
+                $order_state = ORDER_STATE_SEND;
+            } elseif ($status === 1 && (time() - $refill_info['commit_time'] > 600)) {
+                $order_state = ORDER_STATE_NOEXIST;
+            } else {
+                return [false, $resp['desc']];
+            }
+
+            return [true, $order_state];
+        }
+    }
+
+    public function balance()
+    {
+        $params['userid'] = config::USER_ID;
+        $key = config::KEY;
+        $content = "{$params['userid']}{$key}";
+        $params['sign'] = md5($content);
+
+        $resp = http_request(config::BALANCE_URL, $params, 'GET', 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['state'] === 0) {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['desc']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "{$userid}{$params['orderid']}{$params['number']}{$params['norms']}{$params['ot']}{$params['ut']}{$key}";
+        return md5($content);
+    }
+}

+ 7 - 0
helper/refill/api/yl/gaobiao/api.txt

@@ -0,0 +1,7 @@
+接口文档:http://word.591ll.com/huafei.htm
+前台网址:http://agent.591ll.com/login.htm(建议用IE浏览器登录)
+账户:bjyl
+初始密码:Aa123456(登陆后修改密码)
+秘钥:EBA29084917F03FB
+用户序列号:b43d475d-48f7-49f6-b526-e09ed9c08735
+没有产品编码

+ 34 - 0
helper/refill/api/yl/gaobiao/config.php

@@ -0,0 +1,34 @@
+<?php
+
+
+namespace refill\gaobiao;
+
+use mtopcard;
+class config
+{
+    // 回调地址由上游配置
+    const ORDER_URL = 'http://api.591ll.com/buy.aspx';
+    const QUERY_URL= 'http://api.591ll.com/queryAgentId.aspx';
+    const BALANCE_URL = 'http://api.591ll.com/queryAccount.aspx';
+
+    const USER_ID= 'b43d475d-48f7-49f6-b526-e09ed9c08735';
+    const KEY = 'EBA29084917F03FB';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_gaobiao.php";
+
+    const operator = [
+        mtopcard\ChinaMobileCard  => '移动',
+        mtopcard\ChinaUnicomCard  => '联通',
+        mtopcard\ChinaTelecomCard => '电信'
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+
+    //key格式 卡类型-面值-regin_no
+    const Price = [
+        //移动
+        "4-10-16" => 10.1, "4-20-16" => 20.1, "4-30-16" => 30.102, "4-50-16" => 50.1, "4-100-16" => 100.1, "4-200-16" => 200.1, "4-300-16" => 300.102,//河南 16
+        //联通
+
+        //电信
+        "6-10-16" => 10.1, "6-20-16" => 20.1, "6-30-16" => 30.102, "6-50-16" => 50.1, "6-100-16" => 100.1, "6-200-16" => 200.1, "6-300-16" => 300.102, "6-500-16" => 500.1,//河南 16
+    ];
+}

+ 7 - 0
mobile/callback/refill_gaobiao.php

@@ -0,0 +1,7 @@
+<?php
+
+$content = $_SERVER['post_content'] ?? [];
+$inputs = json_decode($content,true);
+refill\util::push_notify('gaobiao',$inputs);
+
+echo ('1');

+ 14 - 0
test/TestRefillYl.php

@@ -742,4 +742,18 @@ class TestRefillYl extends TestCase
         $provider = $this->getProvider('guitong');
         $resp = $provider->balance();
     }
+
+    public function testGaobiao()
+    {
+//        $provider = $this->getProvider('gaobiao');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15136908757, 4, 10, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '38761655707344654690']);
+
+        $body = '{"seqid":"b41be0c9-bad7-4098-846a-0b8ba18501bf","state":3,"orderid":"38761655707344654690","desc":"成功","sign":"3387a08114bc35a3c64804f71cca851d","certificateNo":"","certificateType":""}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('gaobiao','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
 }