充值记录
+系统中充值记录。
+| ID | +订单号 | +金额 | +充值时间 | +状态 | +|
|---|---|---|---|---|---|
| #{$order->id} | +{$order->yft_order} | +{$order->price} 元 | +{$order->create_time} | + {if ($order->state == 1)}已支付 | {else}未支付 | {/if} +
| 暂无充值记录! | +|||||
diff --git a/app/Controllers/PayConfig.php b/app/Controllers/PayConfig.php new file mode 100644 index 00000000..71dd084d --- /dev/null +++ b/app/Controllers/PayConfig.php @@ -0,0 +1,17 @@ +pay_config = [ + "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..dea70ad5 --- /dev/null +++ b/app/Controllers/YftPay.php @@ -0,0 +1,194 @@ +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 = Config::get('yft_secret'); + + $accesskey = Config::get('yft_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 @@系统中充值记录。
+| ID | +订单号 | +金额 | +充值时间 | +状态 | +|
|---|---|---|---|---|---|
| #{$order->id} | +{$order->yft_order} | +{$order->price} 元 | +{$order->create_time} | + {if ($order->state == 1)}已支付 | {else}未支付 | {/if} +
| 暂无充值记录! | +|||||
系统中您的充值记录。
+| ID | +订单号 | +金额 | +充值时间 | +状态 | +|
|---|---|---|---|---|---|
| #{$order->id} | +{$order->yft_order} | +{$order->price} 元 | +{$order->create_time} | + {if ($order->state == 1)}已支付 | {else}未支付 | {/if} +
| 暂无充值记录! | +|||||