This commit is contained in:
2025-07-10 23:55:26 +08:00
commit f140c92ddd
1840 changed files with 184740 additions and 0 deletions

75
pay/api.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
/**
天天支付 www.ttfk.cc
亲手写的代码。请保留信息!
对得起自己的职业操守!
**/
require_once("config.php");
require_once("lib/sub.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>支付中心</title>
</head>
<?php
/**************************请求参数**************************/
$notify_url = "http://".$_SERVER['HTTP_HOST']."/pay/notify_url.php";
//需http://格式的完整路径,不能加?id=123这类自定义参数
//页面跳转同步通知页面路径
$return_url = "https://www.youtube.com";
//需http://格式的完整路径,不能加?id=123这类自定义参数不能写成http://localhost/
//商户订单号
$out_trade_no = 'zs_'.$_POST['WIDout_trade_no'];
//商户网站订单系统中唯一订单号,必填
//支付方式
$type = $_POST['type'];
//商品名称
$name = $_POST['game_name'];
//付款金额
$money = $_POST['money'];
//站点名称
$sitename = $yxm;
//必填
//订单描述
/************************************************************/
//构造要请求的参数数组,无需改动
$parameter = array(
"pid" => trim($alipay_config['partner']),
"type" => $type,
"notify_url" => $notify_url,
"return_url" => $return_url,
"out_trade_no" => $out_trade_no,
"name" => $name,
"money" => $money,
"sitename" => $sitename
);
//建立请求
$alipaySubmit = new AlipaySubmit($alipay_config);
$html_text = $alipaySubmit->buildRequestForm($parameter);
echo $html_text;
preg_match('@^(?:https://)?([^/]+)@i',
$alipay_config['apiurl'], $matches);
$host = $matches[1];
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
if ($matches[0] !=$copy)
{
exit("&#24403;&#21069;&#97;&#112;&#105;&#26410;&#25480;&#26435;&#65281;&#35831;&#20351;&#29992;&#119;&#119;&#119;&#46;&#116;&#116;&#102;&#107;&#46;&#99;&#99;");
}
?>
</body>
</html>

34
pay/config.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
require '../config.php';
$id = '10328'; //商户id www.ttfk.cc 获取
$apikey = 'wjxrfmjxgm8ngmtn4w0th9luk21rpki9'; //商户密钥 www.ttfk.cc 获取
$yxm = $_CONFIG['game_name'];
$bili = '1'; // 写2 就是双倍领取
$pfid = $_CONFIG['pf_id'];
$wupin = array(
//'1' => 'com.game191.icelegend10', // test
'10' => 'com.game191.icelegend10',
'30' => 'com.game191.icelegend30',
'50' => 'com.game191.icelegend50',
'100' => 'com.game191.icelegend100',
'300' => 'com.game191.icelegend300',
'500' => 'com.game191.icelegend500',
'1000' => 'com.game191.icelegend1000',
'3000' => 'com.game191.icelegend3000',
);
$alipay_config['partner'] = $id;
$alipay_config['key'] = $apikey;
//签名方式 不需修改
$alipay_config['sign_type'] = strtoupper('MD5');
//字符编码格式 目前支持 gbk 或 utf-8
$alipay_config['input_charset'] = strtolower('utf-8');
//访问模式,根据自己的服务器是否支持ssl访问若支持请选择https若不支持请选择http
$alipay_config['transport'] = 'http';
$alipay_config['apiurl'] = 'https://www.ttfk.cc/';

43
pay/img/css/style.css Normal file
View File

@@ -0,0 +1,43 @@
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,legend,button,form,fieldset,input,textarea,p,blockquote,th,td{padding:0;margin:0;}
q:before,q:after{content:'';}
fieldset,img,abbr,acronym{border:0 none;}
abbr,acronym{font-variant:normal;}
legend{color:#000;}
address,caption,cite,code,dfn,em,strong,th,var{font-weight:normal;font-style:normal;}
sup{vertical-align:text-top;}
sub{vertical-align:text-bottom;}
table{border-collapse:collapse;border-spacing:0;}
caption,th{text-align:left;}
input,img,select{vertical-align:middle;}
ol,ul{list-style:none;}
input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;}
h1,h2,h3,h4,h5,h6{font-weight:normal;font-size:100%;}
del,ins,a{text-decoration:none;}
a:link{}
a:visited{}
input[type="submit"]{cursor:pointer;}
.content{width: 100%;float: left;}
button{cursor:pointer;}
input::-moz-focus-inner{border:0;padding:0;}
.clear{clear:both;}
.aaa,.aaaa{ border-radius: 5px; display: block;width: 30%;float: left;margin: 1% 0.5%;text-align: center;height: 2.5rem;line-height: 2.5rem;border: 1px solid #3369ff;color: #3369ff;}
.aaamoney{border-radius: 5px;border: none;width:100%;text-align: center;line-height: 2.5rem;}
.text-center{width: 80%;margin: 0 auto;}
p{color: #6262ff;font-weight: 800;}
.game_name{border-radius: 5px;height: 2.5rem;text-indent: 0.5rem;width: 100%;border: solid #627bff 1px;background: #fff;margin: 10px 0px;line-height: 2.5rem;}
.serverlist{border-radius: 5px;text-indent: 0.5rem;height: 2.5rem;width: 100%;border: solid #627bff 1px;background: #fff;margin: 10px 0px;color:#f46262;font-weight: 800;line-height: 2.5rem;}
.top_center{font-size: 2rem;margin: 1rem 1rem;color: #ff6767;font-weight: 800;}
.bottom{float: left;width: 100%;}
.bottom p{height:3rem;height: 3rem;width: 45%;float: left;background: #f8f8f8;margin: 10px 0px 10px 13px;line-height: 3rem;border-radius: 5px;}
.wxpay{background: url(/pay/img/wx.png) 50% 50% no-repeat;}
.alipay{ background: url(/pay/img/zfb.png) 40% 50% no-repeat;}
.bottom button{height: 3rem;width: 100%;border: solid 1px #3369ff;border-radius: 5px;}
input:-webkit-autofill {-webkit-box-shadow: 0 0 0px 1000px white inset !important;}
#autoBox{display:none; border: solid #627bff 1px;border-radius: 5px;}
#autoBox li{ border-bottom: dashed #627bff 1px; margin: 2% 5%; font-size: 1.1rem;height: 1.5rem;font-weight: 800;line-height: 1.5rem;}
#autoBox li span{float: right;color:#ff4141;}
form {width: 100%;height: 100%;float: left;}
.footer{float: left;margin: 0 auto;height: 3rem;width: 100%;
}
.footer p{text-align:center;margin-top:5%;}
.footer a{color: #f97474;}

BIN
pay/img/wx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

BIN
pay/img/zfb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

69
pay/index.php Normal file
View File

@@ -0,0 +1,69 @@
<?php
/**
天天支付 www.ttfk.cc
亲手写的代码。请保留信息!
对得起自己的职业操守!
**/
require 'config.php';
$serverid = htmlspecialchars(trim($_GET['serverId']));
$actorid = htmlspecialchars(trim($_GET['actorid']));
$money = htmlspecialchars(trim($_GET['amount']));
if(0 >= $money) exit('金额错误!');
if(!isset($serverid) || !isset($actorid)) exit('参数错误!');
$sid = intval(str_replace('s', '', $serverid));
$db_name = 'mir_actor_s'.$sid;
if(0 >= $sid) exit('区服ID错误');
$conn = new mysqli($_CONFIG_DB['db_host'], $_CONFIG_DB['db_user'], $_CONFIG_DB['db_password'], $db_name, $_CONFIG_DB['db_port']);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
$stmt = $conn->prepare('SELECT actorname FROM `actors` WHERE actorid = ? limit 1');
$stmt->bind_param('s', $actorid);
$stmt->execute();
$result = $stmt->get_result();
$row = mysqli_fetch_assoc($result);
if(empty($row)) exit('找不到角色!');
$username = isset($row) ? $row['actorname'] : '';
$out_trade_no = date("YmdHis").mt_rand(100,999);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<link type="text/css" rel="stylesheet" href="./img/css/style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>赞助中心-<?=$_CONFIG['game_name']?></title>
</head>
<body >
<!-- <center class="top_center" ><?php echo $yxm?></center>
<form method="post" action="api.php" role="form">
<div class="text-center">
<p class="serverlist">区服 : <?php echo $serverid?></p>
<p class="serverlist">昵称 : <?php echo $username?></p>
<p class="serverlist">金额 : <?php echo $money?></p>
</div>
<div class="content">
<input type="hidden" class="game_name" id="game_name" value="<?php echo $serverid."_".$actorid."_".$username?>" autocomplete="off" name="game_name"/>
<input type="hidden" name="pid" value="<?php echo $id?>" />
<input class="form-control" placeholder="商户订单号" type="hidden" value="h5<?php echo $out_trade_no ?>" name="WIDout_trade_no" type="text" readonly="readonly">
<input type="hidden" class="aaa" autocomplete="off" value="<?php echo $money;?>" name="money"/>
</div>
<div class="bottom">
<p><button type="radio" value="wxpay" name="type" class="btn wxpay btn-success my-3"></button></p>
<p><button type="radio" value="alipay" name="type" class="btn alipay btn-success my-3"></button></p>
</div>
</form>-->
<div class="footer">
<p>想充值!没门儿~ 看游戏公告,免费后台充值哈~</p>
</div>
</body>
</html>

176
pay/lib/core.php Normal file
View File

@@ -0,0 +1,176 @@
<?php
/* *
* 支付宝接口公用函数
* 详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件
* 版本3.3
* 日期2019-07-19
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param $para 需要拼接的数组
* return 拼接完成以后的字符串
*/
function createLinkstring($para) {
$arg = "";
foreach ($para as $key => $val) {
$arg.=$key."=".$val."&";
}
//去掉最后一个&字符
$arg = substr($arg,0,count((array)$arg)-2);
//如果存在转义字符,那么去掉转义
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()){$arg = stripslashes($arg);}
return $arg;
}
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串并对字符串做urlencode编码
* @param $para 需要拼接的数组
* return 拼接完成以后的字符串
*/
function createLinkstringUrlencode($para) {
$arg = "";
foreach ($para as $key => $val) {
$arg.=$key."=".urlencode($val)."&";
}
//去掉最后一个&字符
$arg = substr($arg,0,count($arg)-2);
//如果存在转义字符,那么去掉转义
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()){$arg = stripslashes($arg);}
return $arg;
}
/**
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
function paraFilter($para) {
$para_filter = array();
foreach ($para as $key => $val) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
/**
* 对数组排序
* @param $para 排序前的数组
* return 排序后的数组
*/
function argSort($para) {
ksort($para);
reset($para);
return $para;
}
/**
* 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
* 注意服务器需要开通fopen配置
* @param $word 要写入日志里的文本内容 默认值:空值
*/
function logResult($word='') {
$fp = fopen("log.txt","a");
flock($fp, LOCK_EX) ;
fwrite($fp,"执行日期:".strftime("%Y%m%d%H%M%S",time())."\n".$word."\n");
flock($fp, LOCK_UN);
fclose($fp);
}
/**
* 远程获取数据POST模式
* 注意:
* 1.使用Crul需要修改服务器中php.ini文件的设置找到php_curl.dll去掉前面的";"就行了
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效目前默认路径是getcwd().'\\cacert.pem'
* @param $url 指定URL完整路径地址
* @param $cacert_url 指定当前工作目录绝对路径
* @param $para 请求的数据
* @param $input_charset 编码格式。默认值:空值
* return 远程输出的数据
*/
function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '') {
if (trim($input_charset) != '') {
$url = $url."_input_charset=".$input_charset;
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址
curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果
curl_setopt($curl,CURLOPT_POST,true); // post传输数据
curl_setopt($curl,CURLOPT_POSTFIELDS,$para);// post传输数据
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常可打开此开关以便查看异常内容
curl_close($curl);
return $responseText;
}
/**
* 远程获取数据GET模式
* 注意:
* 1.使用Crul需要修改服务器中php.ini文件的设置找到php_curl.dll去掉前面的";"就行了
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效目前默认路径是getcwd().'\\cacert.pem'
* @param $url 指定URL完整路径地址
* @param $cacert_url 指定当前工作目录绝对路径
* return 远程输出的数据
*/
function getHttpResponseGET($url,$cacert_url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常可打开此开关以便查看异常内容
curl_close($curl);
return $responseText;
}
/**
* 实现多种字符编码方式
* @param $input 需要编码的字符串
* @param $_output_charset 输出的编码格式
* @param $_input_charset 输入的编码格式
* return 编码后的字符串
*/
function charsetEncode($input,$_output_charset ,$_input_charset) {
$output = "";
if(!isset($_output_charset) )$_output_charset = $_input_charset;
if($_input_charset == $_output_charset || $input ==null ) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
} elseif(function_exists("iconv")) {
$output = iconv($_input_charset,$_output_charset,$input);
} else die("sorry, you have no libs support for charset change.");
return $output;
}
/**
* 实现多种字符解码方式
* @param $input 需要解码的字符串
* @param $_output_charset 输出的解码格式
* @param $_input_charset 输入的解码格式
* return 解码后的字符串
*/
function charsetDecode($input,$_input_charset ,$_output_charset) {
$output = "";
if(!isset($_input_charset) )$_input_charset = $_input_charset ;
if($_input_charset == $_output_charset || $input ==null ) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
} elseif(function_exists("iconv")) {
$output = iconv($_input_charset,$_output_charset,$input);
} else die("sorry, you have no libs support for charset changes.");
return $output;
}
?>

41
pay/lib/md5.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
/* *
* MD5
* 详细MD5加密
* 版本3.3
* 日期2019-07-19
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
/**
* 签名字符串
* @param $prestr 需要签名的字符串
* @param $key 私钥
* return 签名结果
*/
function md5Sign($prestr, $key) {
$prestr = $prestr . $key;
return md5($prestr);
}
/**
* 验证签名
* @param $prestr 需要签名的字符串
* @param $sign 签名结果
* @param $key 私钥
* return 签名结果
*/
function md5Verify($prestr, $sign, $key) {
$prestr = $prestr . $key;
$mysgin = md5($prestr);
if($mysgin == $sign) {
return true;
}
else {
return false;
}
}
?>

120
pay/lib/notify.php Normal file
View File

@@ -0,0 +1,120 @@
<?php
/* *
* 功能:天天支付通知处理类
* 详细:处理易支付接口通知返回
*/
require_once("core.php");
require_once("md5.php");
class AlipayNotify {
var $alipay_config;
function __construct($alipay_config){
$this->alipay_config = $alipay_config;
$this->http_verify_url = $this->alipay_config['apiurl'].'api.php?';
}
function AlipayNotify($alipay_config) {
$this->__construct($alipay_config);
}
/**
* 针对notify_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function verifyNotify(){
if(empty($_POST)) {//判断POST来的数组是否为空
return false;
}
else {
//生成签名结果
$isSign = $this->getSignVeryfy($_POST, $_POST["sign"]);
//获取支付宝远程服务器ATN结果验证是否是支付宝发来的消息
$responseTxt = 'true';
//if (! empty($_POST["notify_id"])) {$responseTxt = $this->getResponse($_POST["notify_id"]);}
//验证
//$responsetTxt的结果不是true与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true与安全校验码、请求时的参数格式带自定义参数等、编码格式有关
if (preg_match("/true$/i",$responseTxt) && $isSign) {
return true;
} else {
return false;
}
}
}
/**
* 针对return_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function verifyReturn(){
if(empty($_POST)) {//判断POST来的数组是否为空
return false;
}
else {
//生成签名结果
$isSign = $this->getSignVeryfy($_POST, $_POST["sign"]);
//获取支付宝远程服务器ATN结果验证是否是支付宝发来的消息
$responseTxt = 'true';
//if (! empty($_POST["notify_id"])) {$responseTxt = $this->getResponse($_POST["notify_id"]);}
//验证
//$responsetTxt的结果不是true与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true与安全校验码、请求时的参数格式带自定义参数等、编码格式有关
if (preg_match("/true$/i",$responseTxt) && $isSign) {
return true;
} else {
return false;
}
}
}
/**
* 获取返回时的签名验证结果
* @param $para_temp 通知返回来的参数数组
* @param $sign 返回的签名结果
* @return 签名验证结果
*/
function getSignVeryfy($para_temp, $sign) {
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = argSort($para_filter);
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($para_sort);
$isSgin = false;
$isSgin = md5Verify($prestr, $sign, $this->alipay_config['key']);
return $isSgin;
}
/**
* 获取远程服务器ATN结果,验证返回URL
* @param $notify_id 通知校验ID
* @return 服务器ATN结果
* 验证结果集:
* invalid命令参数不对 出现这个错误请检测返回处理中partner和key是否为空
* true 返回正确信息
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
*/
function getResponse($notify_id) {
$transport = strtolower(trim($this->alipay_config['transport']));
$partner = trim($this->alipay_config['partner']);
$veryfy_url = '';
if($transport == 'https') {
$veryfy_url = $this->https_verify_url;
}
else {
$veryfy_url = $this->http_verify_url;
}
$veryfy_url = $veryfy_url."partner=" . $partner . "&notify_id=" . $notify_id;
$responseTxt = getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']);
return $responseTxt;
}
}
?>

103
pay/lib/sub.php Normal file
View File

@@ -0,0 +1,103 @@
<?php
$copy = "ttfk.cc";
preg_match('@^(?:https://)?([^/]+)@i',
$alipay_config['apiurl'], $matches);
$host = $matches[1];
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
if ($matches[0] !=$copy)
{
exit("&#24403;&#21069;&#97;&#112;&#105;&#26410;&#25480;&#26435;&#65281;&#35831;&#20351;&#29992;&#119;&#119;&#119;&#46;&#116;&#116;&#102;&#107;&#46;&#99;&#99;");
}
require_once("core.php");
require_once("md5.php");
class AlipaySubmit {
var $alipay_config;
function __construct($alipay_config){
$this->alipay_config = $alipay_config;
$this->alipay_gateway_new = $this->alipay_config['apiurl'].'submit.php?';
}
function AlipaySubmit($alipay_config) {
$this->__construct($alipay_config);
}
/**
* 生成签名结果
* @param $para_sort 已排序要签名的数组
* return 签名结果字符串
*/
function buildRequestMysign($para_sort) {
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($para_sort);
$mysign = md5Sign($prestr, $this->alipay_config['key']);
return $mysign;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组
*/
function buildRequestPara($para_temp) {
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = argSort($para_filter);
//生成签名结果
$mysign = $this->buildRequestMysign($para_sort);
//签名结果与签名方式加入请求提交参数组中
$para_sort['sign'] = $mysign;
$para_sort['sign_type'] = strtoupper(trim($this->alipay_config['sign_type']));
return $para_sort;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组字符串
*/
function buildRequestParaToString($para_temp) {
//待请求参数数组
$para = $this->buildRequestPara($para_temp);
//把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串并对字符串做urlencode编码
$request_data = createLinkstringUrlencode($para);
return $request_data;
}
/**
* 建立请求以表单HTML形式构造默认
* @param $para_temp 请求参数数组
* @param $method 提交方式。两个值可选post、get
* @param $button_name 确认按钮显示文字
* @return 提交表单HTML文本
*/
function buildRequestForm($para_temp, $method='POST', $button_name='正在跳转') {
//待请求参数数组
$para = $this->buildRequestPara($para_temp);
$sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='".$this->alipay_gateway_new."_input_charset=".trim(strtolower($this->alipay_config['input_charset']))."' method='".$method."'>";
foreach ($para as $key => $val) {
$sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>";
}
//submit按钮控件请不要含有name属性
$sHtml = $sHtml."<input type='submit' value='".$button_name."'></form>";
$sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>";
return $sHtml;
}
}
?>

137
pay/notify_url.php Normal file
View File

@@ -0,0 +1,137 @@
<?php
/* 支付回调 */
require_once 'config.php';
require_once 'lib/notify.php';
error_reporting(E_ALL & ~E_NOTICE);
function payLog($exit = false, $msg = '') {
global $_POST;
$date = date('Y-m-d');
// 创建日志目录
$path = '../log/';
if(!is_dir($path)) {
@mkdir($path, 0777, true);
}
$file = 'pay_'.$date.'_'.md5($date.BASE_KEY).'.log';
$logFile = $path.$file;
file_put_contents($logFile, '['.date('Y-m-d H:i:s').'] '.$msg.PHP_EOL.(isset($_POST) && !empty($_POST) ? print_r($_POST, true).PHP_EOL : ''), FILE_APPEND);
if($exit) exit($msg);
}
$time = time();
if(get_extension_funcs('mysqli') == false) payLog(true, 'mysqli扩展未启用');
// 检查参数
if(!isset($_POST['sign'])) {
$_POST = $_GET;
}
if(!isset($_POST) || empty($_POST)) payLog(true, 'POST参数错误');
$money = floatval($_POST['money']);
if(0 >= $money) payLog(true, '金额错误!');
$arr = explode('_', $_POST['name']);
$serverId = $arr['0'];
$roleId = $arr['1'];
$username = $arr['2'];
if(!isset($serverId) || !isset($roleId) || !isset($username)) payLog(true, 'serverId/roleId/username参数错误');
$sid = intval(str_replace('s', '', $serverId));
$db_name = 'mir_actor_s'.$sid;
if(0 >= $sid) payLog(true, '区服ID错误');
// 计算得出通知验证结果
$alipayNotify = new AlipayNotify($alipay_config);
$verify_result = $alipayNotify->verifyNotify();
if(!$verify_result) {
payLog(true, '签名验证失败');
}
// 连接区服数据库
$actorDB = new mysqli($_CONFIG_DB['db_host'], $_CONFIG_DB['db_user'], $_CONFIG_DB['db_password'], $db_name, $_CONFIG_DB['db_port']);
if ($actorDB->connect_error) payLog(true, '区服数据库连接失败: '.$actorDB->connect_error);
$feeSQL = "INSERT INTO `feecallback` (`pfid`, `serverid`, `actorid`, `account`, `prodid`, `num`, `oldserverid`) VALUES ('$pfid', '$sid', '$roleId', '$username', '{$wupin["$money"]}', '$bili', '1')";
// FEE插入成功
if (TRUE === $actorDB->query($feeSQL)) {
payLog(false, 'fee insert success'.PHP_EOL.$feeSQL);
// 连接订单数据库
$orderDB = new mysqli($_CONFIG_DB['db_host'], $_CONFIG_DB['db_user'], $_CONFIG_DB['db_password'], $_CONFIG_DB['db_name'], $_CONFIG_DB['db_port']);
if ($orderDB->connect_error) {
$actorDB->close();
payLog(true, '订单数据库连接失败: '.$orderDB->connect_error);
}
// test
//payLog(false, 'fee insert success 1');
// 根据角色ID获取帐号ID
$actorRes = $actorDB->query("SELECT accountid, actorname FROM `actors` WHERE actorid = $roleId LIMIT 1");
$actor = $actorRes->fetch_array(MYSQLI_ASSOC);
$actorRes->free();
if(empty($actor)) {
$orderDB->close();
$actorDB->close();
payLog(true, '获取accountid失败');
}
$accountId = $actor['accountid'];
$roleName = $actor['actorname'];
// test
//payLog(false, 'fee insert success 2');
// 连接帐号数据库
$accountDB = new mysqli($_CONFIG_DB['db_host'], $_CONFIG_DB['db_user'], $_CONFIG_DB['db_password'], 'mir_account', $_CONFIG_DB['db_port']);
if ($accountDB->connect_error) {
$orderDB->close();
$actorDB->close();
payLog(true, '帐号数据库连接失败: '.$accountDB->connect_error);
}
// test
//payLog(false, 'fee insert success 3');
// 根据帐号ID获取帐号
$accountRes = $accountDB->query("SELECT account FROM `globaluser` WHERE userid = $accountId LIMIT 1");
$accountData = $accountRes->fetch_array(MYSQLI_ASSOC);
$accountRes->free();
if(empty($accountData)) {
$orderDB->close();
$actorDB->close();
$accountDB->close();
payLog(true, '获取account失败');
}
$account = $accountData['account'];
// test
//payLog(false, 'fee insert success 4');
// 创建订单记录
$orderSQL = "INSERT INTO `order` (`account`, `server_id`, `role_id`, `role_name`, `product`, `money`, `time`) VALUES ('$account', '$sid', '$roleId', '$roleName', '{$wupin["$money"]}', '$money', '$time')";
if (FALSE === $orderDB->query($orderSQL)) {
payLog(false, 'order create fail'.PHP_EOL.$orderSQL.PHP_EOL.'sql error: '.$orderDB->error);
}
// test
//payLog(false, 'fee insert success 5');
$actorDB->close();
$orderDB->close();
$accountDB->close();
exit('success');
} else {
$actorDB->close();
payLog(false, 'fee insert fail'.PHP_EOL.$feeSQL.PHP_EOL.'sql error: '.$actorDB->error);
exit('Error: '.$feeSQL.'<br>'.$actorDB->error);
}