From 821f7d829d23c5566bc95d0acd90780dfef5dc88 Mon Sep 17 00:00:00 2001 From: NimaQu Date: Sat, 24 Feb 2018 00:22:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E6=98=93=E4=BB=98?= =?UTF-8?q?=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- app/Controllers/PayConfig.php | 19 ++ app/Controllers/QuickPayFunction.php | 107 ++++++++++ app/Controllers/YFTPayCallBackController.php | 128 ++++++++++++ app/Controllers/YftPay.php | 193 +++++++++++++++++++ app/Models/YftOrder.php | 17 ++ app/Utils/Pay.php | 23 ++- app/Utils/YftOrderNumUtil.php | 28 +++ config/routes.php | 9 + resources/views/material/admin/main.tpl | 2 +- resources/views/material/admin/yftOrder.tpl | 85 ++++++++ resources/views/material/user/yft.tpl | 7 + resources/views/material/user/yftOrder.tpl | 85 ++++++++ 13 files changed, 704 insertions(+), 3 deletions(-) create mode 100644 app/Controllers/PayConfig.php create mode 100644 app/Controllers/QuickPayFunction.php create mode 100644 app/Controllers/YFTPayCallBackController.php create mode 100644 app/Controllers/YftPay.php create mode 100644 app/Models/YftOrder.php create mode 100644 app/Utils/YftOrderNumUtil.php create mode 100644 resources/views/material/admin/yftOrder.tpl create mode 100644 resources/views/material/user/yft.tpl create mode 100644 resources/views/material/user/yftOrder.tpl diff --git a/README.md b/README.md index ec5c9ec8..f14b3dbe 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ telegram交流群:https://t.me/joinchat/Fjn0HkeqdoovkJgTRnvoNw **此面板作者为**[galaxychuck](https://github.com/galaxychuck),因某些原因删除仓库,现代为上传 +**作者Paypal打賞:galaxychuck1995@gmail.com** + 本人不懂编程,不接受功能需求及面板搭建失败之类issus,欢迎dalao提交pr 本面板在[宝塔面板5.6.0](www.bt.cn),宝塔安装版 nginx1.12,php 7.1 ,mysql 5.7 上全部功能测试通过 @@ -70,4 +72,4 @@ Image: 它不会影响美观并可以给开发者很大的支持和动力。~~听说删除staff的网站都会遭遇未知DDOS攻击~~ -在这里感谢魔改后花园里所有帮助过我们的人 \ No newline at end of file +在这里感谢魔改后花园里所有帮助过我们的人 diff --git a/app/Controllers/PayConfig.php b/app/Controllers/PayConfig.php new file mode 100644 index 00000000..23fed157 --- /dev/null +++ b/app/Controllers/PayConfig.php @@ -0,0 +1,19 @@ +pay_config = [ + "secret" => "9A30EEBF727DE9A98B6AF916C2BCCA75", + "accesskey" => "C390D630A2B48094854048740A3900D9", + "notify_url" => "/yft/notify", + "return_url" => "/yft/notify", + "type" => "aliPay" + ]; + } +} \ No newline at end of file diff --git a/app/Controllers/QuickPayFunction.php b/app/Controllers/QuickPayFunction.php new file mode 100644 index 00000000..b127b765 --- /dev/null +++ b/app/Controllers/QuickPayFunction.php @@ -0,0 +1,107 @@ +"; + while (list ($key, $val) = each ($para)) { + $sHtml.= ""; + } + if ($pay_config->pay_config["type"] == "aliPay"){ + $sHtml .= ""; + }else{ + $sHtml .= ""; + } + //submit按钮控件请不要含有name属性 + $sHtml = $sHtml.""; + + $sHtml = $sHtml.""; + + return $sHtml; + } + /** + * 生成要请求给云通付的参数数组 + * @param $para_temp 请求前的参数数组 + * @return 要请求的参数数组 + */ + static function buildRequestPara($para_temp) { + //除去待签名参数数组中的空值和签名参数 + $para_filter = QuickPayFunction::paraFilter($para_temp); + //生成签名结果 + $mysign = QuickPayFunction::buildRequestMysign($para_filter); + + //签名结果与签名方式加入请求提交参数组中 + $para_filter['sign'] = $mysign; + + return $para_filter; + } + /** + * 除去数组中的空值和签名参数 + * @param $para 签名参数组 + * return 去掉空值与签名参数后的新签名参数组 + */ + static function paraFilter($para) { + $para_filter = array(); + while (list ($key, $val) = each ($para)) { + if($key == "sign" || $val == "")continue; + else $para_filter[$key] = $para[$key]; + } + return $para_filter; + } + /** + * 生成签名结果 + * @param $para_filter 要签名的数组 + * return 签名结果字符串 + */ + static function buildRequestMysign($para_filter) { + //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 + $prestr = QuickPayFunction::createLinkstring($para_filter); + $mysign = MD5($prestr); + return $mysign; + } + static function md5Sign($prestr) { + return md5($prestr); + } + /** + * 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 + * @param $para 需要拼接的数组 + * return 拼接完成以后的字符串 + */ + static function createLinkstring($para) { + $arg = ""; + while (list ($key, $val) = each ($para)) { + $arg.=$key."=".$val."&"; + } + //去掉最后一个&字符 + $arg = substr($arg,0,count($arg)-2); + + //如果存在转义字符,那么去掉转义 + if(get_magic_quotes_gpc()){$arg = stripslashes($arg);} + + return $arg; + } + +} \ No newline at end of file diff --git a/app/Controllers/YFTPayCallBackController.php b/app/Controllers/YFTPayCallBackController.php new file mode 100644 index 00000000..b259d92b --- /dev/null +++ b/app/Controllers/YFTPayCallBackController.php @@ -0,0 +1,128 @@ +getQueryParams()["total_fee"];//必填 + //易付通返回的订单号 + $yft_order_no = $request->getQueryParams()["trade_no"]; + //面板生成的订单号 + $ss_order_no = $request->getQueryParams()["out_trade_no"];//必填 + //订单说明 + $subject = $request->getQueryParams()["subject"];//必填 + //付款状态 + $trade_status = $request->getQueryParams()["trade_status"];//必填 + //加密验证字符串 + $sign = $request->getQueryParams()["sign"];//必填 + + $verifyNotify = YFTPayCallBackController::md5Verify(floatval($total_fee), $ss_order_no, $yft_order_no, $trade_status, $sign); + if ($verifyNotify) {//验证成功 + if ($trade_status == 'TRADE_SUCCESS') { + /* + 加入您的入库及判断代码; + >>>>>>>!!!为了保证数据传达到回调地址,会请求4次。所以必须要先判断订单状态,然后再插入到数据库,这样后面即使请求3次,也不会造成订单重复!!!!<<<<<<< + 判断返回金额与实金额是否想同; + 判断订单当前状态; + 完成以上才视为支付成功 + */ + $orderInfo = new YftOrder(); + $orderInfo = $orderInfo->where("ss_order", "=", $ss_order_no)->first(); + if ($orderInfo == "" || $orderInfo == null) { + return "订单不存在!"; + } + + if ($orderInfo->price != $total_fee) { + return "订单信息异常!"; + } + + $userInfo = new User(); + $userInfo = $userInfo->where("id", "=", $orderInfo->user_id)->first(); + + if (sizeof($orderInfo) != 0 && $orderInfo->state == 0) { + $oldMoney = $userInfo->money; + $userInfo->money = $total_fee + $oldMoney; + //更新用户余额信息 + $userInfo->save(); + //更新订单信息 + $orderInfo->yft_order = $yft_order_no; + $orderInfo->state = 1; + $orderInfo->save(); + //充值返利处理 start + if ($userInfo->ref_by != "" && $userInfo->ref_by != 0 && $userInfo->ref_by != null && Config::get('code_payback') != 0 && Config::get('code_payback') != null) { + $gift_user = User::where("id", "=", $userInfo->ref_by)->first(); + $gift_user->money = ($gift_user->money + ($total_fee * (Config::get('code_payback') / 100))); + $gift_user->save(); + + $Payback = new Payback(); + $Payback->total = $total_fee; + $Payback->userid = $userInfo->id; + $Payback->ref_by = $userInfo->ref_by; + $Payback->ref_get = $total_fee * (Config::get('code_payback') / 100); + $Payback->datetime = time(); + $Payback->save(); + } + //充值返利处理 end + //telegram提醒 + if (Config::get('enable_donate') == 'true' && Config::get("enable_telegram") == 'true') { + if ($userInfo->is_hide == 1) { + Telegram::Send("感谢!一位不愿透露姓名的大老爷给我们捐了 " . $total_fee . " 元呢~"); + } else { + Telegram::Send("感谢!" . $userInfo->user_name . " 大老爷给我们捐了 " . $total_fee . " 元呢~"); + } + } + } else { + return "订单号异常或交易已完成!"; + } + header("location:" . $request->getUri()->getScheme() . "://" . $request->getUri()->getHost() . "/user/code"); + return "支付成功"; + } else { + return "支付失败"; + } + } else { + //验证失败 + return "订单信息异常!请联系管理员"; + } + } + + /** + * @param $p1 + * @param $p2 + * @param $p3 + * @param $p4 + * @param $sign 传入要比对的sign + * @return boolean 返回比对结果 + */ + private static function md5Verify($p1, $p2, $p3, $p4, $sign) + { + $preStr = $p1 . $p2 . $p3 . $p4 . "yft"; + $mySign = md5($preStr); + if ($mySign == $sign) { + return true; + } else { + return false; + } + } +} \ No newline at end of file diff --git a/app/Controllers/YftPay.php b/app/Controllers/YftPay.php new file mode 100644 index 00000000..60bba88a --- /dev/null +++ b/app/Controllers/YftPay.php @@ -0,0 +1,193 @@ +user = Auth::getUser(); + } + + public function yft($request, $response, $args) + { + $price = $request->getParams()['price']; + return $this->view()->assign('price', $price)->display('user/yft.tpl'); + } + + public function yftPay($request, $response, $args) + { + + $yftLib = new QuickPayFunction(); + $pay_config = new PayConfig(); + $pay_config->init(); + + /**************************请求参数**************************/ + + //订单名称 + $subject = $request->getParams()['subject'];//必填 + + //付款金额 + $total_fee = $request->getParams()['total_fee'];//必填 需为整数 + + //服务器异步通知页面路径 + $notify_url = $request->getUri()->getScheme()."://".$request->getUri()->getHost().$pay_config->pay_config['notify_url']; + + //需http://格式的完整路径,不能加?id=123这类自定义参数 + + //页面跳转同步通知页面路径 + $return_url = $request->getUri()->getScheme()."://".$request->getUri()->getHost().$pay_config->pay_config["return_url"]; + //需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/ + + $secret = $pay_config->pay_config["secret"]; + + $accesskey = $pay_config->pay_config["accesskey"]; + + //生成订单号 + $ss_order_no = YftOrderNumUtil::generate_yftOrder(8); + + /************************************************************/ + //构造要请求的参数数组,无需改动 + $parameter = []; + if ($pay_config->pay_config["type"] == "aliPay") { + $parameter = [ + "total_fee" => $total_fee, + "notify_url" => $notify_url, + "return_url" => $return_url, + "secret" => $secret, + "out_trade_no" => $ss_order_no + ]; + } else { + $parameter = [ + "secret" => $secret, + "notify_url" => $notify_url, + "accesskey" => $accesskey, + "return_url" => $return_url, + "subject" => $subject, + "total_fee" => $total_fee + ]; + } + + //向数据库插入订单信息 + $yft_order_info = new YftOrder(); + $yft_order_info->user_id = $this->user->id; + $yft_order_info->ss_order = $ss_order_no; + $yft_order_info->price = $total_fee; + $yft_order_info->state = 0; + $yft_order_info->save(); + + //建立请求 + $html_text = $yftLib->buildRequestForm($parameter, $ss_order_no,$pay_config); + return $html_text; + + } + + public function yftPayResult($request, $response, $args) + { + $newResponse = $response->withStatus(302)->withHeader('Location', '/user/code'); + $yftLib = new QuickPayFunction(); + $pay_config = new PayConfig(); + $pay_config->init(); + + //价格 + $total_fee = $request->getParams()['total_fee'];//必填 + //付款状态 + $trade_status = $request->getParams()['trade_status'];//必填 + //加密验证字符串 + $sign = $request->getParams()['sign'];//必填 + //易付通返回的订单号 + $yft_order_no = $request->getParams()['yft_order_no']; + //面板生成的订单号 + $ss_order_no = $request->getParams()['ss_order_no'];//必填 + + $verifyNotify = $yftLib->md5Verify(floatval($total_fee), $trade_status, $pay_config->pay_config['secret'], $pay_config->pay_config['accesskey'], $sign); + if ($verifyNotify) {//验证成功 + if ($_REQUEST['trade_status'] == 'success') { + /* + 加入您的入库及判断代码; + >>>>>>>!!!为了保证数据传达到回调地址,会请求4次。所以必须要先判断订单状态,然后再插入到数据库,这样后面即使请求3次,也不会造成订单重复!!!!<<<<<<< + 判断返回金额与实金额是否想同; + 判断订单当前状态; + 完成以上才视为支付成功 + */ + $price = $request->getParams()['total_fee']; + $payInfo = YftOrder::where('ss_order', '=', $ss_order_no)->orderBy('id', 'desc')->first(); + $user = User::where('id', '=', $payInfo->user_id)->orderBy('id', 'desc')->first(); + if ($payInfo != null && $payInfo->state == 0) { + $old = $user->money; + $user->money = $price + $old; + $user->save(); + $payInfo->yft_order = $yft_order_no; + $payInfo->state = 1; + $payInfo->save(); + } else { + echo "订单号异常!请联系管理员!"; + sleep(2); + return $newResponse; + } + + echo "支付成功"; + return $newResponse; + } else { + echo "支付失败"; + return $newResponse; + } + + } else { + //验证失败 + echo "订单信息异常!请联系管理员"; + sleep(2); + return $newResponse; + } + } + + public function yftOrder($request, $response, $args) + { + $pageNum = 1; + if (isset($request->getQueryParams()["page"])) { + $pageNum = $request->getQueryParams()["page"]; + } + $orderList = YftOrder::where("user_id", $this->user->id)->orderBy("id", "asc")->paginate(15, ['*'], 'page', $pageNum); + $count = sizeof(YftOrder::where("user_id", $this->user->id)->get()); + $countPage = ceil($count / 15); + $orderList->setPath('/user/yftOrder'); + + return $this->view()->assign('orderList', $orderList)->assign('countPage', $countPage)->assign('currentPage', $pageNum)->display('user/yftOrder.tpl'); + } + + /** + * @desc 管理员查看所有充值记录 + * @param $request + * @param $response + * @param $args + * @return mixed + */ + public function yftOrderForAdmin($request, $response, $args) + { + $pageNum = 1; + if (isset($request->getQueryParams()["page"])) { + $pageNum = $request->getQueryParams()["page"]; + } + $orderList = YftOrder::where("price",">=", 0)->orderBy("id", "asc")->paginate(15, ['*'], 'page', $pageNum); + $count = sizeof(YftOrder::where("price",">=", 0)->get()); + $countPage = ceil($count / 15); + $orderList->setPath('/admin/yftOrder'); + + return $this->view()->assign('orderList', $orderList)->assign('countPage', $countPage)->assign('currentPage', $pageNum)->display('admin/yftOrder.tpl'); + } + +} \ No newline at end of file diff --git a/app/Models/YftOrder.php b/app/Models/YftOrder.php new file mode 100644 index 00000000..0f4cf8ac --- /dev/null +++ b/app/Models/YftOrder.php @@ -0,0 +1,17 @@ +local_gas_station 充值 '; } + private static function yftpay_html($user) + { + return ' +
+
+

