init
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
require_once 'includes/db.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
try {
|
||||
if ($id) {
|
||||
// 按 ID 下载指定版本
|
||||
$stmt = $db->prepare("SELECT * FROM apps WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$app = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($app && file_exists('data/apps/' . $app['filename'])) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'file' => 'data/apps/' . rawurlencode($app['filename']),
|
||||
'filename' => $app['original_name'],
|
||||
'version' => $app['version'],
|
||||
'date' => date('Y-m-d H:i:s', strtotime($app['upload_time']))
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'APK 文件不存在'
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
// 兼容旧版:返回最新版本
|
||||
$stmt = $db->query("SELECT * FROM apps ORDER BY upload_time DESC LIMIT 1");
|
||||
$app = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($app && file_exists('data/apps/' . $app['filename'])) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'file' => 'data/apps/' . rawurlencode($app['filename']),
|
||||
'filename' => $app['original_name'],
|
||||
'version' => $app['version'],
|
||||
'date' => date('Y-m-d H:i:s', strtotime($app['upload_time']))
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '未找到 APK 文件'
|
||||
]);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '查询失败: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user