2.7 KiB
2.7 KiB
后端接口 TODO 清单 - 通知推送模块
1. 同步通知到后端
文件: LocalNotificationManager.java
接口路径: POST /api/notifications/sync
请求参数:
{
"notificationId": "string",
"type": "string",
"title": "string",
"content": "string",
"timestamp": "number"
}
返回数据:
{
"code": 200,
"data": {
"success": true
}
}
说明:
- 将本地生成的通知同步到后端
- 用于跨设备通知同步
2. 获取未读通知数量
文件: MainActivity.java, NotificationsActivity.java
接口路径: GET /api/notifications/unread/count
请求参数: userId(从token中获取)
返回数据:
{
"code": 200,
"data": {
"unreadCount": "number",
"byType": {
"system": "number",
"interaction": "number",
"follow": "number",
"message": "number",
"live": "number"
}
}
}
3. 标记所有通知为已读
文件: NotificationsActivity.java
接口路径: POST /api/notifications/read/all
请求参数:
{
"userId": "string",
"type": "string"
}
返回数据:
{
"code": 200,
"data": {
"success": true
}
}
4. 删除通知
文件: NotificationsActivity.java
接口路径: DELETE /api/notifications/{notificationId}
请求参数: notificationId (路径参数)
返回数据:
{
"code": 200,
"data": {
"success": true
}
}
推送通知集成
Firebase Cloud Messaging (FCM)
-
注册设备Token
- 接口路径:
POST /api/devices/register - 请求参数:
{deviceToken: string, platform: "android"}
- 接口路径:
-
注销设备Token
- 接口路径:
POST /api/devices/unregister - 请求参数:
{deviceToken: string}
- 接口路径:
-
更新通知设置
- 接口路径:
PUT /api/notifications/settings - 请求参数:
{enablePush: boolean, types: string[]}
- 接口路径:
推送消息格式
{
"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}
接收消息格式
{
"type": "notification",
"data": {
"id": "string",
"type": "string",
"title": "string",
"content": "string",
"timestamp": "number",
"isRead": false
}
}
心跳保持
- 每30秒发送一次心跳:
{"type": "ping"} - 服务器响应:
{"type": "pong"}