如何通过 Firebase 从用户向用户发送直接消息?
How to send direct message via Firebase from user to user?
我真的是菜鸟,求指教。
我有 read documentation,据我所知,如果您需要发送直接消息,请按照以下步骤操作:
- 进行认证,最终得到
Firebase TokenId
和
userId
- 将它们发送到您的服务器端并将其存储在数据库中
- 当您要发送消息时,您需要创建
json
并放置
在 topic
text
和 resipent userId
等等...
- 通过 HTTP 将此
json
发送到您的服务器端
- 当服务器检索这个
json
时,它应该使用 Firebase API
在 firebase 中使用随机名称创建新消息块 child
- 最终服务器必须通过我们从消息中获得的 userId 在数据库中找到 recient 用户。
- 服务器通过userId找到当前recient用户后,接下来我们应该
firebase tokenId
发送通知。
- 并发送带有此类数据的配方用户通知 - 新名称
消息块
child
- 收件人将连接到当前的区块并检索数据
这是我理解的概念,如果有错误请指正?
您建议的方法听起来不错。要认识到的最重要的事情是,您需要应用服务器向设备发送下游消息。使用数据库作为应用程序和应用程序服务器之间的通信机制是一种流行的方法。
您也可以使用 Cloud Messaging's upstream capabilities。但我从未尝试过这种方法,因为数据库对我来说工作正常,而且我对学习另一种协议 (XMPP) 没什么兴趣。
您可以在这个 Firebase 博客中阅读我是如何实现它的 post Sending notifications between Android devices with Firebase Database and Cloud Messaging。
我真的是菜鸟,求指教。
我有 read documentation,据我所知,如果您需要发送直接消息,请按照以下步骤操作:
- 进行认证,最终得到
Firebase TokenId
和userId
- 将它们发送到您的服务器端并将其存储在数据库中
- 当您要发送消息时,您需要创建
json
并放置 在topic
text
和resipent userId
等等... - 通过 HTTP 将此
json
发送到您的服务器端 - 当服务器检索这个
json
时,它应该使用 Firebase API 在 firebase 中使用随机名称创建新消息块 - 最终服务器必须通过我们从消息中获得的 userId 在数据库中找到 recient 用户。
- 服务器通过userId找到当前recient用户后,接下来我们应该
firebase tokenId
发送通知。 - 并发送带有此类数据的配方用户通知 - 新名称
消息块
child
- 收件人将连接到当前的区块并检索数据
child
这是我理解的概念,如果有错误请指正?
您建议的方法听起来不错。要认识到的最重要的事情是,您需要应用服务器向设备发送下游消息。使用数据库作为应用程序和应用程序服务器之间的通信机制是一种流行的方法。
您也可以使用 Cloud Messaging's upstream capabilities。但我从未尝试过这种方法,因为数据库对我来说工作正常,而且我对学习另一种协议 (XMPP) 没什么兴趣。
您可以在这个 Firebase 博客中阅读我是如何实现它的 post Sending notifications between Android devices with Firebase Database and Cloud Messaging。