From 10ca4b517bf5084626aec1cfedc021332f91696f Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Tue, 8 Jul 2025 20:01:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BA=94=E7=94=A8=E5=AE=A1=E6=A0=B8):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=80=E5=8F=91=E8=80=85=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=B9=B6=E5=AE=9E=E7=8E=B0=E5=AE=A1=E6=A0=B8?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=82=AE=E4=BB=B6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在apps表中添加developer_email字段用于存储开发者邮箱 - 修改upload_app.php以获取并存储开发者邮箱 - 在review_apps.php中实现审核结果邮件通知功能 - 为PHPMailer添加UTF-8字符集设置确保邮件内容正确显示 --- admin/review_apps.php | 59 ++++++++++++++++++++++++++++++++++++++++ app_store.sql | 3 +- developer/register.php | 1 + developer/upload_app.php | 19 ++++++++++--- 4 files changed, 77 insertions(+), 5 deletions(-) diff --git a/admin/review_apps.php b/admin/review_apps.php index 7c7c101..30b6112 100644 --- a/admin/review_apps.php +++ b/admin/review_apps.php @@ -1,5 +1,8 @@ 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 = "
+

应用审核通过通知

+

您好,

+

您的应用 {$appName} 已成功通过审核!

+

现在可以在应用商店中查看您的应用。

+

此致
应用商店团队

+
"; + } else { + $mail->Subject = '应用审核未通过通知'; + $mail->Body = "
+

应用审核未通过通知

+

您好,

+

您的应用 {$appName} 未通过审核。

+

原因:
{$rejectionReason}

+

此致
应用商店团队

+
"; + } + + $mail->send(); + $success .= ',邮件通知已发送'; + } catch (Exception $e) { + log_error("邮件发送失败: {$mail->ErrorInfo}", __FILE__, __LINE__); + $error = "审核状态已更新,但邮件发送失败: {$mail->ErrorInfo}"; + } + } } else { $error = '更新审核状态失败: ' . $conn->error; } diff --git a/app_store.sql b/app_store.sql index 9cf163c..d210802 100644 --- a/app_store.sql +++ b/app_store.sql @@ -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 ); -- 确保状态列存在(用于现有数据库) diff --git a/developer/register.php b/developer/register.php index eb2f68d..235e84c 100644 --- a/developer/register.php +++ b/developer/register.php @@ -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); diff --git a/developer/upload_app.php b/developer/upload_app.php index 94fa17d..c4cea7a 100644 --- a/developer/upload_app.php +++ b/developer/upload_app.php @@ -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); }