init
This commit is contained in:
		
							
								
								
									
										137
									
								
								pay/notify_url.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								pay/notify_url.php
									
									
									
									
									
										Normal 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); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user