Pārlūkot izejas kodu

yl huoshenguo_yd

xiaoyu 2 gadi atpakaļ
vecāks
revīzija
5162d719fd

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

@@ -5981,6 +5981,19 @@ $guitong_phone = ['name' => 'guitong', 'store_id' => 210, 'qualitys' => '1',
     ],
     ],
     'official_sn' => true, 'refill_type' => 'api'];
     'official_sn' => true, 'refill_type' => 'api'];
 
 
+$huoshenguo_yd_phone = ['name' => 'huoshenguo_yd', 'store_id' => 225, 'qualitys' => '1',
+    'amount' => [
+//        10 => [['goods_id' => 7890, 'price' => 9.85, 'quality' => 1, 'card_type' => 'chinamobile']],
+//        20 => [['goods_id' => 7891, 'price' => 19.7, 'quality' => 1, 'card_type' => 'chinamobile']],
+        30 => [['goods_id' => 7892, 'price' => 29.55, 'quality' => 1, 'card_type' => 'chinamobile']],
+        50 => [['goods_id' => 7893, 'price' => 49.25, 'quality' => 1, 'card_type' => 'chinamobile']],
+        100 => [['goods_id' => 7894, 'price' => 98.5, 'quality' => 1, 'card_type' => 'chinamobile']],
+        200 => [['goods_id' => 7895, 'price' => 197, 'quality' => 1, 'card_type' => 'chinamobile']],
+        300 => [['goods_id' => 7896, 'price' => 295.5, 'quality' => 1, 'card_type' => 'chinamobile']],
+        500 => [['goods_id' => 7897, 'price' => 492.5, 'quality' => 1, 'card_type' => 'chinamobile']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -6166,6 +6179,7 @@ $phone_providers = [
     ['name' => 'yuke_lt', 'cfg' => $yuke_lt_phone],
     ['name' => 'yuke_lt', 'cfg' => $yuke_lt_phone],
     ['name' => 'yuke_dx', 'cfg' => $yuke_dx_phone],
     ['name' => 'yuke_dx', 'cfg' => $yuke_dx_phone],
     ['name' => 'guitong', 'cfg' => $guitong_phone],
     ['name' => 'guitong', 'cfg' => $guitong_phone],
+    ['name' => 'huoshenguo_yd', 'cfg' => $huoshenguo_yd_phone],
 
 
 ];
 ];
 $config['phone_providers'] = $phone_providers;
 $config['phone_providers'] = $phone_providers;

+ 67 - 0
helper/refill/api/yl/huoshenguo_yd/RefillCallBack.php

@@ -0,0 +1,67 @@
+<?php
+namespace refill\huoshenguo_yd;
+
+require_once(BASE_HELPER_RAPI_PATH . '/huoshenguo_yd/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $params['appSecret'] = config::APP_SECRET;
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content = rtrim($content, '&');
+        return md5($content);
+    }
+
+    private function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['orderStatus']);
+        $order_sn = $params['outOrderId'];
+        $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 === 2) {
+            $data['official_sn'] = strtolower($params['ext1']) == 'null' ? '' : $params['ext1'];
+            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];
+        }
+    }
+}

+ 155 - 0
helper/refill/api/yl/huoshenguo_yd/RefillPhone.php

