Browse Source

liantongzx

haru haru 2 years ago
parent
commit
48c01c5c51

+ 69 - 0
helper/refill/api/xyz/liantongzx/RefillCallBack.php

@@ -0,0 +1,69 @@
+<?php
+namespace refill\liantongzx;
+
+require_once(BASE_HELPER_RAPI_PATH . '/liantongzx/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)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if(false === $this->check_empty($val)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content .= "key=".config::KEY;
+
+        return md5($content);
+    }
+
+
+    protected 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['code']);
+        $order_sn = $params['tmporder'];
+        $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 === 1) {
+            $data['official_sn'] = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
+            $data['ch_trade_no'] = strtolower($params['orderno']) == 'null' ? '' : $params['orderno'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === -1) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 127 - 0
helper/refill/api/xyz/liantongzx/RefillPhone.php

@@ -0,0 +1,127 @@
+<?php
+
+namespace refill\liantongzx;
+
+require_once(BASE_HELPER_RAPI_PATH . '/liantongzx/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['appKey'] = config::APP_KEY;
+        $params['phone'] = $phone;
+        $params['busiId'] = $order_sn;
+        $params['money'] = $amount * 100;
+
+        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 = config::sign($params);
+        $params['signature'] = $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'] === '00000') {
+                return [true, $resp['data']['id'], false];
+            } elseif ($resp['code'] === '20008' || $resp['code'] === '99999') {
+                $net_errno = "HTTP-{$resp['code']}";
+                return [true, $resp['msg'], true];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['appKey'] = config::APP_KEY;
+        $params['busiId'] = $refill_info['order_sn'];
+        $sign = config::sign($params);
+        $params['signature'] = $sign;
+
+        $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, '网络错误'];
+            }
+
+            if($resp['code'] === '00000')
+            {
+                $status = $resp['data']['status'];
+                if ($status === 2) {
+                    Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => $resp['data']['officialOrderNo'], 'ch_trade_no' => $resp['data']['agentOrderNo']]);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 3) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($status, [0, 1, 4], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            elseif($resp['code'] === '40000' && (time() - $refill_info['commit_time'] > 600))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['appKey'] = config::APP_KEY;
+        $sign = config::sign($params);
+        $params['signature'] = $sign;
+
+        $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'] === '00000') {
+                return [true, $resp['data']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+
+}

+ 6 - 0
helper/refill/api/xyz/liantongzx/account.txt

@@ -0,0 +1,6 @@
+https://yx.mail.wo.cn:12443/rechargeplat/login
+账号:Dbjyz      初始密码:Beijyz0516
+appKey:Dbjyz
+secret:C1A0845BEBB9F2BC62A53CC920EF440D
+
+接口文档地址为:https://yx.mail.wo.cn:12443/rechargeplat/login/go-api-page

+ 48 - 0
helper/refill/api/xyz/liantongzx/config.php

@@ -0,0 +1,48 @@
+<?php
+
+
+namespace refill\liantongzx;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'https://yx.mail.wo.cn:11443/rechargeplat-rest/rechargeIntf/singleRecharge';
+    const QUERY_URL= 'https://yx.mail.wo.cn:11443/rechargeplat-rest/rechargeIntf/queryRechargeRecord';
+    const BALANCE_URL= 'https://yx.mail.wo.cn:11443/rechargeplat-rest/getUserBalance';
+
+    const APP_KEY = 'Dbjyz';
+    const APP_SECRET = 'C1A0845BEBB9F2BC62A53CC920EF440D';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_liantongzx.php";
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'MOBILE',
+        mtopcard\ChinaUnicomCard  => 'UNICOM',
+        mtopcard\ChinaTelecomCard => 'TELECOM'
+    ];
+    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded' , 'Accept: application/json;charset=UTF-8'];
+
+    public static function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if(false === self::check_empty($val)) {
+                $content .= "{$key}{$val}";
+            }
+        }
+        $content .= "key=".config::APP_SECRET;
+
+        return strtoupper(md5($content));
+    }
+
+    public static function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+}