且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无论如何,是否可以在没有 Firebase 数据库的情况下使用 FCM 从一台设备向另一台设备发送通知?

更新时间:2022-11-03 22:14:16

Firebase Cloud Messaging 不支持直接向设备发送消息.向设备发送消息(称为下游消息)需要您指定 FCM 服务器密钥,并且(顾名思义)该密钥只能在服务器或其他受信任的环境中使用.

Firebase Cloud Messaging does not support directly sending messages to a device. Sending a message to a device (known as a downstream message) requires that you specify the FCM server key, and (as its name implies) that key should only be used on a server, or otherwise trusted environment.

这样做的原因是,拥有项目的 FCM 服务器密钥允许您向该项目中的任何和所有设备发送任何消息,因此在受信任的环境之外提供此密钥将是一个安全问题.

The reason for this is that having the FCM server key for a project allows you to send any message to any and all of the devices in that project, so having this available outside of a trusted environment would be a security concern.

但无需使用 Firebase 数据库发送 FCM 消息.验证这一点的最简单方法是通过命令行 curl 调用发送消息,如下所示:如何在不使用 Firebase 控制台的情况下发送 Firebase 云消息通知? 您还可以实现代码以在其中发送消息Cloud Functions 或您自己喜欢的没有数据库的服务器端环境.您只需将消息发送到函数的目标传递给函数.

But there is no need to use the Firebase Database to send FCM message. The simplest way to verify this is to send a message through a command line curl call, like shown here: How can I send a Firebase Cloud Messaging notification without use the Firebase Console? You can also implement the code to send a message in Cloud Functions or your own favorite server-side environment without a database. You'll just have to pass in the target of where to send the message into the function.