Node.js 在nest js中集成firebase通知
我正在尝试使用我在颤振中使用的nestjs创建fcmapi。我是Nest js的新手,我已经使用实现了代码。 我的代码中没有错误,但我没有在手机上收到通知 下面是我的服务文件,我在其中实现了推送通知Node.js 在nest js中集成firebase通知,node.js,firebase,firebase-cloud-messaging,nestjs,Node.js,Firebase,Firebase Cloud Messaging,Nestjs,我正在尝试使用我在颤振中使用的nestjs创建fcmapi。我是Nest js的新手,我已经使用实现了代码。 我的代码中没有错误,但我没有在手机上收到通知 下面是我的服务文件,我在其中实现了推送通知 async sendMessageToUser(registrationToken) { var message = { android: { ttl: 3600 * 1000, // 1 hour in milliseconds
async sendMessageToUser(registrationToken) {
var message = {
android: {
ttl: 3600 * 1000, // 1 hour in milliseconds
data: {
title: "hiii",
body: "hello",
}
},
apns: {
headers: {
'apns-priority': '10'
},
payload: {
"aps": {
"alert": {
"body": "hii",
"title": "hello"
},
"sound": "dafault",
}
}
},
token: registrationToken
};
// Send a message to the device corresponding to the provided
// registration token with the provided options.
try{
Logger.log("FIrst try catch");
await admin.messaging().send(message);
try {
Logger.log("second try catch");
} catch (error) {
Logger.error(error);
}
}catch (error) {
Logger.error(error);
}
}
main.ts文件
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import admin, { ServiceAccount } from 'firebase-admin';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
// Set the config options
const adminConfig: ServiceAccount = {
"projectId":"my firebase projetId",
"privateKey": "private key".replace(/\\n/g, '\n'),
"clientEmail": "firebase client email",
};
// Initialize the firebase admin app
admin.initializeApp({
credential: admin.credential.cert(adminConfig),
databaseURL: "db url",
});
app.enableCors();
await app.listen(3000);
}
bootstrap();
有人能告诉我我的代码有什么问题吗?为什么我没有在手机上收到通知?您是否尝试打印admin.messaging().send()的结果?是否尝试打印admin.messaging().send()的结果?