feat(应用管理): 实现应用审核状态和日志系统
- 在app_store.sql中添加应用审核状态字段 - 重构日志系统到单独文件并实现日志分级 - 改进开发者注册和上传应用的错误处理和日志记录 - 为应用详情页添加评价分页加载功能 - 更新SMTP配置并增强邮件发送调试能力
This commit is contained in:
@@ -1,8 +1,25 @@
|
||||
<?php
|
||||
// Define SMTP constants if not already defined
|
||||
if (!defined('SMTP_USERNAME')) define('SMTP_USERNAME', '');
|
||||
if (!defined('SMTP_ENCRYPTION')) define('SMTP_ENCRYPTION', 'tls');
|
||||
if (!defined('SMTP_FROM_EMAIL')) define('SMTP_FROM_EMAIL', 'noreply@example.com');
|
||||
// 引入配置文件
|
||||
// 检查配置文件是否存在并加载
|
||||
$configFile = 'd:\app2\config.php';
|
||||
if (!file_exists($configFile)) {
|
||||
die('配置文件缺失: ' . $configFile . ',无法继续执行');
|
||||
}
|
||||
require_once $configFile;
|
||||
|
||||
// 引入日志工具
|
||||
require_once 'd:\app2\includes\logger.php';
|
||||
|
||||
// 配置文件加载后日志记录和常量检查
|
||||
log_error('配置文件已成功加载: ' . $configFile);
|
||||
// 验证关键常量是否定义
|
||||
log_error('配置加载后常量检查 - SMTP_HOST: ' . (defined('SMTP_HOST') ? SMTP_HOST : '未定义'));
|
||||
log_error('配置加载后常量检查 - SMTP_USERNAME: ' . (defined('SMTP_USERNAME') ? SMTP_USERNAME : '未定义'));
|
||||
log_error('配置加载后常量检查 - SMTP_PASSWORD: ' . (defined('SMTP_PASSWORD') ? '已设置' : '未定义'));
|
||||
log_error('配置加载后常量检查 - SMTP_PORT: ' . (defined('SMTP_PORT') ? SMTP_PORT : '未定义'));
|
||||
log_error('配置文件加载后 - SMTP_USERNAME: ' . (defined('SMTP_USERNAME') ? SMTP_USERNAME : '未定义') . ', SMTP_PORT: ' . (defined('SMTP_PORT') ? SMTP_PORT : '未定义'));
|
||||
|
||||
|
||||
|
||||
|
||||
// 引入PHPMailer命名空间
|
||||
@@ -10,9 +27,6 @@ use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
// 引入配置文件
|
||||
require_once '../config.php';
|
||||
|
||||
// 引入Composer自动加载器
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
@@ -78,10 +92,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// 生成验证令牌
|
||||
$verificationToken = bin2hex(random_bytes(32));
|
||||
$insertStmt = $conn->prepare('INSERT INTO developers (username, email, password, verification_token) VALUES (?, ?, ?, ?)');
|
||||
if (!$insertStmt) {
|
||||
log_error('插入准备失败: ' . $conn->error, __FILE__, __LINE__);
|
||||
$error = '系统错误,请稍后再试';
|
||||
} else {
|
||||
$insertStmt->bind_param('ssss', $username, $email, $hashedPassword, $verificationToken);
|
||||
if (!$insertStmt->execute()) {
|
||||
log_error('插入执行失败: ' . $insertStmt->error, __FILE__, __LINE__);
|
||||
$error = '系统错误,请稍后再试';
|
||||
} else {
|
||||
// 生成验证链接
|
||||
$verificationLink = 'https://' . $_SERVER['HTTP_HOST'] . '/developer/verify_email.php?token=' . urlencode($verificationToken);
|
||||
|
||||
@@ -92,6 +107,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$templateContent = str_replace('{username}', htmlspecialchars($username), $templateContent);
|
||||
$templateContent = str_replace('{verification_link}', $verificationLink, $templateContent);
|
||||
|
||||
// 调试日志测试
|
||||
$testLogDir = 'd:\\app2\\logs';
|
||||
$testLogFile = $testLogDir . '\\test.log';
|
||||
if (!is_dir($testLogDir)) {
|
||||
mkdir($testLogDir, 0755, true);
|
||||
}
|
||||
file_put_contents($testLogFile, date('[Y-m-d H:i:s] ') . '邮件发送代码开始执行' . PHP_EOL, FILE_APPEND);
|
||||
|
||||
// 添加SMTP配置调试日志
|
||||
log_error('SMTP配置参数 - HOST: ' . (defined('SMTP_HOST') ? SMTP_HOST : '未定义') . ', PORT: ' . (defined('SMTP_PORT') ? SMTP_PORT : '未定义') . ', USERNAME: ' . (defined('SMTP_USERNAME') ? SMTP_USERNAME : '未定义') . ', ENCRYPTION: ' . (defined('SMTP_ENCRYPTION') ? SMTP_ENCRYPTION : '未定义'), __FILE__, __LINE__);
|
||||
log_error('开始执行邮件发送流程', __FILE__, __LINE__);
|
||||
|
||||
// 配置SMTP邮件发送
|
||||
require_once '../vendor/phpmailer/phpmailer/src/PHPMailer.php';
|
||||
require_once '../vendor/phpmailer/phpmailer/src/SMTP.php';
|
||||
@@ -101,11 +128,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$mail = new \PHPMailer\PHPMailer\PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->SMTPDebug = 4;
|
||||
// 输出当前SMTP配置参数用于调试
|
||||
log_error('SMTP配置参数: HOST=' . SMTP_HOST . ', PORT=' . SMTP_PORT . ', USERNAME=' . SMTP_USERNAME . ', ENCRYPTION=' . SMTP_ENCRYPTION);
|
||||
// 检查openssl扩展是否启用
|
||||
log_error('OpenSSL扩展状态: ' . (extension_loaded('openssl') ? '已启用' : '未启用')); // 启用详细调试
|
||||
$mail->Debugoutput = function($str, $level) {
|
||||
$logDir = 'd:\\app2\\logs';
|
||||
if (!is_dir($logDir)) {
|
||||
mkdir($logDir, 0755, true);
|
||||
}
|
||||
file_put_contents($logDir . '\\smtp_debug.log', date('[Y-m-d H:i:s] ') . $str . PHP_EOL, FILE_APPEND);
|
||||
};
|
||||
$mail->Host = defined('SMTP_HOST') ? SMTP_HOST : 'smtp.example.com';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = defined('SMTP_USERNAME') ? SMTP_USERNAME : ''; // Ensure SMTP_USERNAME is defined in config.php
|
||||
$mail->Password = defined('SMTP_PASSWORD') ? SMTP_PASSWORD : '';
|
||||
$mail->SMTPSecure = defined('SMTP_ENCRYPTION') ? SMTP_ENCRYPTION : 'tls'; // Ensure SMTP_ENCRYPTION is defined in config.php
|
||||
$mail->AuthType = 'PLAIN'; // 尝试使用PLAIN认证方式
|
||||
$mail->Port = defined('SMTP_PORT') ? SMTP_PORT : 587;
|
||||
|
||||
$mail->setFrom(defined('SMTP_FROM_EMAIL') ? SMTP_FROM_EMAIL : 'noreply@example.com', defined('SMTP_FROM_NAME') ? SMTP_FROM_NAME : 'App Store'); // Ensure SMTP_FROM_EMAIL is defined in config.php
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
<?php
|
||||
require_once('../includes/logger.php');
|
||||
|
||||
// 引入配置文件
|
||||
require_once '../config.php';
|
||||
|
||||
session_start();
|
||||
|
||||
// 检查开发者是否已登录
|
||||
if (!isset($_SESSION['developer_id'])) {
|
||||
if (!isset($_SESSION['developer_id']) || !is_numeric($_SESSION['developer_id'])) {
|
||||
log_error('开发者会话ID不存在或无效', __FILE__, __LINE__);
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$developerId = $_SESSION['developer_id'];
|
||||
$developerId = (int)$_SESSION['developer_id'];
|
||||
log_info("上传应用的开发者ID: $developerId", __FILE__, __LINE__);
|
||||
log_info("上传应用的开发者ID: $developerId", __FILE__, __LINE__);
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
@@ -26,7 +31,10 @@ if (!$stmt) {
|
||||
$developer = $result->fetch_assoc();
|
||||
$stmt->close();
|
||||
|
||||
if (!$developer || !$developer['is_verified']) {
|
||||
log_info("开发者验证状态: " . ($developer ? ($developer['is_verified'] ? "已验证" : "未验证") : "开发者不存在"), __FILE__, __LINE__);
|
||||
if (!$developer) {
|
||||
$error = '开发者账号不存在,请重新登录。';
|
||||
} elseif (!$developer['is_verified']) {
|
||||
$error = '您的邮箱尚未验证,请先验证邮箱后再上传应用。';
|
||||
}
|
||||
}
|
||||
@@ -89,6 +97,29 @@ if (!($conn instanceof mysqli)) {
|
||||
$error = '应用文件上传失败';
|
||||
}
|
||||
} else {
|
||||
// 验证标签ID是否存在
|
||||
if (!empty($tags)) {
|
||||
$tagIds = implode(',', array_map('intval', $tags));
|
||||
$tagCheckStmt = $conn->prepare("SELECT id FROM tags WHERE id IN ($tagIds)");
|
||||
if (!$tagCheckStmt) {
|
||||
log_error('标签验证查询准备失败: ' . $conn->error, __FILE__, __LINE__);
|
||||
$error = '系统错误,请稍后再试';
|
||||
} else {
|
||||
$tagCheckStmt->execute();
|
||||
$tagResult = $tagCheckStmt->get_result();
|
||||
$validTagIds = [];
|
||||
while ($tag = $tagResult->fetch_assoc()) {
|
||||
$validTagIds[] = $tag['id'];
|
||||
}
|
||||
$tagCheckStmt->close();
|
||||
|
||||
$invalidTags = array_diff($tags, $validTagIds);
|
||||
if (!empty($invalidTags)) {
|
||||
log_error('无效的标签ID: ' . implode(',', $invalidTags), __FILE__, __LINE__);
|
||||
$error = '选择了无效的标签,请刷新页面重试';
|
||||
}
|
||||
}
|
||||
}
|
||||
$error = '应用文件上传错误: ' . ($appFile ? $appFile['error'] : '未找到文件');
|
||||
}
|
||||
|
||||
@@ -111,7 +142,7 @@ if (!($conn instanceof mysqli)) {
|
||||
mkdir($target_dir, 0755, true);
|
||||
}
|
||||
if (move_uploaded_file($tmpName, $imagePath)) {
|
||||
$imagePaths[] = $imagePath;
|
||||
$imagePaths[] = $imageRelativePath;
|
||||
} else {
|
||||
log_error('图片文件移动失败: ' . $images['name'][$key], __FILE__, __LINE__);
|
||||
}
|
||||
@@ -147,13 +178,15 @@ if (!($conn instanceof mysqli)) {
|
||||
// 移除多余的$status参数,匹配SQL中9个占位符
|
||||
// 修正age_rating_description类型为字符串,并确保9个参数与占位符匹配
|
||||
// 修复变量名错误:使用已验证的$appFilePath替换未定义的$file_path
|
||||
$stmt->bind_param('ssissssss', $appName, $appDescription, $developerId, $platforms_json, $ageRating, $ageRatingDescription, $version, $changelog, $filePath);
|
||||
$stmt->bind_param('ssissssss', $appName, $appDescription, $developerId, $platforms_json, $ageRating, $ageRatingDescription, $version, $changelog, $appRelativePath);
|
||||
if (!$stmt->execute()) {
|
||||
throw new Exception('应用基本信息查询执行失败: ' . $stmt->error);
|
||||
}
|
||||
$appId = $stmt->insert_id;
|
||||
log_info("应用已插入数据库: ID=$appId, 状态=pending", __FILE__, __LINE__);
|
||||
$stmt->close();
|
||||
|
||||
log_info("开始处理应用关联数据: ID=$appId", __FILE__, __LINE__);
|
||||
// 插入应用标签关联
|
||||
foreach ($tags as $tagId) {
|
||||
$tagStmt = $conn->prepare('INSERT INTO app_tags (app_id, tag_id) VALUES (?, ?)');
|
||||
@@ -168,7 +201,7 @@ if (!($conn instanceof mysqli)) {
|
||||
}
|
||||
|
||||
// 插入应用图片
|
||||
foreach ($imagePaths as $imagePath) {
|
||||
foreach ($imagePaths as $imageRelativePath) {
|
||||
$imageStmt = $conn->prepare('INSERT INTO app_images (app_id, image_path) VALUES (?, ?)');
|
||||
if (!$imageStmt) {
|
||||
throw new Exception('图片关联查询准备失败: ' . $conn->error);
|
||||
@@ -191,13 +224,15 @@ if (!($conn instanceof mysqli)) {
|
||||
}
|
||||
$versionStmt->close();
|
||||
|
||||
log_info("所有关联数据处理完成,准备提交事务: ID=$appId", __FILE__, __LINE__);
|
||||
// 提交事务
|
||||
$conn->commit();
|
||||
log_info("应用上传成功: ID=$appId, 状态=pending", __FILE__, __LINE__);
|
||||
$success = '应用上传成功,请等待管理员审核';
|
||||
} catch (Exception $e) {
|
||||
// 回滚事务
|
||||
$conn->rollback();
|
||||
log_error('应用上传事务失败: ' . $e->getMessage(), __FILE__, __LINE__);
|
||||
log_error('应用上传事务失败(ID=$appId): ' . $e->getMessage(), __FILE__, __LINE__);
|
||||
$error = '上传应用时发生错误,请稍后再试';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user