如何从节点服务器发送 Firebase 云消息传递?

编程入门 行业动态 更新时间:2024-10-14 20:23:24
本文介绍了如何从节点服务器发送 Firebase 云消息传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法从 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 Cloud Messaging 发送消息需要调用 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 云消息传递?

本文发布于:2023-10-11 14:17:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481943.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   消息   服务器   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!