@@ -0,0 +1,155 @@
+<?php
+
+namespace refill\huoshenguo_yd;
+
+require_once(BASE_HELPER_RAPI_PATH . '/huoshenguo_yd/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $amount, int $card_type, string $order_sn)
+    {
+        $params['appId'] = config::APP_ID;
+        $params['outOrderId'] = $order_sn;
+        $params['uuid'] = $phone;
+        $params['itemId'] = config::PRODUCT[$card_type][$amount];
+        $params['itemFace'] = $amount;
+        $params['callbackUrl'] = config::NOTIFY_URL;
+        $params['timestamp'] = date("YmdHis").$this->get_millisecond();
+        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);
+        if(empty($params['itemId'])) {
+            return [false, '商品编号错误', false];
+        }
+        $sign = $this->sign($params);
+        $params['sign'] = $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);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($resp['code'] === '00') {
+                return [true, $resp['orderId'], false];
+            } elseif (in_array($resp['code'], config::ERRCODES, true)) {
+                return [false, $resp['msg'], false];
+            } elseif (in_array($resp['code'], ['-22', '-23', '-99'], true)) {
+                $net_errno = "HTTP-{$resp['code']}";
+                return [false, $resp['msg'], true];
+            } else {
+                $net_errno = "HTTP-998";
+                return [false, $resp['msg'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['appId'] = config::APP_ID;
+        $params['outOrderId'] = $refill_info['order_sn'];
+        $params['timestamp'] = date("YmdHis").$this->get_millisecond();
+        $params['sign'] = $this->sign($params);
+
+        $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, '网络错误'];
+            }
+            elseif ($resp['code'] === '00')
+            {
+                $status = $resp['orderStatus'];
+                if ($status === '2') {
+                    $updata['official_sn'] = $resp['ext1'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === '3') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === '1') {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($status === '4' && (time() - $refill_info['commit_time'] >= 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $resp['msg']];
+                }
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['appId'] = config::APP_ID;
+        $params['timestamp'] = date("YmdHis").$this->get_millisecond();
+        $params['sign'] = $this->sign($params);
+
+        $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['code'] === '00') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function get_millisecond()
+    {
+        list($usec, $sec) = explode(" ", microtime());
+        return round($usec*1000);
+    }
+
+    private function sign($params)
+    {
+        $params['appSecret'] = config::APP_SECRET;
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content = rtrim($content, '&');
+        return md5($content);
+    }
+}

+ 27 - 0
helper/refill/api/yl/huoshenguo_yd/config.php

@@ -0,0 +1,27 @@
+<?php
+
+
+namespace refill\huoshenguo_yd;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://120.26.89.236:8911/api/hf/order/submit';
+    const QUERY_URL = 'http://120.26.89.236:8911/api/order/query';
+    const BALANCE_URL = 'http://120.26.89.236:8911/api/account/balance';
+
+    const APP_ID = '6fFOF0grhX';
+    const APP_SECRET = 'HNQXcbFBUnEwQTUc';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_huoshenguo_yd.php";
+
+    const PRODUCT = [
+        mtopcard\ChinaMobileCard => [
+            30  => 100131,
+            50  => 100132,
+            100 => 100133,
+            200 => 100134
+        ]
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+    const ERRCODES = ['-10', '-12', '-13', '-14', '-15', '-16', '-18', '-21'];
+}

+ 20 - 0
helper/refill/api/yl/huoshenguo_yd/开户信息.txt

@@ -0,0 +1,20 @@
+后台地址:http://120.26.89.236:8888
+帐号:YLCGJ
+密码:674852
+二级密码:PDFN9018
+appId:6fFOF0grhX
+appSecret:HNQXcbFBUnEwQTUc
+后台-商品列表,可查看已配置商品信息
+后台-安全中心,可配置IP白名单
+接口文档:https://www.showdoc.com.cn/1686453783298366/7925312871840290
+话费直充接口:http://120.26.89.236:8911/api/hf/order/submit
+通用直充接口:http://120.26.89.236:8911/api/order/submit
+卡密提取接口:http://120.26.89.236:8911/api/card/get
+查单接口接口:http://120.26.89.236:8911/api/order/query
+余额接口接口:http://120.26.89.236:8911/api/account/balance
+
+
+100131 10分钟移动30
+100132 10分钟移动50
+100133 10分钟移动100
+100134 10分钟移动200

+ 6 - 0
test/TestRefillYl.php

@@ -742,4 +742,10 @@ class TestRefillYl extends TestCase
         $provider = $this->getProvider('guitong');
         $provider = $this->getProvider('guitong');
         $resp = $provider->balance();
         $resp = $provider->balance();
     }
     }
+
+    public function testHuoshenguo_Yd()
+    {
+        $provider = $this->getProvider('huoshenguo_yd');
+        $resp = $provider->balance();
+    }
 }
 }