xiaoyu %!s(int64=2) %!d(string=hai) anos
pai
achega
e2ecd2aaf7

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

@@ -7260,6 +7260,31 @@ $youhe_fs_phone = ['name' => 'youhe_fs', 'store_id' => 268, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$huishi_phone = ['name' => 'huishi', 'store_id' => 269, 'qualitys' => '1',
+    'amount' => [
+//        10 => [['goods_id' => 8239, 'price' => 9.65, 'quality' => 1, 'card_type' => 'chinamobile']],
+//        20 => [['goods_id' => 8240, 'price' => 19.3, 'quality' => 1, 'card_type' => 'chinamobile']],
+        30 => [
+            ['goods_id' => 8241, 'price' => 28.95, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8241, 'price' => 28.95, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 8242, 'price' => 48.25, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8242, 'price' => 48.25, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 8243, 'price' => 96.5, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8243, 'price' => 96.5, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 8244, 'price' => 193, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8244, 'price' => 193, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+//        300 => [['goods_id' => 8245, 'price' => 289.5, 'quality' => 1, 'card_type' => 'chinamobile']],
+//        500 => [['goods_id' => 8246, 'price' => 482.5, 'quality' => 1, 'card_type' => 'chinamobile']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -7485,6 +7510,7 @@ $phone_providers = [
     ['name' => 'meixu_kami', 'cfg' => $meixu_kami_phone],
     ['name' => 'bier', 'cfg' => $bier_phone],
     ['name' => 'youhe_fs', 'cfg' => $youhe_fs_phone],
+    ['name' => 'huishi', 'cfg' => $huishi_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

+ 16 - 0
helper/refill/api/xyz/huishi/API信息.txt

@@ -0,0 +1,16 @@
+正式环境:
+
+话费下单地址:https://telephone-grant.hijin.vip/api/v1/submitOrder
+查询地址:https://telephone-grant.hijin.vip/api/v1/queryOrder
+查询余额地址:https://telephone-grant.hijin.vip/api/v1/queryAccount
+
+
+API_KEY:07onE26tNyaU
+API_SECRET:12bc663f78ac1ed8cffb6be228db7a9c
+
+后台地址:http://telephone-grant-admin.hijin.vip
+登录用户名:duoyiyou-pc
+登录密码:duoyiyou123
+
+对接文档地址:https://www.showdoc.com.cn/telephonehijinvip/8410135380694633
+访问密码:cbbc

+ 38 - 0
helper/refill/api/xyz/huishi/RefillCallBack.php

@@ -0,0 +1,38 @@
+<?php
+namespace refill\huishi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/huishi/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = config::sign($params['timestamp']);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['order_id'];
+        $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 === 5) {
+            Model('refill_order')->edit($order_id, ['official_sn' => $params['voucher']]);
+            return [$order_id, true, false, true];
+        } elseif ($status === 6) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 116 - 0
helper/refill/api/xyz/huishi/RefillPhone.php

@@ -0,0 +1,116 @@
+<?php
+namespace refill\huishi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/huishi/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, string $order_sn)
+    {
+        $params = config::pub_params();
+        $params['order_id'] = $order_sn;
+        $params['phone'] = $phone;
+        $params['amount'] = $amount;
+        $params['callback_url'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $amount, $input['order_sn']);
+        $params = json_encode($params);
+        $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders, $net_errno);
+
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            $code = $resp['code'];
+
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($code === 0) {
+                return [true, '', false];
+            } else {
+                return [false, $resp['message'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params = config::pub_params();
+        $params['order_id'] = $refill_info['order_sn'];
+        $params = json_encode($params);
+        $resp = http_post_data(config::QUERY_URL, $params , 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'] === 0)
+            {
+                $status = $resp['data']['status'];
+                if ($status === 5) {
+                    $updata['official_sn'] = $resp['data']['voucher'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 6) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 0) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            elseif ($resp['code'] === 1007 && (time() - $refill_info['commit_time'] >= 600))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params = config::pub_params();
+        $params = json_encode($params);
+        $resp = http_post_data(config::BALANCE_URL, $params , 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'] === 0) {
+                return [true, $resp['data']['balance']];
+            } else {
+                return [false, $resp['message']];
+            }
+        }
+    }
+}

+ 30 - 0
helper/refill/api/xyz/huishi/config.php

@@ -0,0 +1,30 @@
+<?php
+namespace refill\huishi;
+
+class config
+{
+    const ORDER_URL = 'https://telephone-grant.hijin.vip/api/v1/submitOrder';
+    const QUERY_URL = 'https://telephone-grant.hijin.vip/api/v1/queryOrder';
+    const BALANCE_URL = 'https://telephone-grant.hijin.vip/api/v1/queryAccount';
+
+    const API_KEY = '07onE26tNyaU';
+    const API_SECRET = '12bc663f78ac1ed8cffb6be228db7a9c';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_huishi.php";
+    const ExtHeaders = ['Content-Type: application/json;charset=UTF-8'];
+
+    public static function pub_params()
+    {
+        $cur_time = microtime (true);
+        $cur_time = intval($cur_time * 1000);
+
+        $params['timestamp'] = $cur_time;
+        $params['sign'] = self::sign($cur_time);
+        $params['api_key'] = config::API_KEY;
+        return $params;
+    }
+
+    public static function sign($timestamp)
+    {
+        return strtolower(md5(strtolower(md5(config::API_KEY . $timestamp)) . config::API_SECRET));
+    }
+}

+ 7 - 0
mobile/callback/refill_huishi.php

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

+ 14 - 0
test/TestRefill.php

@@ -2825,6 +2825,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testHuishi()
+    {
+//        $provider = $this->getProvider('huishi');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 50, ['order_sn' => $this->make_sn(), 'regin_no' => 15]);
+//        $resp = $provider->query(['order_sn' => '34271668665589504035']);
+
+        $body = '{"timestamp":1668665604140,"sign":"1b83fd174b4f8d7f89384ff450162faa","api_key":"07onE26tNyaU","order_id":"34271668665589504035","status":6,"voucher":""}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('huishi', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);