有没有办法从 node.js 服务器发送来自 FCM 的通知?
Is there any way to send notifications from FCM from a node.js server?
我在文档中没有找到任何关于它的信息.
I haven't found anything about it inside documentation.
推荐答案通过 Firebase 云消息传递发送消息需要调用 HTTP 端点,如 关于发送下游消息的文档.
Sending messages through Firebase Cloud Messaging takes calling an HTTP end point as described in the documentation on sending downstream messages.
这样简单的事情就可以解决问题:
Something as simple as this could do the trick:
var request = require('request'); function sendMessageToUser(deviceId, message) { request({ url: 'fcm.googleapis/fcm/send', method: 'POST', headers: { 'Content-Type' :' application/json', 'Authorization': 'key=AI...8o' }, body: JSON.stringify( { "data": { "message": message }, "to" : deviceId } ) }, function(error, response, body) { if (error) { console.error(error, response, body); } else if (response.statusCode >= 400) { console.error('HTTP Error: '+response.statusCode+' - '+response.statusMessage+' '+body); } else { console.log('Done!') } }); sendMessageToUser( "d7x...KJQ", { message: 'Hello puf'} );更新(2017 年 4 月):您现在还可以在 Cloud Functions for Firebase 中运行与此非常相似的代码.请参阅 firebase.google/docs/functions/use-cases#notify_users_when_something_interesting_happens
Update (April 2017): you can now also run code very similar to this in Cloud Functions for Firebase. See firebase.google/docs/functions/use-cases#notify_users_when_something_interesting_happens
更多推荐
如何从节点服务器发送 Firebase 云消息?
发布评论