浏览代码

ruizhi_third

xiaoyu 2 年之前
父节点
当前提交
67fc04c395

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

@@ -7923,6 +7923,51 @@ $ruizhi_sec_phone = ['name' => 'ruizhi_sec', 'store_id' => 289, 'qualitys' => '3
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$ruizhi_third_phone = ['name' => 'ruizhi_third', 'store_id' => 290, 'qualitys' => '3',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 8405, 'price' => 10.67, 'quality' => 3, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8405, 'price' => 10.52, 'quality' => 3, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8405, 'price' => 10.77, 'quality' => 3, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 8406, 'price' => 21.34, 'quality' => 3, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8406, 'price' => 20.94, 'quality' => 3, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8406, 'price' => 21.14, 'quality' => 3, 'card_type' => 'chinatelecom']
+//        ],
+        30 => [
+            ['goods_id' => 8407, 'price' => 30.84, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8407, 'price' => 30.84, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8407, 'price' => 30.84, 'quality' => 3, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 8408, 'price' => 51.4, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8408, 'price' => 51.4, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8408, 'price' => 51.4, 'quality' => 3, 'card_type' => 'chinatelecom'],
+        ],
+        100 => [
+            ['goods_id' => 8409, 'price' => 102.8, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8409, 'price' => 102.8, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8409, 'price' => 102.8, 'quality' => 3, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 8410, 'price' => 205.6, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8410, 'price' => 205.6, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8410, 'price' => 205.6, 'quality' => 3, 'card_type' => 'chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 8411, 'price' => 308.4, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8411, 'price' => 308.4, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8411, 'price' => 308.4, 'quality' => 3, 'card_type' => 'chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 8412, 'price' => 514, 'quality' => 3, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8412, 'price' => 514, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8412, 'price' => 514, 'quality' => 3, 'card_type' => 'chinatelecom']
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -8168,6 +8213,7 @@ $phone_providers = [
     ['name' => 'meixu_tax', 'cfg' => $meixu_tax_phone],
     ['name' => 'meixu_tax_sec', 'cfg' => $meixu_tax_sec_phone],
     ['name' => 'ruizhi_sec', 'cfg' => $ruizhi_sec_phone],
+    ['name' => 'ruizhi_third', 'cfg' => $ruizhi_third_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

+ 55 - 0
helper/refill/api/xyz/ruizhi_third/RefillCallBack.php

@@ -0,0 +1,55 @@
+<?php
+
+
+namespace refill\ruizhi_third;
+
+require_once(BASE_HELPER_RAPI_PATH . '/ruizhi_third/config.php');
+
+
+use refill;
+use Log;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        unset($input['voucher']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $str = implode('', $params);
+        $str .= config::KEY;
+        return strtoupper(md5($str));
+    }
+
+    public function notify($params)
+    {
+        $status = $params['state'];
+        $order_sn = $params['user_order'];
+        $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 === 'success') {
+            $data['official_sn'] = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 'failed') {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 137 - 0
helper/refill/api/xyz/ruizhi_third/RefillPhone.php

@@ -0,0 +1,137 @@
+<?php
+
+namespace refill\ruizhi_third;
+
+require_once(BASE_HELPER_RAPI_PATH . '/ruizhi_third/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 $card_type, int $amount, string $order_sn)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['create_time'] = date("YmdHis");
+        $params['buy_type'] = 1;
+        $params['account'] = $phone;
+        $params['product_id'] = config::PRODUCT[$card_type][$amount];
+        $params['amount'] = $amount;
+        $params['user_order'] = $order_sn;
+        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, $card_type, $amount, $order_sn);
+
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = https_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['status'] === '0') {
+                return [true, $resp['order_id'], false];
+            } elseif (in_array($resp['status'], config::ERRCODES, true)) {
+                return [false, $resp['msg'], false];
+            } elseif (in_array($resp['status'], ['110', '113', '-999'], true)) {
+                $net_errno = "HTTP-{$resp['status']}";
+                return [false, $resp['msg'], true];
+            } else {
+                $net_errno = "HTTP-998";
+                return [false, $resp['msg'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['create_time'] = date("YmdHis");
+        $params['user_order'] = $refill_info['order_sn'];
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+        $resp = https_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['status'] === '0')
+            {
+                $status = $resp['state'];
+                if ($status === 'success') {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $updata['official_sn'] = $resp['voucher'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                } elseif ($status === 'failed') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 'untreated') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['userid'] = config::USER_ID;
+        $params['create_time'] = date("YmdHis");
+        $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['status'] === '0') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $str = implode('', $params);
+        $str .= config::KEY;
+        return strtoupper(md5($str));
+    }
+}

+ 28 - 0
helper/refill/api/xyz/ruizhi_third/account.txt

@@ -0,0 +1,28 @@
+客户端入口:http://47.104.129.40:80/
+下单接口:http://47.104.129.40:80/recharge/buy.do
+订单查询:http://47.104.129.40:80/recharge/query.do
+余额查询:http://47.104.129.40:80/user/balance.do
+帐号:YoulaiyouwangRZ
+密码:123456
+用户编号:85378
+秘钥:34DA051FFD61
+
+20003	全国移动30元
+20004	全国移动50元
+20005	全国移动100元
+20006	全国移动200元
+20007	全国移动300元
+20008	全国移动500元
+
+20011	全国联通30元
+20012	全国联通50元
+20013	全国联通100元
+20014	全国联通200元
+20015	全国联通300元
+
+20019	全国电信30元
+20020	全国电信50元
+20021	全国电信100元
+20022	全国电信200元
+20023	全国电信300元
+20024	全国电信500元

+ 44 - 0
helper/refill/api/xyz/ruizhi_third/config.php

@@ -0,0 +1,44 @@
+<?php
+
+
+namespace refill\ruizhi_third;
+
+use mtopcard;
+
+class config
+{
+    //回调地址需上游配置
+    const ORDER_URL = 'http://47.104.129.40:80/recharge/buy.do';
+    const QUERY_URL = 'http://47.104.129.40:80/recharge/query.do';
+    const BALANCE_URL = 'http://47.104.129.40:80/user/balance.do';
+    const USER_ID = '85378';
+    const KEY = '34DA051FFD61';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_ruizhi_third.php";
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+    const PRODUCT = [
+        mtopcard\ChinaMobileCard => [
+            30  => 20003,
+            50  => 20004,
+            100 => 20005,
+            200 => 20006,
+            300 => 20007,
+            500 => 20008
+        ],
+        mtopcard\ChinaUnicomCard => [
+            30  => 20011,
+            50  => 20012,
+            100 => 20013,
+            200 => 20014,
+            300 => 20015,
+        ],
+        mtopcard\ChinaTelecomCard => [
+            30  => 20019,
+            50  => 20020,
+            100 => 20021,
+            200 => 20022,
+            300 => 20023,
+            500 => 20024
+        ],
+    ];
+    const ERRCODES = ['101', '102', '103', '104', '105', '106', '107', '108', '109', '100', '112', '115', '116', '117', '118', '119', '120'];
+}

二进制
helper/refill/api/xyz/ruizhi_third/互联网增值业务接口文档(技术文档).pdf


+ 6 - 0
test/TestRefill.php

@@ -3044,6 +3044,12 @@ class TestRefill extends TestCase
         $resp = $provider->balance();
     }
 
+    public function testRuizhi_third()
+    {
+        $provider = $this->getProvider('ruizhi_third');
+        $resp = $provider->balance();
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);