feat(push): migrate APNs provider from @parse/node-apn to apns2 library

- Replace @parse/node-apn with apns2 for improved APNs integration
- Update ApnsProvider to use new ApnsClient with modern API
- Refactor notification creation and sending logic for better error handling
- Add proper error event listeners for device token issues
- Update configuration interface to match apns2 requirements
- Modify push notification endpoints to allow public access for token registration
- Update service methods to handle new response format from apns2
- Add UsersModule dependency to PushNotificationsModule
This commit is contained in:
richarjiang
2025-10-14 19:25:30 +08:00
parent 305a969912
commit 38dd740c8c
9 changed files with 520 additions and 171 deletions

View File

@@ -13,21 +13,24 @@ import { Public } from '../common/decorators/public.decorator';
@ApiTags('推送通知')
@Controller('push-notifications')
@UseGuards(JwtAuthGuard)
export class PushNotificationsController {
constructor(private readonly pushNotificationsService: PushNotificationsService) { }
@Post('register-token')
@ApiOperation({ summary: '注册设备推送令牌' })
@Public()
@ApiResponse({ status: 200, description: '注册成功', type: RegisterTokenResponseDto })
async registerToken(
@CurrentUser() user: AccessTokenPayload,
@Body() registerTokenDto: RegisterDeviceTokenDto,
): Promise<RegisterTokenResponseDto> {
return this.pushNotificationsService.registerToken(user.sub, registerTokenDto);
return this.pushNotificationsService.registerToken(registerTokenDto, user.sub);
}
@Put('update-token')
@Public()
@ApiOperation({ summary: '更新设备推送令牌' })
@ApiResponse({ status: 200, description: '更新成功', type: UpdateTokenResponseDto })
async updateToken(
@@ -38,6 +41,7 @@ export class PushNotificationsController {
}
@Delete('unregister-token')
@Public()
@ApiOperation({ summary: '注销设备推送令牌' })
@ApiResponse({ status: 200, description: '注销成功', type: UnregisterTokenResponseDto })
async unregisterToken(
@@ -49,6 +53,7 @@ export class PushNotificationsController {
@Post('send')
@ApiOperation({ summary: '发送推送通知' })
@UseGuards(JwtAuthGuard)
@ApiResponse({ status: 200, description: '发送成功', type: PushResponseDto })
async sendNotification(
@Body() sendNotificationDto: SendPushNotificationDto,
@@ -58,6 +63,7 @@ export class PushNotificationsController {
@Post('send-by-template')
@ApiOperation({ summary: '使用模板发送推送' })
@UseGuards(JwtAuthGuard)
@ApiResponse({ status: 200, description: '发送成功', type: PushResponseDto })
async sendNotificationByTemplate(
@Body() sendByTemplateDto: SendPushByTemplateDto,
@@ -67,6 +73,7 @@ export class PushNotificationsController {
@Post('send-batch')
@ApiOperation({ summary: '批量发送推送' })
@UseGuards(JwtAuthGuard)
@ApiResponse({ status: 200, description: '发送成功', type: BatchPushResponseDto })
async sendBatchNotifications(
@Body() sendBatchDto: SendPushNotificationDto,
@@ -76,6 +83,7 @@ export class PushNotificationsController {
@Post('send-silent')
@ApiOperation({ summary: '发送静默推送' })
@UseGuards(JwtAuthGuard)
@ApiResponse({ status: 200, description: '发送成功', type: PushResponseDto })
async sendSilentNotification(
@Body() body: { userId: string; payload: any },