瀏覽代碼

xyz qiantu

xiaoyu 1 年之前
父節點
當前提交
fc6dab3094

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

@@ -9106,6 +9106,19 @@ $tianchen_trd_phone = ['name' => 'tianchen_trd', 'store_id' => 337, 'qualitys' =
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$qiantu_phone = ['name' => 'qiantu', 'store_id' => 342, 'qualitys' => '2',
+    'amount' => [
+//        10 => [['goods_id' => 8742, 'price' => 10.013, 'quality' => 2, 'card_type' => 'chinamobile']],
+//        20 => [['goods_id' => 8743, 'price' => 20.026, 'quality' => 2, 'card_type' => 'chinamobile']],
+//        30 => [['goods_id' => 8744, 'price' => 30.039, 'quality' => 2, 'card_type' => 'chinamobile']],
+//        50 => [['goods_id' => 8745, 'price' => 50.065, 'quality' => 2, 'card_type' => 'chinamobile']],
+        100 => [['goods_id' => 8746, 'price' => 100.13, 'quality' => 2, 'card_type' => 'chinamobile']],
+        200 => [['goods_id' => 8747, 'price' => 200.26, 'quality' => 2, 'card_type' => 'chinamobile']],
+        300 => [['goods_id' => 8748, 'price' => 300.39, 'quality' => 2, 'card_type' => 'chinamobile']],
+        500 => [['goods_id' => 8749, 'price' => 500.65, 'quality' => 2, 'card_type' => 'chinamobile']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -9387,6 +9400,7 @@ $phone_providers = [
     ['name' => 'quanzhen_hf_man', 'cfg' => $quanzhen_hf_man_phone],
     ['name' => 'meixu_sec', 'cfg' => $meixu_sec_phone],
     ['name' => 'tianchen_trd', 'cfg' => $tianchen_trd_phone],
+    ['name' => 'qiantu', 'cfg' => $qiantu_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 50 - 0
helper/refill/api/xyz/qiantu/RefillCallBack.php

@@ -0,0 +1,50 @@
+<?php
+namespace refill\qiantu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/qiantu/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)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$userid}&orderid={$params['orderid']}&sporderid={$params['sporderid']}&merchantsubmittime={$params['merchantsubmittime']}";
+        $content .= "&resultno={$params['resultno']}&key={$key}";
+        return strtoupper(md5($content));
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['resultno']);
+        $order_sn = $params['sporderid'];
+        $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false, false, ''];
+        }
+
+        $official_sn = '';
+        $order_id = $order_info['order_id'];
+        if ($status === 1) {
+            $official_sn = strtolower($params['remark1']) == 'null' ? '' : $params['remark1'];
+            $data['official_sn'] = $official_sn;
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true, $official_sn];
+        } elseif ($status === 9) {
+            return [$order_id, false, true, true, $official_sn];
+        } else {
+            return [$order_id, false, false, false, $official_sn];
+        }
+    }
+}

+ 157 - 0
helper/refill/api/xyz/qiantu/RefillPhone.php

@@ -0,0 +1,157 @@
+<?php
+
+namespace refill\qiantu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/qiantu/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, $card_type, string $order_sn)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['productid'] = '';
+        $params['price'] = $amount;
+        $params['num'] = 1;
+        $params['mobile'] = $phone;
+        $params['spordertime'] = date("YmdHis");
+        $params['sporderid'] = $order_sn;
+        $params['back_url'] = config::NOTIFY_URL;
+        $params['paytype'] = 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, 'POST', false, config::ExtHeaders, $net_errno);
+
+        if (empty($resp)) {
+            return [false, '网络错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            }
+
+            $resultno = $resp['resultno'];
+            if (in_array($resultno, ['0', '2'], true)) {
+                return [true, $resp['orderid'], false];
+            } elseif (in_array($resultno, config::ERR_NOS, true)) {
+                return [false, $resultno, false];
+            } elseif ($resultno === '9999' || $resultno === '5006') {
+                $net_errno = "HTTP-{$resultno}";
+                return [false, $resultno, true];
+            } else {
+                //未知结果码
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resultno, true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['sporderid'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "userid={$params['userid']}&sporderid={$params['sporderid']}&key={$key}";
+        $params['sign'] = strtoupper(md5($content));
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误', ''];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp))
+            {
+                return [false, '网络错误', ''];
+            }
+            else
+            {
+                $official_sn = '';
+                $resultno = $resp['resultno'];
+                if ($resultno === '1') {
+                    $official_sn = $resp['remark1'];
+                    $updata['official_sn'] = $official_sn;
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($resultno === '9') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($resultno, ['0','2'], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($resultno === '5007' && (time() - $refill_info['commit_time'] > 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $resultno, $official_sn];
+                }
+
+                return [true, $order_state, $official_sn];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['userid'] = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$params['userid']}&key={$key}";
+        $params['sign'] = strtoupper(md5($content));
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['resultno'] === '1') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['resultno']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$userid}&productid={$params['productid']}&price={$params['price']}&num={$params['num']}&mobile={$params['mobile']}&spordertime={$params['spordertime']}";
+        $content .= "&sporderid={$params['sporderid']}&key={$key}";
+        return strtoupper(md5($content));
+    }
+
+    public function xmlToArray($xml)
+    {
+        $replace_str = str_replace(' ','','encoding="gb2312"');
+        $xml = mb_convert_encoding($xml,"UTF-8","gb2312");
+        $xml = str_replace($replace_str, "encoding='utf-8'", $xml);
+        return refill\util::xmlToArray($xml);
+    }
+}

+ 24 - 0
helper/refill/api/xyz/qiantu/config.php

@@ -0,0 +1,24 @@
+<?php
+namespace refill\qiantu;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://39.103.136.121:9086/onlinepay.do';
+    const QUERY_URL= 'http://39.103.136.121:9086/searchpay.do';
+    const BALANCE_URL = 'http://39.103.136.121:9086/searchbalance.do';
+
+    const USER_ID= '10003166';
+    const KEY = '3taYTWC8iQfHZmN2kHknHFj4YDmikzaK';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_qiantu.php";
+
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'yd',
+        mtopcard\ChinaUnicomCard  => 'lt',
+        mtopcard\ChinaTelecomCard => 'dx'
+    ];
+    const ERR_NOS = [
+        '5001','5002','5003','5004','5005','5008','5009','5010','5011','5012'
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;'];
+}

+ 6 - 0
helper/refill/api/xyz/qiantu/对接文档-yezi.txt

@@ -0,0 +1,6 @@
+http://39.103.136.121:9080/login.jsp
+账号:yelinkeji
+密码:yelinkeji123
+
+用户编号 10003166
+密钥 3taYTWC8iQfHZmN2kHknHFj4YDmikzaK

二進制
helper/refill/api/xyz/qiantu/通信充值接口.doc


+ 4 - 0
mobile/callback/refill_qiantu.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('qiantu',$_POST);
+echo ('OK');

+ 14 - 0
test/TestRefill.php

@@ -3514,6 +3514,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testQiantu()
+    {
+//        $provider = $this->getProvider('qiantu');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 100, ['order_sn' => $this->make_sn(), 'regin_no' => 1]);
+//        $resp = $provider->query(['order_sn' => '37251686721677638585']);
+
+        $body = '{"orderid":"NE2A230614134804263-7800830","sporderid":"37251686721677638585","userid":"10003166","merchantsubmittime":"20230614134805","resultno":"9","parvalue":"100","remark1":"","fundbalance":"-97.3","sign":"F09ABCC44C5C3350D628B3C7414253EB"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('qiantu', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);