Hypixel Mirror API 是一个智能的 Hypixel API 缓存代理服务,旨在帮助开发者避免直接请求 Hypixel API 时的速率限制问题。
通过本服务,您可以:
数据缓存 3 小时,访问过期缓存时自动从官方 API 刷新,用户完全无感知。
支持多个 Hypixel API 密钥,自动轮换使用,失效密钥自动删除。
详细的请求日志、缓存命中率、密钥使用情况等统计数据。
Web 界面管理缓存和密钥,支持手动清理和维护操作。
| 组件 | 版本要求 | 说明 |
|---|---|---|
| PHP | 7.4+ | 推荐使用 PHP 8.0+ |
| MySQL | 5.7+ | 或 MariaDB 10.2+ |
| Web 服务器 | Nginx 1.25+ 或 Apache 2.4+ | 推荐使用 Nginx |
| PHP 扩展 | PDO, PDO_MySQL, cURL, JSON | 必需扩展 |
git clone https://github.com/weige0831/HypixelAPImirror.git
cd HypixelAPImirror
登录 MySQL 并创建数据库(如果使用现有数据库可跳过):
# 登录 MySQL
mysql -u root -p
# 创建数据库
CREATE DATABASE IF NOT EXISTS api CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
# 退出 MySQL
exit;
导入数据库结构:
mysql -u root -p api < database.sql
复制配置模板并编辑:
cp config.example.php config.php
nano config.php
需要修改的配置项:
database.host - 数据库主机地址database.dbname - 数据库名称(默认:api)database.username - 数据库用户名database.password - 数据库密码admin.username - 管理员用户名admin.password - 管理员密码(请使用强密码)Nginx 配置示例:
server {
listen 80;
server_name api.example.com;
root /path/to/hypixelmirro/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
重启 Nginx:
systemctl restart nginx
访问初始化页面(需要管理员认证):
http://api.example.com/setup.php
或使用命令行:
curl -u admin:password "http://api.example.com/setup.php"
首先,在 Hypixel 开发者面板 获取您的 API 密钥。
然后,使用以下任一方式添加密钥:
curl -u admin:password "http://api.example.com/hypixel-keys.php?add_key=YOUR_HYPIXEL_API_KEY"
curl -u admin:password -X POST \
-H "Content-Type: application/json" \
-d '{"hypixel_key":"YOUR_HYPIXEL_API_KEY"}' \
"http://api.example.com/hypixel-keys.php"
# 查看所有密钥
curl -u admin:password "http://api.example.com/hypixel-keys.php"
获取指定玩家的所有 Hypixel 数据。支持通过 UUID 或玩家名称查询。
GET /index.php?uuid={player_uuid}
GET /index.php?name={player_name}
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
uuid |
string | 二选一 | 玩家的 UUID(32位,无连字符) |
name |
string | 二选一 | 玩家的游戏名称 |
{
"success": true,
"data": {
"player": {
"uuid": "f7c77d999f154a66a87dc4a51ef30d19",
"displayname": "jeb_",
"firstLogin": 1413309026000,
"lastLogin": 1731662015000,
"playername": "jeb_",
"networkExp": 1234567,
"stats": {
"Bedwars": {
"wins_bedwars": 1250,
"kills_bedwars": 8500,
...
},
"SkyWars": {
...
}
},
...
},
"fetch_time": "2025-11-25 10:30:00"
}
}
{
"success": false,
"error": "Either player UUID or name is required"
}
# 通过 UUID 查询
curl "https://api.example.com/index.php?uuid=f7c77d999f154a66a87dc4a51ef30d19"
# 通过玩家名查询
curl "https://api.example.com/index.php?name=Notch"
获取 API 服务的运行统计信息,包括请求数、缓存命中率、密钥使用情况等。
GET /stats.php
{
"success": true,
"data": {
"timestamp": "2025-11-25 10:30:00",
"date": "2025-11-25",
"api_keys": {
"total": 3,
"valid": 3
},
"today_stats": {
"api_requests": 125,
"cache_hits": 450,
"successful_requests": 570,
"failed_requests": 5,
"unique_players": 89,
"total_requests": 575
},
"cache_stats": {
"total_entries": 500,
"valid_entries": 480,
"expired_entries": 20
},
"keys_detail": [
{
"key": "12345678...abcd",
"owner": "admin",
"requests_today": 42,
"total_requests": 1250,
"is_valid": true
}
]
}
}
curl "https://api.example.com/stats.php"
| HTTP 状态码 | 说明 | 可能原因 |
|---|---|---|
| 200 | 成功 | 请求成功处理 |
| 400 | 请求错误 | 缺少必需参数或参数格式错误 |
| 401 | 未授权 | 访问管理功能需要认证 |
| 404 | 未找到 | 玩家不存在或端点不存在 |
| 429 | 请求过多 | 触发速率限制 |
| 500 | 服务器错误 | 内部错误,请联系管理员 |
config.php 中配置的管理员账户。
用于首次部署或重新初始化系统。检查系统要求、创建数据库表、验证配置。
GET /setup.php
{
"success": true,
"setup_time": "2025-11-25 10:30:00",
"steps": [
{
"step": "system_check",
"status": "success",
"message": "System requirements checked"
},
{
"step": "table_check",
"status": "success",
"message": "All tables exist"
},
{
"step": "api_keys_check",
"status": "success",
"message": "Found 3 valid API keys"
}
],
"message": "✅ Setup completed successfully!",
"next_steps": [
"1. Add Hypixel API keys via /hypixel-keys.php",
"2. Test the API via /index.php?uuid=player_uuid",
"3. Monitor statistics via /stats.php"
]
}
curl -u admin:password "https://api.example.com/setup.php"
管理 Hypixel API 密钥。查看、添加密钥及其使用统计。
GET /hypixel-keys.php
返回所有 API 密钥的列表及其统计信息。
{
"success": true,
"data": [
{
"key": "12345678-1234-1234-1234-123456789abc",
"created_at": "2025-11-25 10:00:00",
"last_checked": "2025-11-25 12:30:00",
"last_used": "2025-11-25 12:35:00",
"daily_requests": 125,
"total_requests": 5430,
"is_valid": true,
"status_code": 200,
"owner": "admin",
"notes": "主密钥"
}
]
}
curl -u admin:password "https://api.example.com/hypixel-keys.php"
GET /hypixel-keys.php?add_key={your_hypixel_api_key}
curl -u admin:password "https://api.example.com/hypixel-keys.php?add_key=12345678-1234-1234-1234-123456789abc"
{
"success": true,
"message": "Hypixel API key added successfully"
}
POST /hypixel-keys.php
Content-Type: application/json
{
"hypixel_key": "your_hypixel_api_key"
}
curl -u admin:password -X POST \
-H "Content-Type: application/json" \
-d '{"hypixel_key":"12345678-1234-1234-1234-123456789abc"}' \
"https://api.example.com/hypixel-keys.php"
| 字段 | 类型 | 说明 |
|---|---|---|
key |
string | API 密钥(完整显示) |
owner |
string | 密钥所有者/备注(可选) |
notes |
string | 备注信息(可选) |
is_valid |
boolean | 密钥是否有效 |
daily_requests |
integer | 今日请求数 |
total_requests |
integer | 总请求数 |
last_used |
datetime | 最后使用时间 |
status_code |
integer | 最后请求的 HTTP 状态码 |
{
"success": false,
"error": "Invalid Hypixel API key"
}
查看缓存统计信息和手动清理缓存。
GET /cache-stats.php
显示详细的缓存统计信息,包括总条目数、有效条目、过期条目、重复条目等。
# 标准清理
GET /cleanup.php
# 强制清理(更激进)
GET /cleanup.php?force=1
{
"success": true,
"cleanup_type": "force",
"cleanup_time": "2025-11-25 10:30:00",
"before_cleanup": {
"total_entries": 500,
"valid_entries": 450,
"expired_entries": 50
},
"cleanup_result": {
"expired_removed": 50,
"duplicates_removed": 5,
"total_cleaned": 55
},
"after_cleanup": {
"total_entries": 445,
"valid_entries": 445,
"expired_entries": 0
},
"summary": {
"space_saved": 55
}
}
# 标准清理
curl -u admin:password "https://api.example.com/cleanup.php"
# 强制清理
curl -u admin:password "https://api.example.com/cleanup.php?force=1"
全功能缓存维护工具,支持多种维护操作。
GET /maintenance.php?action={action}
| 操作 | 说明 |
|---|---|
status |
查看缓存状态和重复项统计 |
cleanup |
标准清理(删除过期和重复) |
force_cleanup |
强制清理(更激进) |
remove_duplicates |
仅删除重复条目 |
full_maintenance |
完整维护(删除重复 + 强制清理) |
# 查看状态
curl -u admin:password "https://api.example.com/maintenance.php?action=status"
# 标准清理
curl -u admin:password "https://api.example.com/maintenance.php?action=cleanup"
# 完整维护
curl -u admin:password "https://api.example.com/maintenance.php?action=full_maintenance"
{
"success": true,
"action": "status",
"timestamp": "2025-11-25 10:30:00",
"data": {
"cache_stats": {
"total_entries": 500,
"valid_entries": 480,
"expired_entries": 20,
"duplicate_entries": 3
},
"duplicates": {
"uuid_duplicates": 2,
"name_duplicates": 1
},
"total_issues": 23
}
}
本系统采用智能的即时缓存过期检测机制:
| 参数 | 值 | 说明 |
|---|---|---|
| 缓存时长 | 3 小时 (10800 秒) | 可在 config.php 中修改 |
| 过期检测 | 每次请求 | 访问时即时检测 |
| 批量清理 | 1/100 概率 | >50 条过期时触发 |
// 获取玩家数据
async function getPlayerData(uuid) {
try {
const response = await fetch(`https://api.example.com/index.php?uuid=${uuid}`);
const data = await response.json();
if (data.success) {
console.log('Player:', data.data.player.displayname);
console.log('Stats:', data.data.player.stats);
return data.data;
} else {
console.error('Error:', data.error);
}
} catch (error) {
console.error('Request failed:', error);
}
}
// 使用
getPlayerData('f7c77d999f154a66a87dc4a51ef30d19');
import requests
def get_player_data(uuid):
url = f"https://api.example.com/index.php?uuid={uuid}"
try:
response = requests.get(url)
data = response.json()
if data['success']:
player = data['data']['player']
print(f"Player: {player['displayname']}")
print(f"Network Level: {player.get('networkExp', 0)}")
return data['data']
else:
print(f"Error: {data['error']}")
except Exception as e:
print(f"Request failed: {e}")
# 使用
get_player_data('f7c77d999f154a66a87dc4a51ef30d19')
<?php
function getPlayerData($uuid) {
$url = "https://api.example.com/index.php?uuid=" . urlencode($uuid);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
if ($data['success']) {
return $data['data'];
}
}
return null;
}
// 使用
$playerData = getPlayerData('f7c77d999f154a66a87dc4a51ef30d19');
if ($playerData) {
echo $playerData['player']['displayname'];
}
?>
#!/bin/bash
# 获取玩家数据
UUID="f7c77d999f154a66a87dc4a51ef30d19"
curl "https://api.example.com/index.php?uuid=$UUID" | jq .
# 管理员清理缓存
curl -u admin:password "https://api.example.com/cleanup.php?force=1" | jq .
# 查看统计
curl "https://api.example.com/stats.php" | jq '.data.today_stats'
原因:没有可用的有效 API 密钥
解决方案:
/hypixel-keys.php 添加新的 API 密钥原因:数据库连接失败
解决方案:
config.php 中的数据库配置mysql -u username -p database原因:PHP 类加载错误
解决方案:
chmod -R 755 /path/to/hypixelmirrosrc/ 目录原因:过期数据未被删除
解决方案:
/cleanup.php?force=1/maintenance.php?action=full_maintenance原因:访问管理功能需要认证
解决方案:
config.php 中的 admin 配置curl -u username:password 格式# Ubuntu/Debian
tail -f /var/log/php7.4-fpm.log
# 或 Nginx 错误日志
tail -f /var/log/nginx/error.log
mysql -u your_username -p api -e "SELECT COUNT(*) FROM player_cache;"
php -m | grep -E "pdo|curl|json"
curl "https://api.example.com/test.php"
如果以上方法无法解决您的问题: