Appearance
用户资料与设置
获取用户公开资料
GET 公开
/api/user/profile/:userId
获取指定用户的公开资料,无需认证。返回的 isOnline 字段基于 WebSocket 连接状态。
路径参数:
| 参数 | 类型 | 说明 |
|---|---|---|
| userId | string | 目标用户 ID |
请求示例:
bash
curl http://localhost:3000/api/user/profile/u_abc123成功响应:
json
{
"code": 200,
"data": {
"id": "u_abc123",
"username": "zhangsan",
"avatar": "",
"nickname": "张三",
"gender": "male",
"bio": "Hello world",
"phone": "138****8888",
"isOnline": 1
}
}更新个人资料
POST JWT
/api/user/profile
更新当前登录用户的个人资料。所有字段均为可选,只传需要更新的字段。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| nickname | string | 否 | 昵称 |
| avatar | string | 否 | 头像 URL |
| gender | string | 否 | 性别:"" / "male" / "female" / "secret" |
| bio | string | 否 | 个人简介 |
| phone | string | 否 | 手机号 |
| string | 否 | 邮箱 |
请求示例:
bash
curl -X POST http://localhost:3000/api/user/profile \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"nickname": "张三丰",
"gender": "male",
"bio": "大家好,我是张三"
}'成功响应:
json
{
"code": 200,
"message": "资料更新成功",
"data": {
"id": "u_abc123",
"username": "zhangsan",
"avatar": "",
"nickname": "张三丰",
"email": "zhangsan@example.com",
"gender": "male",
"bio": "大家好,我是张三",
"phone": "",
"push_enabled": 1,
"dnd_enabled": 0
}
}更新通知设置
POST JWT
/api/user/settings
更新用户的通知相关设置。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| pushEnabled | boolean | 否 | 是否启用推送通知 |
| dndEnabled | boolean | 否 | 是否开启免打扰模式 |
请求示例:
bash
curl -X POST http://localhost:3000/api/user/settings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"pushEnabled": true,
"dndEnabled": false
}'成功响应:
json
{
"code": 200,
"message": "设置更新成功",
"data": {
"id": "u_abc123",
"username": "zhangsan",
"push_enabled": 1,
"dnd_enabled": 0
}
}免打扰模式
开启后,用户仍可收到消息,但不会触发推送通知。
屏蔽用户
POST JWT
/api/user/block
屏蔽指定用户。屏蔽后,被屏蔽用户无法向你发送好友请求或聊天消息。不能屏蔽自己。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| blockedId | string | 是 | 要屏蔽的用户 ID |
请求示例:
bash
curl -X POST http://localhost:3000/api/user/block \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{ "blockedId": "u_def456" }'解除屏蔽
POST JWT
/api/user/unblock
解除对指定用户的屏蔽。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| blockedId | string | 是 | 要解除屏蔽的用户 ID |
获取屏蔽列表
GET JWT
/api/user/blocked
获取当前用户已屏蔽的用户列表,按屏蔽时间倒序排列。
请求示例:
bash
curl http://localhost:3000/api/user/blocked \
-H "Authorization: Bearer <token>"成功响应:
json
{
"code": 200,
"data": [
{
"id": "u_def456",
"username": "lisi",
"avatar": "",
"create_time": 1719000000000
}
]
}