韩志成你给我俩等着

This commit is contained in:
2025-04-10 02:32:42 +08:00
parent 188fe51b24
commit 29c65ddc02
8 changed files with 599 additions and 27 deletions

View File

@@ -0,0 +1,154 @@
<?php
/* *
* 彩虹易支付SDK服务类
* 说明:
* 包含发起支付、查询订单、回调验证等功能
*/
class EpayCore
{
private $pid;
private $key;
private $submit_url;
private $mapi_url;
private $api_url;
private $sign_type = 'MD5';
function __construct($config){
$this->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 = '<form id="dopay" action="'.$this->submit_url.'" method="post">';
foreach ($param as $k=>$v) {
$html.= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
}
$html .= '<input type="submit" value="'.$button.'"></form><script>document.getElementById("dopay").submit();</script>';
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;
}
}

View File

@@ -0,0 +1,13 @@
<?php
/* *
* 配置文件
*/
//支付接口地址
$epay_config['apiurl'] = 'http://epay.web-dev.nia.ink/';
//商户ID
$epay_config['pid'] = '1000';
//商户密钥
$epay_config['key'] = 'v16bJiwTo744Bkw24Epk547DIEPdQeza';

View File

@@ -0,0 +1,60 @@
<?php
/* *
* 功能:彩虹易支付异步通知页面
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
*/
require_once("lib/epay.config.php");
require_once("lib/EpayCore.class.php");
include_once("../../common/init.php");
//计算得出通知验证结果
$epay = new EpayCore($epay_config);
$verify_result = $epay->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";
}
?>

View File

@@ -0,0 +1,68 @@
<?php
/* *
* 功能:彩虹易支付页面跳转同步通知页面
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
*/
require_once("lib/epay.config.php");
require_once("lib/EpayCore.class.php");
include_once("../../common/init.php");
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>支付返回页面</title>
</head>
<body>
<?php
//计算得出通知验证结果
$epay = new EpayCore($epay_config);
$verify_result = $epay->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");
}
?>
</body>
</html>

74
admin/student/submit.php Normal file
View File

@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>正在为您跳转到支付页面,请稍候...</title>
<style type="text/css">
body{margin:0;padding:0}
p{position:absolute;left:50%;top:50%;height:35px;margin:-35px 0 0 -160px;padding:20px;font:bold 16px/30px "宋体",Arial;text-indent:40px;border:1px solid #c5d0dc}
#waiting{font-family:Arial}
</style>
</head>
<body>
<?php
include_once("../../common/init.php");
require_once("lib/epay.config.php");
require_once("lib/EpayCore.class.php");
check_loginuser();
$_POST['price']=isset($_GET['price'])?$_GET['price']:$_POST['price'];
if(!$_POST){goBakMsg("请输入金额");die;}
$row = db_get_row("select * from yajin where userid='". $_SESSION["studentid"] ."'");
if ($row["id"]) { //有过充值记录
if($_POST["price"]+$row["price"]<300){
goBakMsg("预存款不能少于300元");
die;
}
}else{ //新户开号
if($_POST["price"]<300){
goBakMsg("预存款不能少于300元");
die;
}
}
$notify_url = "http://danche.web-dev.nia.ink/admin/student/notify_url.php";
$return_url = "http://danche.web-dev.nia.ink/admin/student/return_url.php";
$db_data123=array();
$db_data123['orderid'] =date("YmdHis").rand(10000,99999);
$db_data123['money']=$_POST["price"];
$db_data123['uid']=$_SESSION["studentid"];
db_add("payorder",$db_data123);
$parameter = array(
"pid" => $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;
?>
<p>正在为您跳转到支付页面,请稍候...</p>
</body>
</html>

View File

@@ -1,27 +1,3 @@
<?php
include_once("../../common/init.php");
check_loginuser();
if ($_POST){
$data = array();
$row = db_get_row("select * from yajin where userid='". $_SESSION["studentid"] ."'");
if ($row["id"]) {
if($_POST["price"]+$row["price"]<300){
goBakMsg("预存款不能少于300元");
die;}else{db_query("update yajin set price=price+".$_POST["price"]." where id=".$row["id"]);}
}
else{if($_POST["price"]<300){goBakMsg("预存款不能少于300元");die;}}
$data["price"] = "'".$_POST["price"]."'";
$data["studentid"] = "'".$_SESSION['stuname']."'";
$data["userid"] = "'".$_SESSION['studentid']."'";
if ($row["id"]) {
} else {
db_add("yajin",$data);
}
urlMsg("提交成功", "main.php");
die;
}
?>
<?php include_once("base.php");?>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
@@ -44,7 +20,7 @@
<table width="100%">
<tr>
<td colspan="2">
<form name="add" method="post" action="?" enctype="multipart/form-data">
<form name="add" method="post" action="submit.php" enctype="multipart/form-data">
<table width="100%" class="cont">
<tr>