在线充值

+
+ + +
+
+
+
+ +
+
+
+'; + } private static function pmw_html($user) { \Paymentwall_Config::getInstance()->set(array( diff --git a/app/Utils/YftOrderNumUtil.php b/app/Utils/YftOrderNumUtil.php new file mode 100644 index 00000000..a50b0cdf --- /dev/null +++ b/app/Utils/YftOrderNumUtil.php @@ -0,0 +1,28 @@ +get('/tos', 'App\Controllers\HomeController:tos'); $app->get('/staff', 'App\Controllers\HomeController:staff'); $app->get('/gfwlistjs', 'App\Controllers\LinkController:GetGfwlistJs'); $app->post('/telegram_callback', 'App\Controllers\HomeController:telegram'); +$app->get('/yft/notify','App\Controllers\YFTPayCallBackController:yft_notify'); + // User Center @@ -136,6 +138,12 @@ $app->group('/user', function () { $this->post('/kill', 'App\Controllers\UserController:handleKill'); $this->get('/logout', 'App\Controllers\UserController:logout'); $this->get('/code', 'App\Controllers\UserController:code'); + //易付通路由定义 start + $this->post('/code/yft/pay', 'App\Controllers\YftPay:yftPay'); + $this->get('/code/yft/pay/result', 'App\Controllers\YftPay:yftPayResult'); + $this->post('/code/yft', 'App\Controllers\YftPay:yft'); + $this->get('/yftOrder','App\Controllers\YftPay:yftOrder'); + //易付通路由定义 end $this->get('/alipay', 'App\Controllers\UserController:alipay'); $this->post('/code/f2fpay', 'App\Controllers\UserController:f2fpay'); $this->get('/code/f2fpay', 'App\Controllers\UserController:f2fpayget'); @@ -285,6 +293,7 @@ $app->group('/admin', function () { $this->get('/sys', 'App\Controllers\AdminController:sys'); $this->get('/logout', 'App\Controllers\AdminController:logout'); $this->post('/payback/ajax', 'App\Controllers\AdminController:ajax_payback'); + $this->get('/yftOrder','App\Controllers\YftPay:yftOrderForAdmin'); })->add(new Admin()); // API diff --git a/resources/views/material/admin/main.tpl b/resources/views/material/admin/main.tpl index 4554fb6a..58fc511c 100644 --- a/resources/views/material/admin/main.tpl +++ b/resources/views/material/admin/main.tpl @@ -109,7 +109,7 @@
  • shop 商品
  • card_giftcard 优惠码
  • shopping_cart 购买记录
  • -
  • loyalty 邀请码
  • +
  • shopping_cart 充值记录
  • person 用户中心
  • diff --git a/resources/views/material/admin/yftOrder.tpl b/resources/views/material/admin/yftOrder.tpl new file mode 100644 index 00000000..dba02326 --- /dev/null +++ b/resources/views/material/admin/yftOrder.tpl @@ -0,0 +1,85 @@ +{include file='admin/main.tpl'} + +
    +
    +
    +

    充值记录

    +
    +
    +
    +
    +
    + +
    +
    +
    +

    系统中充值记录。

    +
    +
    +
    + +
    + {$orderList->render()} + + + + + + + + + {if sizeof($orderList) > 0} + {foreach $orderList as $order} + + + + + + {if ($order->state == 1)}{else}{/if} + + {/foreach} + {else} + + + + {/if} +
    ID订单号金额充值时间状态
    #{$order->id}{$order->yft_order}{$order->price} 元{$order->create_time}已支付未支付
    暂无充值记录!
    +
    + 总共{$countPage}页 + + 当前第{$currentPage}页 + + 首页 + 上一页 + 下一页 + 尾页 + {$orderList->render()} +
    +
    +
    +{include file='admin/footer.tpl'} + \ No newline at end of file diff --git a/resources/views/material/user/yft.tpl b/resources/views/material/user/yft.tpl new file mode 100644 index 00000000..4c1920f8 --- /dev/null +++ b/resources/views/material/user/yft.tpl @@ -0,0 +1,7 @@ +
    + + +
    + \ No newline at end of file diff --git a/resources/views/material/user/yftOrder.tpl b/resources/views/material/user/yftOrder.tpl new file mode 100644 index 00000000..ad9ab937 --- /dev/null +++ b/resources/views/material/user/yftOrder.tpl @@ -0,0 +1,85 @@ +{include file='user/main.tpl'} + +
    +
    +
    +

    充值记录

    +
    +
    +
    +
    +
    + +
    +
    +
    +

    系统中您的充值记录。

    +
    +
    +
    + +
    + {$orderList->render()} + + + + + + + + + {if sizeof($orderList) > 0} + {foreach $orderList as $order} + + + + + + {if ($order->state == 1)}{else}{/if} + + {/foreach} + {else} + + + + {/if} +
    ID订单号金额充值时间状态
    #{$order->id}{$order->yft_order}{$order->price} 元{$order->create_time}已支付未支付
    暂无充值记录!
    +
    + 总共{$countPage}页 + + 当前第{$currentPage}页 + + 首页 + 上一页 + 下一页 + 尾页 + {$orderList->render()} +
    +
    +
    +{include file='user/footer.tpl'} + \ No newline at end of file From c0b7f92dfb20a0f48d68f455a9c93538057cf086 Mon Sep 17 00:00:00 2001 From: NimaQu Date: Sat, 24 Feb 2018 12:28:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=B0=86=E6=98=93=E4=BB=98=E9=80=9Akey?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=86=99=E5=85=A5config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controllers/PayConfig.php | 2 -- app/Controllers/YftPay.php | 5 +++-- config/.config.php.example | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Controllers/PayConfig.php b/app/Controllers/PayConfig.php index 23fed157..71dd084d 100644 --- a/app/Controllers/PayConfig.php +++ b/app/Controllers/PayConfig.php @@ -9,8 +9,6 @@ class PayConfig{ public function init() { $this->pay_config = [ - "secret" => "9A30EEBF727DE9A98B6AF916C2BCCA75", - "accesskey" => "C390D630A2B48094854048740A3900D9", "notify_url" => "/yft/notify", "return_url" => "/yft/notify", "type" => "aliPay" diff --git a/app/Controllers/YftPay.php b/app/Controllers/YftPay.php index 60bba88a..dea70ad5 100644 --- a/app/Controllers/YftPay.php +++ b/app/Controllers/YftPay.php @@ -13,6 +13,7 @@ use App\Models\User; use App\Models\YftOrder; use App\Services\Auth; use App\Utils\YftOrderNumUtil; +use App\Services\Config; class YftPay extends BaseController { @@ -53,9 +54,9 @@ class YftPay extends BaseController $return_url = $request->getUri()->getScheme()."://".$request->getUri()->getHost().$pay_config->pay_config["return_url"]; //需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/ - $secret = $pay_config->pay_config["secret"]; + $secret = Config::get('yft_secret'); - $accesskey = $pay_config->pay_config["accesskey"]; + $accesskey = Config::get('yft_accesskey'); //生成订单号 $ss_order_no = YftOrderNumUtil::generate_yftOrder(8); diff --git a/config/.config.php.example b/config/.config.php.example index b1292908..0789681b 100644 --- a/config/.config.php.example +++ b/config/.config.php.example @@ -316,6 +316,10 @@ $System_Config['pmw_height']='350px'; $System_Config['alipay_id']=''; $System_Config['alipay_key']=''; +#alipay,yftpay +$System_Config['yft_secret']=''; +$System_Config['yft_accesskey']=''; + #alipay,zfbjk.com $System_Config['zfbjk_pid']=''; $System_Config['zfbjk_key']='';