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:
@@ -80,7 +80,7 @@ export class PushNotificationsService {
|
||||
const apnsNotification = this.apnsProvider.createNotification({
|
||||
title: notificationData.title,
|
||||
body: notificationData.body,
|
||||
payload: notificationData.payload,
|
||||
data: notificationData.payload,
|
||||
pushType: notificationData.pushType,
|
||||
priority: notificationData.priority,
|
||||
expiry: notificationData.expiry,
|
||||
@@ -239,7 +239,7 @@ export class PushNotificationsService {
|
||||
const apnsNotification = this.apnsProvider.createNotification({
|
||||
title: notificationData.title,
|
||||
body: notificationData.body,
|
||||
payload: notificationData.payload,
|
||||
data: notificationData.payload,
|
||||
pushType: notificationData.pushType,
|
||||
priority: notificationData.priority,
|
||||
expiry: notificationData.expiry,
|
||||
@@ -290,11 +290,12 @@ export class PushNotificationsService {
|
||||
const message = await this.pushMessageService.createMessage(messageData);
|
||||
|
||||
// 查找对应的APNs结果
|
||||
const apnsResult = apnsResults.sent.find(s => s.device === deviceToken) ||
|
||||
const apnsResult = apnsResults.sent.includes(deviceToken) ?
|
||||
{ device: deviceToken, success: true } :
|
||||
apnsResults.failed.find(f => f.device === deviceToken);
|
||||
|
||||
if (apnsResult) {
|
||||
if ('device' in apnsResult && apnsResult.device === deviceToken) {
|
||||
if (apnsResult.device === deviceToken && 'success' in apnsResult && apnsResult.success) {
|
||||
// 成功发送
|
||||
await this.pushMessageService.updateMessageStatus(message.id, PushMessageStatus.SENT, apnsResult);
|
||||
await this.pushTokenService.updateLastUsedTime(deviceToken);
|
||||
@@ -424,9 +425,9 @@ export class PushNotificationsService {
|
||||
/**
|
||||
* 注册设备令牌
|
||||
*/
|
||||
async registerToken(userId: string, tokenData: any): Promise<any> {
|
||||
async registerToken(tokenData: any, userId?: string,): Promise<any> {
|
||||
try {
|
||||
const token = await this.pushTokenService.registerToken(userId, tokenData);
|
||||
const token = await this.pushTokenService.registerToken(tokenData, userId);
|
||||
return {
|
||||
code: ResponseCode.SUCCESS,
|
||||
message: '设备令牌注册成功',
|
||||
|
||||
Reference in New Issue
Block a user