解决方法
通过Firebase发送邮件云消息传递将按照
documentation on sending downstream messages中所述调用HTTP端点.
像这样简单的事情可以做到这一点:
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,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