zhibo/android-app/后端接口TODO清单-通知推送.md

146 lines
2.7 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.

# 后端接口 TODO 清单 - 通知推送模块
## 1. 同步通知到后端
**文件**: `LocalNotificationManager.java`
**接口路径**: `POST /api/notifications/sync`
**请求参数**:
```json
{
"notificationId": "string",
"type": "string",
"title": "string",
"content": "string",
"timestamp": "number"
}
```
**返回数据**:
```json
{
"code": 200,
"data": {
"success": true
}
}
```
**说明**:
- 将本地生成的通知同步到后端
- 用于跨设备通知同步
## 2. 获取未读通知数量
**文件**: `MainActivity.java`, `NotificationsActivity.java`
**接口路径**: `GET /api/notifications/unread/count`
**请求参数**: userId从token中获取
**返回数据**:
```json
{
"code": 200,
"data": {
"unreadCount": "number",
"byType": {
"system": "number",
"interaction": "number",
"follow": "number",
"message": "number",
"live": "number"
}
}
}
```
## 3. 标记所有通知为已读
**文件**: `NotificationsActivity.java`
**接口路径**: `POST /api/notifications/read/all`
**请求参数**:
```json
{
"userId": "string",
"type": "string"
}
```
**返回数据**:
```json
{
"code": 200,
"data": {
"success": true
}
}
```
## 4. 删除通知
**文件**: `NotificationsActivity.java`
**接口路径**: `DELETE /api/notifications/{notificationId}`
**请求参数**: notificationId (路径参数)
**返回数据**:
```json
{
"code": 200,
"data": {
"success": true
}
}
```
## 推送通知集成
### Firebase Cloud Messaging (FCM)
1. 注册设备Token
- 接口路径: `POST /api/devices/register`
- 请求参数: `{deviceToken: string, platform: "android"}`
2. 注销设备Token
- 接口路径: `POST /api/devices/unregister`
- 请求参数: `{deviceToken: string}`
3. 更新通知设置
- 接口路径: `PUT /api/notifications/settings`
- 请求参数: `{enablePush: boolean, types: string[]}`
### 推送消息格式
```json
{
"notification": {
"title": "string",
"body": "string",
"icon": "string"
},
"data": {
"type": "string",
"targetId": "string",
"action": "string"
}
}
```
### 通知类型
- `system`: 系统通知
- `interaction`: 互动通知(点赞、评论)
- `follow`: 关注通知
- `message`: 私信通知
- `live`: 直播通知(关注的主播开播)
## WebSocket 实时推送
### 连接
- WebSocket URL: `ws://api.example.com/notifications`
- 连接时携带 token: `?token={token}`
### 接收消息格式
```json
{
"type": "notification",
"data": {
"id": "string",
"type": "string",
"title": "string",
"content": "string",
"timestamp": "number",
"isRead": false
}
}
```
### 心跳保持
- 每30秒发送一次心跳: `{"type": "ping"}`
- 服务器响应: `{"type": "pong"}`