This commit is contained in:
Zhanghu
2026-01-13 13:50:27 +08:00
commit a9efcd55a7
72 changed files with 8430 additions and 0 deletions

56
test_api.sh Executable file
View File

@@ -0,0 +1,56 @@
#!/bin/bash
# DRS9 Dashboard API 测试脚本
BASE_URL="http://localhost:5264"
echo "=================================="
echo "DRS9 Dashboard API 测试"
echo "=================================="
# 1. 设备注册
echo -e "\n1. 设备注册..."
REGISTER_RESPONSE=$(curl -s -X POST $BASE_URL/api/devices/register \
-H "Content-Type: application/json" \
-d '{"deviceCode":"TEST-001-DEV","deviceName":"测试设备1号","deviceType":"Android"}')
TOKEN=$(echo $REGISTER_RESPONSE | jq -r '.token')
DEVICE_ID=$(echo $REGISTER_RESPONSE | jq -r '.deviceId')
echo "Token: $TOKEN"
echo "Device ID: $DEVICE_ID"
# 2. 获取设备信息
echo -e "\n2. 获取设备信息..."
curl -s -X GET $BASE_URL/api/devices/info \
-H "Authorization: Bearer $TOKEN" | jq .
# 3. 获取设备分配的内容(初始为空)
echo -e "\n3. 获取设备分配的内容(初始为空)..."
curl -s -X GET $BASE_URL/api/devices/content \
-H "Authorization: Bearer $TOKEN" | jq .
# 4. 心跳测试
echo -e "\n4. 心跳测试..."
curl -s -X POST $BASE_URL/api/devices/heartbeat \
-H "Authorization: Bearer $TOKEN" | jq .
# 5. 获取所有可用应用(不需要认证的测试接口)
echo -e "\n5. 获取所有应用(数据库中的预置数据)..."
echo "注意:需要管理员权限访问 /api/admin/applications"
echo -e "\n=================================="
echo "测试完成"
echo "=================================="
echo ""
echo "管理 API 端点(需要管理员认证):"
echo " GET /api/admin/applications - 获取所有应用"
echo " POST /api/admin/applications - 创建应用"
echo " GET /api/admin/devices - 获取所有设备"
echo " POST /api/admin/devices - 创建设备(生成设备码)"
echo " GET /api/admin/devices/{id}/content - 获取设备内容"
echo " POST /api/admin/devices/{id}/content - 分配内容给设备"
echo " POST /api/admin/devices/{id}/push/refresh - 推送刷新指令"
echo " GET /api/admin/devicegroups - 获取所有分组"
echo ""
echo "WebSocket 端点:"
echo " ws://localhost:5264/ws?deviceId=1"