From 29c65ddc02703dcab505f224854c832f19bdd1e3 Mon Sep 17 00:00:00 2001 From: gaoyuheng Date: Thu, 10 Apr 2025 02:32:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9F=A9=E5=BF=97=E6=88=90=E4=BD=A0=E7=BB=99?= =?UTF-8?q?=E6=88=91=E4=BF=A9=E7=AD=89=E7=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/student/lib/EpayCore.class.php | 154 ++++++++++++++++++ admin/student/lib/epay.config.php | 13 ++ admin/student/notify_url.php | 60 +++++++ admin/student/return_url.php | 68 ++++++++ admin/student/submit.php | 74 +++++++++ admin/student/yajin_add.php | 26 +-- common/func_db.php | 4 +- danche.sql | 227 +++++++++++++++++++++++++++ 8 files changed, 599 insertions(+), 27 deletions(-) create mode 100644 admin/student/lib/EpayCore.class.php create mode 100644 admin/student/lib/epay.config.php create mode 100644 admin/student/notify_url.php create mode 100644 admin/student/return_url.php create mode 100644 admin/student/submit.php create mode 100644 danche.sql diff --git a/admin/student/lib/EpayCore.class.php b/admin/student/lib/EpayCore.class.php new file mode 100644 index 0000000..b3a5a78 --- /dev/null +++ b/admin/student/lib/EpayCore.class.php @@ -0,0 +1,154 @@ +pid = $config['pid']; + $this->key = $config['key']; + $this->submit_url = $config['apiurl'].'submit.php'; + $this->mapi_url = $config['apiurl'].'mapi.php'; + $this->api_url = $config['apiurl'].'api.php'; + } + + // 发起支付(页面跳转) + public function pagePay($param_tmp, $button='正在跳转'){ + $param = $this->buildRequestParam($param_tmp); + + $html = '
'; + foreach ($param as $k=>$v) { + $html.= ''; + } + $html .= '
'; + + return $html; + } + + // 发起支付(获取链接) + public function getPayLink($param_tmp){ + $param = $this->buildRequestParam($param_tmp); + $url = $this->submit_url.'?'.http_build_query($param); + return $url; + } + + // 发起支付(API接口) + public function apiPay($param_tmp){ + $param = $this->buildRequestParam($param_tmp); + $response = $this->getHttpResponse($this->mapi_url, http_build_query($param)); + $arr = json_decode($response, true); + return $arr; + } + + // 异步回调验证 + public function verifyNotify(){ + if(empty($_GET)) return false; + + $sign = $this->getSign($_GET); + + if($sign === $_GET['sign']){ + $signResult = true; + }else{ + $signResult = false; + } + + return $signResult; + } + + // 同步回调验证 + public function verifyReturn(){ + if(empty($_GET)) return false; + + $sign = $this->getSign($_GET); + + if($sign === $_GET['sign']){ + $signResult = true; + }else{ + $signResult = false; + } + + return $signResult; + } + + // 查询订单支付状态 + public function orderStatus($trade_no){ + $result = $this->queryOrder($trade_no); + if($result['status']==1){ + return true; + }else{ + return false; + } + } + + // 查询订单 + public function queryOrder($trade_no){ + $url = $this->api_url.'?act=order&pid=' . $this->pid . '&key=' . $this->key . '&trade_no=' . $trade_no; + $response = $this->getHttpResponse($url); + $arr = json_decode($response, true); + return $arr; + } + + // 订单退款 + public function refund($trade_no, $money){ + $url = $this->api_url.'?act=refund'; + $post = 'pid=' . $this->pid . '&key=' . $this->key . '&trade_no=' . $trade_no . '&money=' . $money; + $response = $this->getHttpResponse($url, $post); + $arr = json_decode($response, true); + return $arr; + } + + private function buildRequestParam($param){ + $mysign = $this->getSign($param); + $param['sign'] = $mysign; + $param['sign_type'] = $this->sign_type; + return $param; + } + + // 计算签名 + private function getSign($param){ + ksort($param); + reset($param); + $signstr = ''; + + foreach($param as $k => $v){ + if($k != "sign" && $k != "sign_type" && $v!=''){ + $signstr .= $k.'='.$v.'&'; + } + } + $signstr = substr($signstr,0,-1); + $signstr .= $this->key; + $sign = md5($signstr); + return $sign; + } + + // 请求外部资源 + private function getHttpResponse($url, $post = false, $timeout = 10){ + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + $httpheader[] = "Accept: */*"; + $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8"; + $httpheader[] = "Connection: close"; + curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if($post){ + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + } + $response = curl_exec($ch); + curl_close($ch); + return $response; + } +} diff --git a/admin/student/lib/epay.config.php b/admin/student/lib/epay.config.php new file mode 100644 index 0000000..a3f36c5 --- /dev/null +++ b/admin/student/lib/epay.config.php @@ -0,0 +1,13 @@ +verifyNotify(); + +if($verify_result) {//验证成功 + + //商户订单号 + $out_trade_no = $_GET['out_trade_no']; + + //彩虹易支付交易号 + $trade_no = $_GET['trade_no']; + + //交易状态 + $trade_status = $_GET['trade_status']; + + //支付方式 + $type = $_GET['type']; + + //支付金额 + $money = $_GET['money']; + + if ($_GET['trade_status'] == 'TRADE_SUCCESS') { + //判断该笔订单是否在商户网站中已经做过处理 + //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 + //如果有做过处理,不执行商户的业务程序 + $row = db_get_row("select * from payorder where orderid='". $out_trade_no ."'"); + if($row['status']==1){die("success");} + + $userid=$row['uid']; + $money=$row['money']; + $row1 = db_get_row("select * from yajin where userid='". $userid ."'"); + if ($row1["id"]) { //有过充值记录 + db_query("update yajin set price=price+".$money." where id=".$row1["id"]); + }else{ + $data2 = array(); + $data2["price"] = $money; + $data2["userid"] = $userid; + db_add("yajin",$data2); + } + db_query("update payorder set status=1 where orderid='". $out_trade_no ."'"); + } + //验证成功返回 + echo "success"; +} +else { + //验证失败 + echo "fail"; +} +?> \ No newline at end of file diff --git a/admin/student/return_url.php b/admin/student/return_url.php new file mode 100644 index 0000000..4968d41 --- /dev/null +++ b/admin/student/return_url.php @@ -0,0 +1,68 @@ + + + + + + 支付返回页面 + + +verifyReturn(); + +if($verify_result) {//验证成功 + + //商户订单号 + $out_trade_no = $_GET['out_trade_no']; + + //支付宝交易号 + $trade_no = $_GET['trade_no']; + + //交易状态 + $trade_status = $_GET['trade_status']; + + //支付方式 + $type = $_GET['type']; + + + if($_GET['trade_status'] == 'TRADE_SUCCESS') { + //判断该笔订单是否在商户网站中已经做过处理 + //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 + //如果有做过处理,不执行商户的业务程序 + $row = db_get_row("select * from payorder where orderid='". $out_trade_no ."'"); + if($row['status']==1){urlMsg("充值成功", "main.php");die();} + + $userid=$row['uid']; + $money=$row['money']; + $row1 = db_get_row("select * from yajin where userid='". $userid ."'"); + if ($row1["id"]) { //有过充值记录 + db_query("update yajin set price=price+".$money." where id=".$row1["id"]); + }else{ + $data2 = array(); + $data2["price"] = $money; + $data2["userid"] = $userid; + db_add("yajin",$data2); + } + db_query("update payorder set status=1 where orderid='". $out_trade_no ."'"); + urlMsg("充值成功", "main.php"); + } +} +else { + //验证失败 + urlMsg("充值失败", "main.php"); +} +?> + + \ No newline at end of file diff --git a/admin/student/submit.php b/admin/student/submit.php new file mode 100644 index 0000000..bcea254 --- /dev/null +++ b/admin/student/submit.php @@ -0,0 +1,74 @@ + + + + + + 正在为您跳转到支付页面,请稍候... + + + + + $epay_config['pid'], + "type" => "alipay", + "notify_url" => $notify_url, + "return_url" => $return_url, + "out_trade_no" => $db_data123['orderid'], + "name" => "预存款支付", + "money" => $db_data123['money'], +); + +$epay = new EpayCore($epay_config); +$html_text = $epay->pagePay($parameter); +echo $html_text; +?> +

