有什么办法可以发送通知吗FCM
from a node.js
server?
我在文档中没有找到任何有关它的内容。
通过 Firebase Cloud Messaging 发送消息需要调用 HTTP 端点,如发送下游消息的文档 https://firebase.google.com/docs/cloud-messaging/downstream.
像这样简单的事情就可以达到目的:
var request = require('request');
function sendMessageToUser(deviceId, message) {
request({
url: 'https://fcm.googleapis.com/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+'\n'+body);
}
else {
console.log('Done!')
}
});
sendMessageToUser(
"d7x...KJQ",
{ message: 'Hello puf'}
);
更新(2017 年 4 月):您现在还可以在 Cloud Functions for Firebase 中运行与此非常相似的代码。看https://firebase.google.com/docs/functions/use-cases#notify_users_when_something_interesting_happens https://firebase.google.com/docs/functions/use-cases#notify_users_when_something_interesting_happens
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)