用户管理接口
用户管理相关的 API 接口,包括用户认证、个人信息、上传记录等功能。
🔐 认证接口
用户登录
接口地址:POST /api/auth/login
请求参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| username | string | 是 | 用户名 |
| password | string | 是 | 密码 |
请求示例:
json
{
"username": "admin",
"password": "chenxi123"
}响应示例:
json
{
"code": 200,
"message": "登录成功",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"username": "admin",
"email": "admin@example.com",
"role": "ADMIN",
"avatar": "/uploads/avatars/default.png",
"createdAt": "2024-01-01T00:00:00Z"
}
}
}用户注册
接口地址:POST /api/auth/register
请求参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| username | string | 是 | 用户名(3-20位字母数字) |
| password | string | 是 | 密码(6位以上) |
| string | 是 | 邮箱地址 | |
| captcha | string | 是 | 验证码 |
请求示例:
json
{
"username": "newuser",
"password": "password123",
"email": "newuser@example.com",
"captcha": "123456"
}获取验证码
接口地址:GET /api/auth/captcha
响应示例:
json
{
"code": 200,
"message": "验证码获取成功",
"data": {
"captchaId": "captcha_123456",
"captchaImage": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
"expiresIn": 300
}
}刷新令牌
接口地址:POST /api/auth/refresh
请求头:
Authorization: Bearer <refresh-token>👤 用户信息接口
获取用户信息
接口地址:GET /api/user/profile
请求头:
Authorization: Bearer <jwt-token>响应示例:
json
{
"code": 200,
"message": "获取成功",
"data": {
"id": 1,
"username": "admin",
"email": "admin@example.com",
"role": "ADMIN",
"avatar": "/uploads/avatars/default.png",
"storageUsed": 1024000,
"storageLimit": 104857600,
"uploadCount": 150,
"lastLogin": "2024-01-15T10:30:00Z",
"createdAt": "2024-01-01T00:00:00Z"
}
}更新用户信息
接口地址:PUT /api/user/profile
请求参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| string | 否 | 邮箱地址 | |
| avatar | string | 否 | 头像 URL |
请求示例:
json
{
"email": "newemail@example.com",
"avatar": "/uploads/avatars/custom.png"
}修改密码
接口地址:PUT /api/user/password
请求参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| oldPassword | string | 是 | 旧密码 |
| newPassword | string | 是 | 新密码 |
📤 上传记录接口
获取上传记录列表
接口地址:GET /api/user/uploads
查询参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | integer | 否 | 页码(默认1) |
| size | integer | 否 | 每页大小(默认20) |
| sort | string | 否 | 排序字段(如:createdAt,desc) |
响应示例:
json
{
"code": 200,
"message": "获取成功",
"data": {
"content": [
{
"id": 1,
"filename": "example.jpg",
"originalName": "example.jpg",
"fileSize": 102400,
"fileType": "image/jpeg",
"storageType": "LOCAL",
"url": "http://localhost:8080/uploads/example.jpg",
"thumbnailUrl": "http://localhost:8080/uploads/thumbnails/example.jpg",
"uploadTime": "2024-01-15T10:30:00Z",
"status": "ACTIVE"
}
],
"totalElements": 150,
"totalPages": 8,
"size": 20,
"number": 0,
"first": true,
"last": false
}
}删除上传记录
接口地址:DELETE /api/user/uploads/{id}
路径参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | integer | 是 | 上传记录 ID |
批量删除上传记录
接口地址:DELETE /api/user/uploads/batch
请求参数:
json
{
"ids": [1, 2, 3]
}🔑 API 密钥管理
获取 API 密钥列表
接口地址:GET /api/user/apikeys
响应示例:
json
{
"code": 200,
"message": "获取成功",
"data": [
{
"id": 1,
"name": "Web应用",
"key": "ak_xxxxxxxxxxxxxxxx",
"createdAt": "2024-01-01T00:00:00Z",
"lastUsed": "2024-01-15T10:30:00Z",
"status": "ACTIVE"
}
]
}创建 API 密钥
接口地址:POST /api/user/apikeys
请求参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | 密钥名称 |
响应示例:
json
{
"code": 200,
"message": "创建成功",
"data": {
"id": 2,
"name": "移动应用",
"key": "ak_yyyyyyyyyyyyyyyy",
"createdAt": "2024-01-16T10:30:00Z",
"status": "ACTIVE"
}
}删除 API 密钥
接口地址:DELETE /api/user/apikeys/{id}
📊 统计信息
获取用户统计
接口地址:GET /api/user/stats
响应示例:
json
{
"code": 200,
"message": "获取成功",
"data": {
"totalUploads": 150,
"todayUploads": 5,
"storageUsed": 1024000,
"storageLimit": 104857600,
"storageUsage": "0.98%",
"uploadTrends": [
{
"date": "2024-01-15",
"count": 12
},
{
"date": "2024-01-14",
"count": 8
}
]
}
}⚠️ 错误码说明
| 错误码 | 说明 | 可能原因 |
|---|---|---|
| 1001 | 用户名或密码错误 | 登录信息不正确 |
| 1002 | 用户不存在 | 用户未注册 |
| 1003 | 用户已被禁用 | 账户被管理员禁用 |
| 1004 | 验证码错误 | 验证码输入错误或过期 |
| 1005 | 邮箱已存在 | 注册时邮箱已被使用 |
| 1006 | 用户名已存在 | 注册时用户名已被使用 |
| 1007 | 旧密码错误 | 修改密码时旧密码不正确 |
🧪 测试示例
完整登录流程
bash
# 1. 用户登录
curl -X POST "http://localhost:8080/api/auth/login" \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "chenxi123"
}'
# 2. 获取用户信息
curl -X GET "http://localhost:8080/api/user/profile" \
-H "Authorization: Bearer <token-from-step1>"
# 3. 获取上传记录
curl -X GET "http://localhost:8080/api/user/uploads?page=1&size=10" \
-H "Authorization: Bearer <token-from-step1>"🔄 更新日志
v1.0.0 (2024-01-01)
- 用户认证接口(登录、注册、验证码)
- 用户信息管理接口
- 上传记录管理接口
- API 密钥管理接口
- 用户统计信息接口
🔗 相关链接: API 概览