fix: 修复验证链接协议为http并添加API根路径处理
修复开发者注册邮件验证链接错误使用https协议的问题,改为使用http协议 在API入口添加根路径处理,返回可用端点信息和示例 添加数据库查询错误处理,返回500状态码和错误信息
This commit is contained in:
23
api.php
23
api.php
@@ -4,6 +4,24 @@ header('Content-Type: application/json');
|
||||
|
||||
$requestMethod = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
// API根路径处理 - 返回可用端点信息
|
||||
if (!isset($_GET['action'])) {
|
||||
http_response_code(200);
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'App Store API',
|
||||
'version' => '1.0',
|
||||
'endpoints' => [
|
||||
'/api?action=list' => '获取应用列表,支持search、platform、age_rating、tag、page、limit参数',
|
||||
'/api?action=app&id=1' => '获取指定ID的应用详情',
|
||||
'/api?action=favorite' => '收藏应用(POST方法,需app_id和user_id参数)'
|
||||
],
|
||||
'example' => 'GET /api?action=list&platform=windows&limit=20'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
// 支持查询参数路由模式(不依赖URL重写)
|
||||
if (isset($_GET['action'])) {
|
||||
$action = $_GET['action'];
|
||||
@@ -85,6 +103,11 @@ if (isset($_GET['action'])) {
|
||||
|
||||
// 执行主查询
|
||||
$stmt = $conn->prepare($sql);
|
||||
if (!$stmt) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Database error: ' . $conn->error]);
|
||||
exit;
|
||||
}
|
||||
call_user_func_array([$stmt, 'bind_param'], array_merge([$paramTypes], $stmtParams));
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
@@ -98,7 +98,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$error = '系统错误,请稍后再试';
|
||||
} else {
|
||||
// 生成验证链接
|
||||
$verificationLink = 'https://' . $_SERVER['HTTP_HOST'] . '/developer/verify_email.php?token=' . urlencode($verificationToken);
|
||||
$verificationLink = 'http://' . $_SERVER['HTTP_HOST'] . '/developer/verify_email.php?token=' . urlencode($verificationToken);
|
||||
|
||||
// 加载邮件模板
|
||||
$templatePath = __DIR__ . '/../mail/verification_template.php';
|
||||
|
||||
Reference in New Issue
Block a user