topfans/backend/gateway/API_TEST_QUICK.md
2026-04-07 22:29:48 +08:00

109 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# API 快速测试指南
本文档包含最新调整的 API 接口的 curl 测试命令。
## 前置准备
```bash
# 1. 登录获取 JWT Token
TOKEN=$(curl -s -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"mobile":"13800138000","password":"password123"}' \
| jq -r '.data.access_token')
echo "Token: $TOKEN"
```
## 新增/变更的接口
### 1. 获取用户完整信息Login 格式)
```bash
curl -X GET http://localhost:8080/api/v1/auth/user \
-H "Authorization: Bearer $TOKEN"
```
### 2. OSS 单个文件预签名 URL已调整
```bash
# 获取头像预签名 URL
curl -X GET "http://localhost:8080/api/v1/assets/oss/presigned-url?type=avatar&file_name=test.jpg&expires=3600" \
-H "Authorization: Bearer $TOKEN"
# 获取资产预签名 URL
curl -X GET "http://localhost:8080/api/v1/assets/oss/presigned-url?type=asset&file_name=cover.png&expires=3600" \
-H "Authorization: Bearer $TOKEN"
```
### 3. OSS 批量获取预签名 URL已调整
```bash
# 批量获取头像图片
curl -X GET "http://localhost:8080/api/v1/assets/oss/batch-presigned-urls?type=avatar&expires=3600&max_keys=50" \
-H "Authorization: Bearer $TOKEN"
# 批量获取资产图片
curl -X GET "http://localhost:8080/api/v1/assets/oss/batch-presigned-urls?type=asset&expires=3600&max_keys=50" \
-H "Authorization: Bearer $TOKEN"
```
## 参数说明
### OSS 预签名接口参数变更
**旧接口(已废弃):**
- 需要传入完整的 OSS URL`file_url=https://bucket.oss-region.aliyuncs.com/path/file.jpg`
**新接口:**
- 单个文件:`type=avatar|asset` + `file_name=文件名`
- 批量文件:`type=avatar|asset`
- 自动从 JWT Token 中获取 `user_id``star_id`
- 文件路径自动构建为:`{type}/{user_id}/{star_id}/{file_name}`
### Auth 接口说明
**两个用户信息接口的区别:**
| 接口 | 路径 | 返回格式 | 用途 |
|------|------|----------|------|
| GetCurrentUser | `/api/v1/auth/me` | GetMeResponseDTO | 获取基本用户信息 |
| GetAuthMe | `/api/v1/auth/user` | LoginResponseDTO | 获取完整用户信息(同登录接口) |
## 完整测试流程
```bash
#!/bin/bash
# 1. 登录
echo "=== 1. 登录 ==="
TOKEN=$(curl -s -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"mobile":"13800138000","password":"password123"}' \
| jq -r '.data.access_token')
echo "Token: ${TOKEN:0:20}..."
# 2. 获取用户完整信息
echo -e "\n=== 2. 获取用户完整信息 ==="
curl -s -X GET http://localhost:8080/api/v1/auth/user \
-H "Authorization: Bearer $TOKEN" | jq '.'
# 3. 获取单个文件预签名 URL
echo -e "\n=== 3. 获取头像预签名 URL ==="
curl -s -X GET "http://localhost:8080/api/v1/assets/oss/presigned-url?type=avatar&file_name=test.jpg&expires=3600" \
-H "Authorization: Bearer $TOKEN" | jq '.data.url'
# 4. 批量获取预签名 URL
echo -e "\n=== 4. 批量获取头像图片 ==="
curl -s -X GET "http://localhost:8080/api/v1/assets/oss/batch-presigned-urls?type=avatar&expires=3600&max_keys=10" \
-H "Authorization: Bearer $TOKEN" | jq '.data.count'
echo -e "\n=== 测试完成 ==="
```
## 主要变更总结
1. **安全性增强**OSS 路径不再由前端传入,自动从 JWT 提取用户信息构建,防止越权访问
2. **简化调用**:前端无需拼接完整 OSS URL只需传入 `type``file_name`
3. **新增接口**`GET /api/v1/auth/user` 返回与登录接口相同格式的完整用户信息