330 lines
11 KiB
Markdown
330 lines
11 KiB
Markdown
# 后端接口 Windows 手动测试命令
|
|
|
|
当前后端 `server_encrypted.cpp` 只监听 HTTP 端口:
|
|
|
|
```text
|
|
8082
|
|
```
|
|
|
|
以下命令适合在 Windows PowerShell 或 CMD 中复制执行。Windows 下建议使用 `curl.exe`,避免 PowerShell 把 `curl` 解析成别名。
|
|
|
|
如果后端在本机运行,使用:
|
|
|
|
```text
|
|
http://127.0.0.1:8082
|
|
```
|
|
|
|
如果测试公网服务器,替换成:
|
|
|
|
```text
|
|
http://27.106.113.205:8082
|
|
```
|
|
|
|
下面示例默认使用本机地址。
|
|
|
|
## 1. 测试端口和服务健康
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 "http://27.106.113.205:8082/api/v1/system/health"
|
|
```
|
|
|
|
预期能看到 `HTTP/1.1 200 OK` 或类似成功响应。
|
|
|
|
## 2. 获取服务器时间
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/system/time"
|
|
```
|
|
|
|
## 2.0 查看 SQLite 存储状态
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/system/storage"
|
|
```
|
|
|
|
重点看:
|
|
|
|
```text
|
|
"storage":"sqlite"
|
|
"database":"attendance.db"
|
|
"ok":true
|
|
"quick_check":"ok"
|
|
"records": 考勤记录数量
|
|
"face_photos": 服务端照片数量
|
|
"pending_deletes": K210待删除任务数量
|
|
```
|
|
|
|
## 2.0.1 查看当前同步版本
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/sync/version"
|
|
```
|
|
|
|
## 2.1 统一同步状态:K210
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/sync/state?client=k210&last_version=0"
|
|
```
|
|
|
|
重点看:
|
|
|
|
```text
|
|
"version": 当前服务端同步版本
|
|
"changed": true/false
|
|
"face_mappings": 人脸ID到学号映射
|
|
"pending_delete": K210需要删除的本地人脸ID
|
|
```
|
|
|
|
## 2.2 统一同步状态:STM32
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/sync/state?client=stm32&last_version=0"
|
|
```
|
|
|
|
重点看 `time_slots` 是否正确返回。
|
|
|
|
## 2.3 统一同步状态:Qt
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/sync/state?client=qt&last_version=0"
|
|
```
|
|
|
|
## 2.4 K210 确认统一同步删除
|
|
|
|
把 `2` 换成真实已删除成功的人脸 ID。
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data-binary "{\"client\":\"k210\",\"version\":1,\"deleted\":[\"2\"]}" "http://27.106.113.205:8082/api/v1/sync/ack"
|
|
```
|
|
|
|
## 3. 获取全部考勤记录
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/attendance/records?limit=1000&offset=0"
|
|
```
|
|
|
|
后端当前以 `attendance.db` 为准。旧 `attendance_database.csv` 只会在首次启动 SQLite 时作为迁移来源,之后新增记录不会再写回 CSV。
|
|
|
|
如果本机安装了 `sqlite3.exe`,也可以在服务端运行目录执行:
|
|
|
|
```powershell
|
|
sqlite3.exe attendance.db "SELECT timestamp,student_id,name,confidence,status,class_id FROM records ORDER BY id DESC LIMIT 10;"
|
|
```
|
|
|
|
备份当前数据库:
|
|
|
|
```powershell
|
|
sqlite3.exe attendance.db ".backup attendance_backup.db"
|
|
```
|
|
|
|
## 4. 获取统计信息
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/attendance/statistics"
|
|
```
|
|
|
|
## 5. 获取签到时间段
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/config/time-slots"
|
|
```
|
|
|
|
## 6. 保存签到时间段
|
|
|
|
用于测试 Qt 端 `/api/v1/config/time-slots` 保存失败的问题。执行后观察后端日志,正常应该显示 `POST body size` 大于 0。
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data-binary "{\"time_slots\":[{\"name\":\"上午签到\",\"start_time\":\"08:00\",\"end_time\":\"09:30\",\"enabled\":true},{\"name\":\"中午签退\",\"start_time\":\"12:00\",\"end_time\":\"13:00\",\"enabled\":true},{\"name\":\"下午签到\",\"start_time\":\"14:00\",\"end_time\":\"15:00\",\"enabled\":true},{\"name\":\"晚上签退\",\"start_time\":\"17:00\",\"end_time\":\"18:30\",\"enabled\":true}]}" "http://27.106.113.205:8082/api/v1/config/time-slots"
|
|
```
|
|
|
|
## 7. 检查是否重复签到
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/attendance/duplicates?student_id=1&slot_start=00:00&slot_end=23:59"
|
|
```
|
|
|
|
## 8. 获取今天指定时间段记录
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/attendance/today?slot_start=00:00&slot_end=23:59"
|
|
```
|
|
|
|
也可以测试指定签到时间段:
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/attendance/today?slot_start=14:00&slot_end=15:00"
|
|
```
|
|
|
|
## 9. 获取映射配置
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/config/mappings"
|
|
```
|
|
|
|
## 10. 保存映射配置
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data-binary "{\"student_name_map\":{\"1\":\"ID1\"},\"class_name_map\":{\"1\":\"一班\"}}" "http://27.106.113.205:8082/api/v1/config/mappings"
|
|
```
|
|
|
|
## 11. 获取人脸照片列表
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/faces/photos"
|
|
```
|
|
|
|
## 12. 下载指定人脸照片
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" "http://27.106.113.205:8082/api/v1/faces/photos/1" --output "%TEMP%\backend_face_1.jpg"
|
|
```
|
|
|
|
如果 `face_id=1` 存在,照片会保存到:
|
|
|
|
```text
|
|
%TEMP%\backend_face_1.jpg
|
|
```
|
|
|
|
## 13. 上传人脸照片
|
|
|
|
把 `C:\path\to\face.jpg` 换成真实 jpg 文件路径。
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Content-Type: image/jpeg" --data-binary "@C:\path\to\face.jpg" "http://27.106.113.205:8082/api/v1/faces/photos/1"
|
|
```
|
|
|
|
## 14. 获取人脸 ID 映射
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/faces/mappings"
|
|
```
|
|
|
|
## 15. 保存人脸 ID 映射
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data-binary "{\"mappings\":{\"1\":\"1\"}}" "http://27.106.113.205:8082/api/v1/faces/mappings"
|
|
```
|
|
|
|
## 16. 获取全部学生 ID
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/faces/student-ids"
|
|
```
|
|
|
|
## 17. 获取待删除列表
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/faces/pending-delete"
|
|
```
|
|
|
|
## 18. 确认删除同步完成
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data-binary "{\"face_id\":\"1\"}" "http://27.106.113.205:8082/api/v1/faces/delete-ack"
|
|
```
|
|
|
|
## 19. K210 查询是否需要同步
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" "http://27.106.113.205:8082/api/v1/sync/request"
|
|
```
|
|
|
|
## 20. 触发 K210 同步
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data-binary "{\"sync\":true}" "http://27.106.113.205:8082/api/v1/sync/trigger"
|
|
```
|
|
|
|
## 21. K210 同步确认
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data-binary "{\"ack\":true}" "http://27.106.113.205:8082/api/v1/sync/request/ack"
|
|
```
|
|
|
|
## 22. 加密签到接口
|
|
|
|
`/api/v1/attendance/checkins` 需要 STM32 生成的 AES-128-CBC Base64 加密正文。把 `BODY` 替换成真实加密数据。
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "X-Encrypted: AES128-CBC" -H "Content-Type: application/octet-stream" --data-binary "BODY" "http://27.106.113.205:8082/api/v1/attendance/checkins"
|
|
```
|
|
|
|
## 23. 删除单条考勤记录
|
|
|
|
危险操作,会删除真实数据。执行前把时间和学生 ID 改成要删除的记录。
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -X DELETE "http://27.106.113.205:8082/api/v1/attendance/records?timestamp=2026-05-01%2014%3A30%3A38&student_id=1"
|
|
```
|
|
|
|
## 24. 删除指定人脸
|
|
|
|
危险操作,只删除人脸信息,不删除考勤记录。
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -X DELETE "http://27.106.113.205:8082/api/v1/faces/1"
|
|
```
|
|
|
|
## 25. 删除指定人脸并删除相关考勤记录
|
|
|
|
危险操作,会删除人脸和相关记录。
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -X DELETE "http://27.106.113.205:8082/api/v1/faces/1?delete_records=true"
|
|
```
|
|
|
|
## 26. 清空全部考勤记录
|
|
|
|
危险操作,会清空考勤数据库。
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Content-Type: application/json" -X POST --data-binary "{}" "http://27.106.113.205:8082/api/v1/attendance/records/clear"
|
|
```
|
|
|
|
## 27. Windows 上检查端口占用
|
|
|
|
```powershell
|
|
netstat -ano | findstr :8082
|
|
```
|
|
|
|
如果能看到 `LISTENING`,说明本机有程序正在监听 `8082`。
|
|
|
|
## 28. Windows 上测试 TCP 端口连通
|
|
|
|
```powershell
|
|
Test-NetConnection 127.0.0.1 -Port 8082
|
|
```
|
|
|
|
公网服务器测试:
|
|
|
|
```powershell
|
|
Test-NetConnection 27.106.113.205 -Port 8082
|
|
```
|
|
|
|
`TcpTestSucceeded : True` 表示 TCP 端口可连通。
|
|
|
|
## 29. 判断 Qt POST 是否真的发送了请求体
|
|
|
|
先手动执行这条:
|
|
|
|
```powershell
|
|
curl.exe -i --max-time 8 -H "X-Api-Token: change-me-token" -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data-binary "{\"time_slots\":[{\"name\":\"下午签到\",\"start_time\":\"14:00\",\"end_time\":\"15:00\",\"enabled\":true}]}" "http://27.106.113.205:8082/api/v1/config/time-slots"
|
|
```
|
|
|
|
如果后端日志显示:
|
|
|
|
```text
|
|
[HTTP] POST body size: xx bytes
|
|
```
|
|
|
|
说明服务端可以正常接收请求体。
|
|
|
|
如果 Qt 保存时后端仍显示:
|
|
|
|
```text
|
|
[HTTP] POST body size: 0 bytes
|
|
```
|
|
|
|
说明问题在 Qt 端发送 POST 的方式上。
|
|
|