Browse Source

椰子:荟分快充2号

lowkeyman 11 months ago
parent
commit
b9c73afb63

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

@@ -11093,6 +11093,51 @@ $kachong_sec_phone = ['name' => 'kachong_sec', 'store_id' => 409, 'qualitys' =>
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$huifen_fast_sec_phone = ['name' => 'huifen_fast_sec', 'store_id' => 410, 'qualitys' => '2',
+    'amount' => [
+        10 => [
+            ['goods_id' => 9240, 'price' => 10.35, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9240, 'price' => 10.12, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9240, 'price' => 10.35, 'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        20 => [
+            ['goods_id' => 9241, 'price' => 20.7, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9241, 'price' => 20.24, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9241, 'price' => 20.7, 'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        30 => [
+            ['goods_id' => 9242, 'price' => 31.05, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9242, 'price' => 30.36, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9242, 'price' => 31.05, 'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        50 => [
+            ['goods_id' => 9243, 'price' => 50.9, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9243, 'price' => 50.1, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9243, 'price' => 50.9, 'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        100 => [
+            ['goods_id' => 9244, 'price' => 100.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9244, 'price' => 100.2, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9244, 'price' => 100.8, 'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        200 => [
+            ['goods_id' => 9245, 'price' => 201, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9245, 'price' => 200.4, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9245, 'price' => 201.6, 'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        300 => [
+            ['goods_id' => 9246, 'price' => 301.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9246, 'price' => 300.6, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9246, 'price' => 303, 'quality' => 2, 'card_type' => 'chinatelecom'],
+        ],
+        500 => [
+            ['goods_id' => 9247, 'price' => 502.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 9247, 'price' => 501, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 9247, 'price' => 505, 'quality' => 2, 'card_type' => 'chinatelecom'],
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_p hone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -11420,6 +11465,7 @@ $phone_providers = [
     ['name' => 'dunhui', 'cfg' => $dunhui_phone],
     ['name' => 'ruizhi_tax_yj', 'cfg' => $ruizhi_tax_yj_phone],
     ['name' => 'kachong_sec', 'cfg' => $kachong_sec_phone],
+    ['name' => 'huifen_fast_sec', 'cfg' => $huifen_fast_sec_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 24 - 0
helper/refill/api/xyz/huifen_fast_sec/API.MD

@@ -0,0 +1,24 @@
+
+## 荟分快充2号
+
+### 接口地址:
+- 下单地址:https://hfx.vipsave.cn/hf/api/procuder/order/submit
+- 订单状态查询地址:https://hfx.vipsave.cn/hf/api/procuder/order/queryOrderStatus
+- 余额查询地址:https://hfx.vipsave.cn/hf/api/procuder/order/queryBalanceAmt
+
+### 后台:
+- https://hfadmin.vipsave.cn/hf-pos-admin-html/#/login
+- 账号:guoyan
+- 密码:guoyan6688
+
+### 对接文档
+- https://www.showdoc.com.cn/posProducer/7417894866479018
+- 访问密码:886886
+
+### 账户信息:
+- 生产合作方编号:guoyan
+- 秘钥:7pMNzvrCcaa8niMBG9lbZkooSh2DkGvm
+
+## 店铺
+- 账号:huifen_fast_sec
+- 密码:huifen_fast_sec67890

+ 40 - 0
helper/refill/api/xyz/huifen_fast_sec/RefillCallBack.php

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

+ 154 - 0
helper/refill/api/xyz/huifen_fast_sec/RefillPhone.php

@@ -0,0 +1,154 @@
+<?php
+
+namespace refill\huifen_fast_sec;
+
+require_once(BASE_HELPER_RAPI_PATH . '/huifen_fast_sec/config.php');
+
+use Exception;
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    /**
+     * @throws Exception
+     */
+    private function req_params(int $card_no, int $card_type, string $order_sn, int $amount): array
+    {
+        $operatorName = config::operator[$card_type] ?? false;
+        if($operatorName === false) {
+            return [];
+        }
+
+        $params['partnerNo'] = config::PARTNER_NO;
+        $params['productNo'] = $amount;
+        $params['orderNo'] = $order_sn;
+        $params['productQty'] = 1;
+        $params['operatorName'] = $operatorName;
+        $params['accountNo'] = $card_no;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
+    {
+        $params = $this->req_params($card_no, $card_type, $params['order_sn'], $amount);
+        if(empty($params)) {
+            return [false, '参数错误', false];
+        }
+
+        $sign = config::sign($params);
+        $params['sign'] = $sign;
+
+        $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);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            }
+
+            $code = intval($resp['code']);
+            if ($code === 200) {
+                return [true, '', false];
+            } elseif (in_array($code, config::ERR_NOS, true)) { //const ERR_NOS = [500, 50001, 50003, 50005];
+                return [false, $resp['message'], false];
+            } elseif (in_array($code, config::EXP_NOS, true)) {
+                $net_errno = "HTTP-$code";
+                return [false, $resp['message'], true];
+            } else {
+                $err = 998;
+                $net_errno = "HTTP-$err";
+                return [false, $resp['message'], true];
+            }
+        }
+    }
+
+    public function query($refill_info): array
+    {
+        $params['partnerNo'] = config::PARTNER_NO;
+        $params['orderNo'] = $refill_info['order_sn'];
+        $sign = config::sign($params);
+        $params['sign'] = $sign;
+
+        $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, '网络错误', ''];
+            }
+
+            $code = intval($resp['code']);
+            if ($code === 200)
+            {
+                $offical_sn = '';
+                $status = intval($resp['data']['orderStatus']);
+
+                if ($status === 20) {
+                    $offical_sn = $resp['data']['operatorSerialNo'];
+                    Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => $offical_sn]);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 40) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 10) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['data']['orderStatusDesc'], $offical_sn];
+                }
+
+                return [true, $order_state, $offical_sn];
+            }
+            else
+            {
+                return [false, $resp['message'], ''];
+            }
+        }
+    }
+
+    public function balance(): array
+    {
+        $params['partnerNo'] = config::PARTNER_NO;
+
+        $sign = config::sign($params);
+        $params['sign'] = $sign;
+
+        $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, '网络错误'];
+            }
+
+            $code = intval($resp['code']);
+            if ($code === 200) {
+                return [true, $resp['data']['balanceAmt']];
+            } else {
+                return [false, $resp['message']];
+            }
+        }
+    }
+}