正在为您跳转到支付页面,请稍候...

+ + + + + + + + + + + + + + + diff --git a/admin/student/yajin_add.php b/admin/student/yajin_add.php index f151c47..6350c5b 100644 --- a/admin/student/yajin_add.php +++ b/admin/student/yajin_add.php @@ -1,27 +1,3 @@ - @@ -44,7 +20,7 @@
-
+ diff --git a/common/func_db.php b/common/func_db.php index a6f8ac3..a302115 100644 --- a/common/func_db.php +++ b/common/func_db.php @@ -26,8 +26,8 @@ $strleft='insert into '.$table.' ('.ltrim($strleft,',').')'; $strright=' values ('.ltrim($strright,',').')'; $sql=$strleft.$strright; - //echo $sql; - //die; + // echo $sql; + // die; db_query($sql); return db_insert_id(); diff --git a/danche.sql b/danche.sql new file mode 100644 index 0000000..0433780 --- /dev/null +++ b/danche.sql @@ -0,0 +1,227 @@ +-- phpMyAdmin SQL Dump +-- version 4.0.10.20 +-- https://www.phpmyadmin.net +-- +-- 主机: localhost +-- 生成日期: 2025-04-10 02:32:17 +-- 服务器版本: 5.6.50-log +-- PHP 版本: 5.6.40 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- 数据库: `danche` +-- + +-- -------------------------------------------------------- + +-- +-- 表的结构 `admin` +-- + +CREATE TABLE IF NOT EXISTS `admin` ( + `id` int(4) NOT NULL AUTO_INCREMENT, + `username` varchar(50) DEFAULT NULL, + `password` varchar(50) DEFAULT NULL, + `type` varchar(30) DEFAULT NULL, + `img` varchar(50) DEFAULT NULL, + `sex` varchar(10) DEFAULT NULL, + `begintime` varchar(50) DEFAULT NULL, + `desc1` varchar(200) DEFAULT NULL, + `tname` varchar(10) DEFAULT NULL, + `tel` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ; + +-- +-- 转存表中的数据 `admin` +-- + +INSERT INTO `admin` (`id`, `username`, `password`, `type`, `img`, `sex`, `begintime`, `desc1`, `tname`, `tel`) VALUES +(1, 'admin', '21232f297a57a5a743894a0e4a801fc3', '超级管理员', '0', NULL, NULL, NULL, NULL, NULL); + +-- -------------------------------------------------------- + +-- +-- 表的结构 `baoxiu` +-- + +CREATE TABLE IF NOT EXISTS `baoxiu` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `carsid` int(11) DEFAULT '0' COMMENT '车辆id', + `content` varchar(250) DEFAULT NULL COMMENT '详细', + `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `status` varchar(10) DEFAULT '维修中' COMMENT '状态', + `eacherid` int(11) DEFAULT '0' COMMENT '人员id', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `cars` +-- + +CREATE TABLE IF NOT EXISTS `cars` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `categoryid` int(11) DEFAULT '0' COMMENT '品牌', + `colors` varchar(50) DEFAULT NULL COMMENT '颜色', + `title` varchar(50) DEFAULT NULL COMMENT '车牌号', + `img` varchar(50) DEFAULT NULL, + `ages` varchar(11) DEFAULT NULL COMMENT '车龄', + `lat` varchar(255) NOT NULL, + `lng` varchar(255) NOT NULL, + `status` varchar(10) DEFAULT NULL COMMENT '状态', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=56 ; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `category` +-- + +CREATE TABLE IF NOT EXISTS `category` ( + `id` int(6) NOT NULL AUTO_INCREMENT COMMENT 'id自然编号', + `title` varchar(60) NOT NULL COMMENT '名称', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ; + +-- +-- 转存表中的数据 `category` +-- + +INSERT INTO `category` (`id`, `title`) VALUES +(8, '出行'), +(7, 'hellobike'), +(6, 'ofo'), +(5, 'mobike'), +(9, '小蓝'), +(10, '123'); + +-- -------------------------------------------------------- + +-- +-- 表的结构 `eacher` +-- + +CREATE TABLE IF NOT EXISTS `eacher` ( + `id` int(4) NOT NULL AUTO_INCREMENT, + `username` varchar(50) DEFAULT NULL, + `password` varchar(50) DEFAULT NULL, + `img` varchar(50) DEFAULT NULL, + `sex` varchar(10) DEFAULT NULL, + `begintime` varchar(50) DEFAULT NULL, + `desc1` varchar(200) DEFAULT NULL, + `tname` varchar(10) DEFAULT NULL, + `tel` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ; + +-- +-- 转存表中的数据 `eacher` +-- + +INSERT INTO `eacher` (`id`, `username`, `password`, `img`, `sex`, `begintime`, `desc1`, `tname`, `tel`) VALUES +(8, '111222', '00b7691d86d96aebd21dd9e138f90840', '1756066.png', '男', '2000-10-09', '123', '王师傅2', '13325652145'); + +-- -------------------------------------------------------- + +-- +-- 表的结构 `orders` +-- + +CREATE TABLE IF NOT EXISTS `orders` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `studentid` varchar(50) DEFAULT '0' COMMENT '学生id', + `carsid` int(11) DEFAULT '0' COMMENT '车辆id', + `price` decimal(11,0) DEFAULT '0' COMMENT '预计价格', + `begintime` date DEFAULT NULL COMMENT '开始时间', + `endtime` date DEFAULT NULL COMMENT '结束时间', + `addtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间', + `status` varchar(50) DEFAULT NULL, + `carstitle` varchar(50) DEFAULT NULL COMMENT '车牌号', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=28 ; + +-- -------------------------------------------------------- + +-- +-- 表的结构 `payorder` +-- + +CREATE TABLE IF NOT EXISTS `payorder` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `orderid` text NOT NULL, + `uid` text NOT NULL, + `money` text NOT NULL, + `status` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=27 ; + +-- +-- 转存表中的数据 `payorder` +-- + +INSERT INTO `payorder` (`id`, `orderid`, `uid`, `money`, `status`) VALUES +(26, '2025041002282963899', '18', '300', 1); + +-- -------------------------------------------------------- + +-- +-- 表的结构 `user` +-- + +CREATE TABLE IF NOT EXISTS `user` ( + `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, + `studentid` varchar(64) NOT NULL COMMENT '学号', + `stuname` varchar(50) NOT NULL COMMENT '姓名', + `password` char(32) NOT NULL COMMENT '密码', + `banji` varchar(50) DEFAULT NULL COMMENT '班级', + `addtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '注册时间', + `img` varchar(255) DEFAULT NULL COMMENT '头像', + `sex` varchar(255) DEFAULT NULL COMMENT '性别', + `status` int(2) NOT NULL DEFAULT '0' COMMENT '状态', + `tel` varchar(50) DEFAULT NULL COMMENT '电话', + PRIMARY KEY (`id`), + UNIQUE KEY `account` (`studentid`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ; + +-- +-- 转存表中的数据 `user` +-- + +INSERT INTO `user` (`id`, `studentid`, `stuname`, `password`, `banji`, `addtime`, `img`, `sex`, `status`, `tel`) VALUES +(18, '20221109', '张三', 'c812a07d304cedbaceb66144428d6c7a', '网络工程2班', '2022-11-09 05:35:31', '2516853.png', '男', 0, '13325652145'); + +-- -------------------------------------------------------- + +-- +-- 表的结构 `yajin` +-- + +CREATE TABLE IF NOT EXISTS `yajin` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `userid` int(11) DEFAULT '0' COMMENT '学生id', + `price` decimal(11,0) NOT NULL DEFAULT '0' COMMENT '金额', + `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '时间', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ; + +-- +-- 转存表中的数据 `yajin` +-- + +INSERT INTO `yajin` (`id`, `userid`, `price`, `addtime`) VALUES +(9, 18, '300', '2025-04-09 18:29:03'); + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;