haru haru преди 2 години
родител
ревизия
84a7b0268f

+ 52 - 0
helper/refill/api/xyz/yuke/RefillCallBack.php

@@ -0,0 +1,52 @@
+<?php
+namespace refill\yuke;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yuke/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)
+    {
+        $key = config::SECRET_KEY;
+        $content = "tPfChannelId={$params['tPfChannelId']}&rechargeAccount={$params['rechargeAccount']}&rechargeAmount={$params['rechargeAmount']}&orderType={$params['orderType']}";
+        $content .= "&orderStatus={$params['orderStatus']}&orderSn={$params['orderSn']}&outOrderId={$params['outOrderId']}&createTime={$params['createTime']}";
+        $content .= "&updatedTime={$params['updatedTime']}&secret_key={$key}";
+
+        return strtoupper(md5($content));
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['orderStatus']);
+        $order_sn = $params['outOrderId'];
+        $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 === 2) {
+            $data['official_sn'] = $params['data']['callbackOtherAttr']['cert_no'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 3 || $status === 4) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 144 - 0
helper/refill/api/xyz/yuke/RefillPhone.php

@@ -0,0 +1,144 @@
+<?php
+
+namespace refill\yuke;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yuke/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['rechargeAccount'] = $phone;
+        $params['rechargeAmount'] = $amount;
+        $params['tPfChannelId'] = config::CHANNEL_ID;
+        $params['orderType'] = 0;
+        $params['outOrderId'] = $order_sn;
+        $params['randomNumber'] = $this->createNoncestr(10);
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $card_type, $amount, $params['order_sn']);
+        $sign = $this->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];
+            } elseif ($resp['code'] === 1) {
+                return [true, $resp['data']['order_sn'], false];
+            } else {
+                return [false, $resp['message'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['tPfChannelId'] = config::CHANNEL_ID;
+        $params['outOrderId'] = $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'] === 1)
+            {
+                $status = $resp['data']['orderInfo']['orderStatus'];
+                if ($status === 2) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 3 || $status === 4) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 1) {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($status === 5 && (time() - $refill_info['commit_time'] > 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            elseif ($resp['code'] === -2004 && (time() - $refill_info['commit_time'] > 600))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['tPfChannelId'] = config::CHANNEL_ID;
+        $params['tunnelType'] = 0;
+        $key = config::SECRET_KEY;
+        $content = "tPfChannelId={$params['tPfChannelId']}&tunnelType={$params['tunnelType']}&secret_key={$key}";
+        $params['sign'] = strtoupper(md5($content));
+        $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'] == 1) {
+                return [true, $resp['data']['amountOfMoney']];
+            } else {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    private function createNoncestr( $length = 32 )
+    {
+        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
+        $str ="";
+        for ( $i = 0; $i < $length; $i++ )  {
+            $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
+        }
+        return $str;
+    }
+
+    private function sign($params)
+    {
+        $key = config::SECRET_KEY;
+        $content = "orderType={$params['orderType']}&tPfChannelId={$params['tPfChannelId']}&rechargeAccount={$params['rechargeAccount']}&rechargeAmount={$params['rechargeAmount']}";
+        $content .= "&randomNumber={$params['randomNumber']}&secret_key={$key}";
+        return strtoupper(md5($content));
+    }
+}

+ 7 - 0
helper/refill/api/xyz/yuke/api.txt

@@ -0,0 +1,7 @@
+http://www.recharge.org.cn/rechargeServiceAdmin
+渠道ID:192
+账户:15811535608
+密码:123456
+key:49BA59ABBE56E057
+
+下单地址:http://quantum.recharge.org.cn:19860/polymeric/api/tunnel/aries

+ 15 - 0
helper/refill/api/xyz/yuke/config.php

@@ -0,0 +1,15 @@
+<?php
+namespace refill\yuke;
+
+class config
+{
+    //回调地址上游配置
+    const ORDER_URL = 'http://quantum.recharge.org.cn:19860/polymeric/api/tunnel/aries';
+    const QUERY_URL = 'http://quantum.recharge.org.cn:19860/polymeric/api/tunnel/getOrderInfo';
+    const BALANCE_URL = 'http://quantum.recharge.org.cn:19860/polymeric/api/tunnel/getBalanceInfo';
+
+    const CHANNEL_ID = '192';
+    const SECRET_KEY = '49BA59ABBE56E057';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_yuke.php";
+    const ExtHeaders = ['Content-Type: application/json; charset=utf-8'];
+}

BIN
helper/refill/api/xyz/yuke/充值服务接入文档v2.4.docx