我有一个 Android 应用程序,我可以在其中以 http 格式从我的设备发送推送通知,但现在我想编写一个 Node ,我希望在特定日期和时间安排推送通知,请有人帮忙我很长一段时间都卡在这个过程中
这是我的 Node ;
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.https.onRequest((req, res) => {
const to = req.query.to;
const title = req.query.title;
const body = req.query.body;
var payload;
if (body != undefined && body !== '') {
payload = {
notification: {
title: title,
body: body
}
};
} else {
payload = {
notification: {
title: title
}
};
}
var options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
if (to == 'all') {
admin.messaging().sendToTopic(to, payload, options)
.then(function (response) {
res.send(200, 'ok');
})
.catch(function (error) {
res.send(200, 'failed');
});
} else {
admin.messaging().sendToDevice(to, payload, options)
.then(function (response) {
res.send(200, 'ok');
})
.catch(function (error) {
res.send(200, 'failed');
});
}
});
运行推送通知生成时,这里有 URL,
https://MyProjectName.cloudfunctions.net/sendNotification?to=all&title=hello&body=EnterBodyHere
现在,请帮我安排这样的推送通知
localhost:8080:/schedulePush?day=17&month=10&hour=12&minute=22
最佳答案
Cloud Functions 目前没有内置的调度机制。如果您想在特定时间执行某个功能,则需要使用其他一些调度程序。有一个 blog post那是关于这个的,和sample code也讨论了这个问题。
关于android - 谷歌云功能 Node.js Firebase 网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44581665/