【发布时间】:2017-06-16 05:47:45
【问题描述】:
我有一个 Android 应用程序,我可以在其中以 http 格式从我的设备发送推送通知,但现在我想编写一个节点,我希望在特定日期和时间安排推送通知,请有人帮忙我很长一段时间都陷入了这个过程
这是我的节点;
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
【问题讨论】:
标签: android node.js firebase push-notification google-cloud-functions