我正在 node.js 中构建命令行应用程序并希望接收 GCM 推送通知(命令行应用程序将与 iOS/Android 应用程序使用的同一组服务交互,因此想使用相同的通知服务)。
鉴于 GCM 可以在 iOS 上使用(因此不是特定于 Android 的)我希望它也可以在 node.js 上使用。
我看过很多关于发送来自 node.js 的推送通知的文章,但还没有找到任何关于在接收端使用 node.js 的文章。
最佳答案
我认为如果你必须向 ios 和 android 发送推送通知,那么 fcm 比 fcm 使用这个更好
router.post('/pushmessage', function (req, res) {
var serverKey = '';//put server key here
var fcm = new FCM(serverKey);
var token = "";// put token here which user you have to send push notification
var message = {
to: token,
collapse_key: 'your_collapse_key',
notification: {title: 'hello', body: 'test'},
data: {my_key: 'my value', contents: "abcv/"}
};
fcm.send(message, function (err, response) {
if (err) {
res.json({status: 0, message: err});
} else {
res.json({status: 1, message: response});
}
});
});
关于node.js - 在 node.js 应用程序中接收 GCM 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41106557/