feat(push-notification): 添加用户登录后自动更新推送token绑定功能
- 新增updateTokenUserId方法用于更新设备令牌的用户ID绑定关系 - 添加onUserLogin方法在用户登录成功后自动更新token绑定 - 优化checkAndRegisterToken逻辑,确保每次应用启动都更新用户ID绑定 - 修改UpdateTokenRequest接口,将appVersion和osVersion设为可选参数 - 在用户登录成功后自动触发推送token用户ID绑定更新
This commit is contained in:
@@ -19,8 +19,8 @@ export interface DeviceTokenRequest {
|
||||
export interface UpdateTokenRequest {
|
||||
currentDeviceToken: string;
|
||||
newDeviceToken: string;
|
||||
appVersion: string;
|
||||
osVersion: string;
|
||||
appVersion?: string;
|
||||
osVersion?: string;
|
||||
}
|
||||
|
||||
// 设备令牌注销请求参数
|
||||
@@ -125,6 +125,27 @@ export class PushNotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备令牌的用户ID绑定关系
|
||||
* 用户ID从服务端通过header中的token解析获取
|
||||
*/
|
||||
async updateTokenUserId(deviceToken: string): Promise<PushNotificationResponse> {
|
||||
try {
|
||||
logger.info('更新设备令牌用户ID绑定:', deviceToken.substring(0, 20) + '...');
|
||||
|
||||
const response = await api.put<PushNotificationResponse>(
|
||||
'/push-notifications/update-token-user-id',
|
||||
{ deviceToken }
|
||||
);
|
||||
|
||||
logger.info('设备令牌用户ID绑定更新成功:', response.tokenId);
|
||||
return response;
|
||||
} catch (error) {
|
||||
logger.error('更新设备令牌用户ID绑定失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地存储的设备令牌
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user