feat(应用审核): 添加开发者邮箱字段并实现审核结果邮件通知

- 在apps表中添加developer_email字段用于存储开发者邮箱
- 修改upload_app.php以获取并存储开发者邮箱
- 在review_apps.php中实现审核结果邮件通知功能
- 为PHPMailer添加UTF-8字符集设置确保邮件内容正确显示
This commit is contained in:
2025-07-08 20:01:30 +08:00
parent 9efa8fff7c
commit 10ca4b517b
4 changed files with 77 additions and 5 deletions

View File

@@ -1,5 +1,8 @@
<?php
require_once '../config.php';
require_once '../vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
session_start();
// 检查管理员登录状态
@@ -34,7 +37,63 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['review_action'])) {
} else {
$stmt->bind_param("ssi", $status, $rejectionReason, $appId);
if ($stmt->execute()) {
// 获取应用信息和开发者邮箱
$getAppStmt = $conn->prepare("SELECT name, developer_email FROM apps WHERE id = ?");
$getAppStmt->bind_param("i", $appId);
$getAppStmt->execute();
$appResult = $getAppStmt->get_result();
$appInfo = $appResult->fetch_assoc();
$getAppStmt->close();
$success = '应用审核已更新';
$appName = $appInfo['name'] ?? '未知应用';
$devEmail = $appInfo['developer_email'] ?? '';
// 发送邮件通知
if (!empty($devEmail)) {
$mail = new PHPMailer(true);
try {
// 服务器配置
$mail->isSMTP();
$mail->Host = SMTP_HOST;
$mail->Port = SMTP_PORT;
$mail->SMTPSecure = SMTP_ENCRYPTION;
$mail->SMTPAuth = true;
$mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD;
$mail->CharSet = 'UTF-8';
$mail->isHTML(true);
$mail->setFrom(SMTP_FROM_EMAIL, SMTP_FROM_NAME);
$mail->addAddress($devEmail);
// 邮件内容
if ($status === 'approved') {
$mail->Subject = '应用审核通过通知';
$mail->Body = "<div style='font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 8px;'>
<h2 style='color: #2c3e50;'>应用审核通过通知</h2>
<p>您好,</p>
<p>您的应用 <strong>{$appName}</strong> 已成功通过审核!</p>
<p>现在可以在应用商店中查看您的应用。</p>
<p style='margin-top: 20px; color: #666;'>此致<br>应用商店团队</p>
</div>";
} else {
$mail->Subject = '应用审核未通过通知';
$mail->Body = "<div style='font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 8px;'>
<h2 style='color: #e74c3c;'>应用审核未通过通知</h2>
<p>您好,</p>
<p>您的应用 <strong>{$appName}</strong> 未通过审核。</p>
<p>原因:<br>{$rejectionReason}</p>
<p style='margin-top: 20px; color: #666;'>此致<br>应用商店团队</p>
</div>";
}
$mail->send();
$success .= ',邮件通知已发送';
} catch (Exception $e) {
log_error("邮件发送失败: {$mail->ErrorInfo}", __FILE__, __LINE__);
$error = "审核状态已更新,但邮件发送失败: {$mail->ErrorInfo}";
}
}
} else {
$error = '更新审核状态失败: ' . $conn->error;
}

View File

@@ -15,7 +15,8 @@ CREATE TABLE IF NOT EXISTS apps (
version VARCHAR(20) NOT NULL,
changelog TEXT NOT NULL,
file_path VARCHAR(255) NOT NULL,
status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending'
status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending',
developer_email VARCHAR(255) NOT NULL
);
-- 确保状态列存在(用于现有数据库)

View File

@@ -147,6 +147,7 @@ log_error('OpenSSL扩展状态: ' . (extension_loaded('openssl') ? '已启用' :
$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->CharSet = 'UTF-8';
$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
$mail->addAddress($email, $username);

View File

@@ -159,10 +159,21 @@ if (!($conn instanceof mysqli)) {
throw new Exception('缺少必要的上传参数');
}
// 获取开发者邮箱
$userStmt = $conn->prepare('SELECT email FROM developers WHERE id = ?');
$userStmt->bind_param('i', $developerId);
$userStmt->execute();
$userResult = $userStmt->get_result();
$user = $userResult->fetch_assoc();
$developerEmail = $user['email'] ?? '';
$userStmt->close();
if (empty($developerEmail)) {
throw new Exception('无法获取开发者邮箱信息');
}
// 插入应用基本信息
$filePath = ''; // 初始化file_path为空字符串以满足数据库要求
// 添加created_at字段并设置为当前时间戳
$stmt = $conn->prepare('INSERT INTO apps (name, description, developer_id, platforms, status, age_rating, age_rating_description, version, changelog, file_path, created_at) VALUES (?, ?, ?, ?, \'pending\', ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)');
$stmt = $conn->prepare('INSERT INTO apps (name, description, platforms, status, age_rating, age_rating_description, version, changelog, file_path, developer_email, created_at) VALUES (?, ?, ?, \'pending\', ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)');
if (!$stmt) {
throw new Exception('应用基本信息查询准备失败: ' . $conn->error);
}
@@ -178,7 +189,7 @@ 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, $appRelativePath);
$stmt->bind_param('sssssssss', $appName, $appDescription, $platforms_json, $ageRating, $ageRatingDescription, $version, $changelog, $appRelativePath, $developerEmail);
if (!$stmt->execute()) {
throw new Exception('应用基本信息查询执行失败: ' . $stmt->error);
}