+ 50 - 0
helper/refill/api/xyz/huifen_fast_sec/config.php

@@ -0,0 +1,50 @@
+<?php
+namespace refill\huifen_fast_sec;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'https://hfx.vipsave.cn/hf/api/procuder/order/submit';
+    const QUERY_URL = 'https://hfx.vipsave.cn/hf/api/procuder/order/queryOrderStatus';
+    const BALANCE_URL = 'https://hfx.vipsave.cn/hf/api/procuder/order/queryBalanceAmt';
+    const PARTNER_NO = 'guoyan';
+    const SECRET_KEY = '7pMNzvrCcaa8niMBG9lbZkooSh2DkGvm';
+
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_huifen_fast_sec.php";
+    const ExtHeaders = ['Content-Type: application/json;charset=UTF-8'];
+
+    const ERR_NOS = [500, 50001, 50003, 50005];
+    const EXP_NOS = [50004, 50006, 50009];
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'YD',
+        mtopcard\ChinaUnicomCard  => 'LT',
+        mtopcard\ChinaTelecomCard => 'DX'
+    ];
+
+    public static function sign(array $params, array $ignore = []): string
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value)
+        {
+            if (in_array($key, $ignore)) {
+                continue;
+            }
+            if(self::check_empty($value) === false) {
+                $content .= "$key=$value&";
+            }
+        }
+        $content .= "secretKey=" . config::SECRET_KEY;
+        return strtoupper(md5($content));
+    }
+
+    public static function check_empty($value): bool
+    {
+        if (!isset($value))
+            return true;
+        if (trim($value) === "null")
+            return true;
+
+        return false;
+    }
+}

+ 6 - 0
mobile/callback/refill_huifen_fast_sec.php

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

+ 6 - 0
test/TestRefill.php

@@ -6119,6 +6119,12 @@ class TestRefill extends TestCase
         $resp = $provider->balance();
     }
 
+    public function testhuifen_fast_sec()
+    {
+        $provider = $this->getProvider('huifen_fast_sec');
+        $resp = $provider->balance();
+    }
+
 }