diff --git a/api.php b/api.php index c898333..67e6d76 100644 --- a/api.php +++ b/api.php @@ -9,6 +9,7 @@ * - /api.php?t=gettagapp&id={tagid} - 获取某标签里的APP列表 * - /api.php?t=getdeveloperapp&id={developerid} - 获取某开发者的APP列表 * - /api.php?t=getdeveloperinfo&id={developerid} - 获取开发者信息 + * - /api.php?t=getalldevelopers - 获取所有开发者列表 * - /api.php?t=getacc - 获取所有公告 * - /api.php?t=getcount - 获取计数信息 * - /api.php?t=getappversions&id={appid} - 获取某个应用的版本列表 @@ -71,6 +72,9 @@ switch ($apiType) { case 'getappversions': getAppVersions(); break; + case 'getalldevelopers': + getAllDevelopers(); + break; default: showApiEndpoints(); break; @@ -115,6 +119,7 @@ function showApiEndpoints() { '/api.php?t=gettagapp&id={tagid}' => '获取某标签里的APP列表', '/api.php?t=getdeveloperapp&id={developerid}' => '获取某开发者的APP列表', '/api.php?t=getdeveloperinfo&id={developerid}' => '获取开发者信息', + '/api.php?t=getalldevelopers' => '获取所有开发者列表', '/api.php?t=getacc' => '获取所有公告', '/api.php?t=getcount' => '获取计数信息(如所有APP的数量、开发者的数量等)', '/api.php?t=getappversions&id={appid}' => '获取某个应用的版本列表' @@ -544,6 +549,68 @@ function getCountInfo() { sendSuccessResponse($counts); } +/** + * 获取所有开发者列表 + */ +function getAllDevelopers() { + global $conn; + + // 获取分页参数 + $page = isset($_GET['page']) ? max(1, intval($_GET['page'])) : 1; + $limit = isset($_GET['limit']) ? min(100, max(1, intval($_GET['limit']))) : 20; + $offset = ($page - 1) * $limit; + + // 获取总数量 + $countSql = "SELECT COUNT(*) as total FROM developers"; + $countResult = $conn->query($countSql); + $total = $countResult->fetch_assoc()['total'] ?? 0; + $totalPages = ceil($total / $limit); + + // 获取开发者列表 + $sql = "SELECT id, username, email, created_at FROM developers ORDER BY created_at DESC LIMIT ?, ?"; + $stmt = $conn->prepare($sql); + $stmt->bind_param("ii", $offset, $limit); + $stmt->execute(); + $result = $stmt->get_result(); + + $developers = []; + while ($row = $result->fetch_assoc()) { + // 获取每个开发者的应用数量 + $appCountSql = "SELECT COUNT(*) as count FROM apps WHERE developer_id = ? AND status = 'approved' AND is_approved = 1"; + $appCountStmt = $conn->prepare($appCountSql); + $appCountStmt->bind_param("i", $row['id']); + $appCountStmt->execute(); + $appCountResult = $appCountStmt->get_result(); + $appCount = $appCountResult->fetch_assoc()['count'] ?? 0; + $row['app_count'] = $appCount; + + // 获取每个开发者的总下载量 + $downloadCountSql = "SELECT SUM(download_count) as count FROM app_versions + JOIN apps ON app_versions.app_id = apps.id + WHERE apps.developer_id = ?"; + $downloadCountStmt = $conn->prepare($downloadCountSql); + $downloadCountStmt->bind_param("i", $row['id']); + $downloadCountStmt->execute(); + $downloadCountResult = $downloadCountStmt->get_result(); + $downloadCount = $downloadCountResult->fetch_assoc()['count'] ?? 0; + $row['total_downloads'] = $downloadCount; + + $developers[] = $row; + } + + $response = [ + 'developers' => $developers, + 'pagination' => [ + 'total' => $total, + 'page' => $page, + 'limit' => $limit, + 'totalPages' => $totalPages + ] + ]; + + sendSuccessResponse($response); +} + /** * 获取指定应用的版本列表 */ diff --git a/apidocs/openapi.json b/apidocs/openapi.json new file mode 100644 index 0000000..6b268c1 --- /dev/null +++ b/apidocs/openapi.json @@ -0,0 +1,1091 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "App Store API", + "description": "App Store API v2.0 - 提供应用商店的各种数据接口", + "version": "2.0.0" + }, + "servers": [ + { + "url": "http://localhost/APP Store", + "description": "本地开发服务器" + } + ], + "paths": { + "/api.php": { + "get": { + "summary": "API端点总览", + "description": "显示所有可用的API端点信息", + "parameters": [ + { + "name": "t", + "in": "query", + "description": "API类型参数,留空则显示所有端点", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "成功获取端点信息", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "message": { + "type": "string", + "example": "App Store API v2.0" + }, + "endpoints": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "example": { + "type": "string", + "example": "/api.php?t=getallapps" + } + } + } + } + } + } + } + } + }, + "/api.php?t=getallapps": { + "get": { + "summary": "获取所有应用列表", + "description": "获取所有已批准的应用列表,支持分页", + "parameters": [ + { + "name": "page", + "in": "query", + "description": "页码", + "required": false, + "schema": { + "type": "integer", + "default": 1 + } + }, + { + "name": "limit", + "in": "query", + "description": "每页数量", + "required": false, + "schema": { + "type": "integer", + "default": 20, + "maximum": 100 + } + } + ], + "responses": { + "200": { + "description": "成功获取应用列表", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "object", + "properties": { + "apps": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "age_rating": { + "type": "string" + }, + "version": { + "type": "string" + }, + "avg_rating": { + "type": "number" + }, + "total_downloads": { + "type": "integer" + } + } + } + }, + "pagination": { + "type": "object", + "properties": { + "total": { + "type": "integer" + }, + "page": { + "type": "integer" + }, + "limit": { + "type": "integer" + }, + "totalPages": { + "type": "integer" + } + } + } + } + } + } + } + } + } + } + } + } + }, + "/api.php?t=getappinfo": { + "get": { + "summary": "获取应用详细信息", + "description": "获取指定应用的详细信息,包括版本、图片和标签", + "parameters": [ + { + "name": "id", + "in": "query", + "description": "应用ID", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "成功获取应用信息", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "age_rating": { + "type": "string" + }, + "version": { + "type": "string" + }, + "avg_rating": { + "type": "number" + }, + "total_downloads": { + "type": "integer" + }, + "platforms": { + "type": "array" + }, + "versions": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "version": { + "type": "string" + }, + "changelog": { + "type": "string" + }, + "file_path": { + "type": "string" + }, + "download_count": { + "type": "integer" + }, + "created_at": { + "type": "string" + } + } + } + }, + "images": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "image_path": { + "type": "string" + } + } + } + }, + "tags": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + } + } + } + } + } + } + } + } + }, + "400": { + "description": "无效的应用ID", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "请提供有效的应用ID" + } + } + } + } + } + }, + "404": { + "description": "未找到应用", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "未找到该应用" + } + } + } + } + } + } + } + } + }, + "/api.php?t=getalltags": { + "get": { + "summary": "获取所有标签", + "description": "获取所有可用的应用标签", + "responses": { + "200": { + "description": "成功获取标签列表", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + } + } + } + } + } + } + } + } + } + }, + "/api.php?t=gettagapp": { + "get": { + "summary": "获取标签下的应用", + "description": "获取指定标签下的所有应用列表,支持分页", + "parameters": [ + { + "name": "id", + "in": "query", + "description": "标签ID", + "required": true, + "schema": { + "type": "integer" + } + }, + { + "name": "page", + "in": "query", + "description": "页码", + "required": false, + "schema": { + "type": "integer", + "default": 1 + } + }, + { + "name": "limit", + "in": "query", + "description": "每页数量", + "required": false, + "schema": { + "type": "integer", + "default": 20, + "maximum": 100 + } + } + ], + "responses": { + "200": { + "description": "成功获取标签下的应用列表", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "object", + "properties": { + "tag": { + "type": "object", + "properties": { + "name": { + "type": "string" + } + } + }, + "apps": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "age_rating": { + "type": "string" + }, + "version": { + "type": "string" + }, + "avg_rating": { + "type": "number" + } + } + } + }, + "pagination": { + "type": "object", + "properties": { + "total": { + "type": "integer" + }, + "page": { + "type": "integer" + }, + "limit": { + "type": "integer" + }, + "totalPages": { + "type": "integer" + } + } + } + } + } + } + } + } + } + }, + "400": { + "description": "无效的标签ID", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "请提供有效的标签ID" + } + } + } + } + } + }, + "404": { + "description": "未找到标签", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "未找到该标签" + } + } + } + } + } + } + } + } + }, + "/api.php?t=getdeveloperapp": { + "get": { + "summary": "获取开发者的应用", + "description": "获取指定开发者的所有应用列表,支持分页", + "parameters": [ + { + "name": "id", + "in": "query", + "description": "开发者ID", + "required": true, + "schema": { + "type": "integer" + } + }, + { + "name": "page", + "in": "query", + "description": "页码", + "required": false, + "schema": { + "type": "integer", + "default": 1 + } + }, + { + "name": "limit", + "in": "query", + "description": "每页数量", + "required": false, + "schema": { + "type": "integer", + "default": 20, + "maximum": 100 + } + } + ], + "responses": { + "200": { + "description": "成功获取开发者的应用列表", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "object", + "properties": { + "developer": { + "type": "object", + "properties": { + "username": { + "type": "string" + } + } + }, + "apps": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "age_rating": { + "type": "string" + }, + "version": { + "type": "string" + }, + "created_at": { + "type": "string" + } + } + } + }, + "pagination": { + "type": "object", + "properties": { + "total": { + "type": "integer" + }, + "page": { + "type": "integer" + }, + "limit": { + "type": "integer" + }, + "totalPages": { + "type": "integer" + } + } + } + } + } + } + } + } + } + }, + "400": { + "description": "无效的开发者ID", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "请提供有效的开发者ID" + } + } + } + } + } + }, + "404": { + "description": "未找到开发者", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "未找到该开发者" + } + } + } + } + } + } + } + } + }, + "/api.php?t=getdeveloperinfo": { + "get": { + "summary": "获取开发者信息", + "description": "获取指定开发者的详细信息,包括应用数量和下载量", + "parameters": [ + { + "name": "id", + "in": "query", + "description": "开发者ID", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "成功获取开发者信息", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + }, + "email": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "app_count": { + "type": "integer" + }, + "total_downloads": { + "type": "integer" + } + } + } + } + } + } + } + }, + "400": { + "description": "无效的开发者ID", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "请提供有效的开发者ID" + } + } + } + } + } + }, + "404": { + "description": "未找到开发者", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "未找到该开发者" + } + } + } + } + } + } + } + } + }, + "/api.php?t=getalldevelopers": { + "get": { + "summary": "获取所有开发者列表", + "description": "获取所有开发者的列表,支持分页", + "parameters": [ + { + "name": "page", + "in": "query", + "description": "页码", + "required": false, + "schema": { + "type": "integer", + "default": 1 + } + }, + { + "name": "limit", + "in": "query", + "description": "每页数量", + "required": false, + "schema": { + "type": "integer", + "default": 20, + "maximum": 100 + } + } + ], + "responses": { + "200": { + "description": "成功获取开发者列表", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "object", + "properties": { + "developers": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + }, + "email": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "app_count": { + "type": "integer" + }, + "total_downloads": { + "type": "integer" + } + } + } + }, + "pagination": { + "type": "object", + "properties": { + "total": { + "type": "integer" + }, + "page": { + "type": "integer" + }, + "limit": { + "type": "integer" + }, + "totalPages": { + "type": "integer" + } + } + } + } + } + } + } + } + } + } + } + } + }, + "/api.php?t=getacc": { + "get": { + "summary": "获取所有公告", + "description": "获取所有系统公告", + "responses": { + "200": { + "description": "成功获取公告列表", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "title": { + "type": "string" + }, + "content": { + "type": "string" + }, + "created_at": { + "type": "string" + } + } + } + } + } + } + } + } + } + } + } + }, + "/api.php?t=getcount": { + "get": { + "summary": "获取计数信息", + "description": "获取应用商店的各类统计信息", + "responses": { + "200": { + "description": "成功获取计数信息", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "object", + "properties": { + "total_apps": { + "type": "integer" + }, + "total_developers": { + "type": "integer" + }, + "total_tags": { + "type": "integer" + }, + "total_announcements": { + "type": "integer" + }, + "total_downloads": { + "type": "integer" + } + } + } + } + } + } + } + } + } + } + }, + "/api.php?t=getappversions": { + "get": { + "summary": "获取应用版本列表", + "description": "获取指定应用的所有版本列表,支持分页", + "parameters": [ + { + "name": "id", + "in": "query", + "description": "应用ID", + "required": true, + "schema": { + "type": "integer" + } + }, + { + "name": "page", + "in": "query", + "description": "页码", + "required": false, + "schema": { + "type": "integer", + "default": 1 + } + }, + { + "name": "limit", + "in": "query", + "description": "每页数量", + "required": false, + "schema": { + "type": "integer", + "default": 20, + "maximum": 100 + } + } + ], + "responses": { + "200": { + "description": "成功获取版本列表", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "success" + }, + "data": { + "type": "object", + "properties": { + "app_id": { + "type": "integer" + }, + "versions": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "version": { + "type": "string" + }, + "changelog": { + "type": "string" + }, + "file_path": { + "type": "string" + }, + "download_count": { + "type": "integer" + }, + "created_at": { + "type": "string" + } + } + } + }, + "pagination": { + "type": "object", + "properties": { + "total": { + "type": "integer" + }, + "page": { + "type": "integer" + }, + "limit": { + "type": "integer" + }, + "totalPages": { + "type": "integer" + } + } + } + } + } + } + } + } + } + }, + "400": { + "description": "无效的应用ID", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "请提供有效的应用ID" + } + } + } + } + } + }, + "404": { + "description": "未找到应用", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "error" + }, + "message": { + "type": "string", + "example": "未找到该应用" + } + } + } + } + } + } + } + } + } + } +} \ No newline at end of file