如何在不使用 Firebase 控制台的情况下发送 Firebase 云消息传递通知? [英] How can I send a Firebase Cloud Messaging notification without use the Firebase Console?

查看:48
本文介绍了如何在不使用 Firebase 控制台的情况下发送 Firebase 云消息传递通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用用于通知的新 Google 服务 Firebase Cloud Messaging.

I'm starting with the new Google service for the notifications, Firebase Cloud Messaging.

感谢这段代码https://github.com/firebase/quickstart-android/tree/master/messaging 我能够从我的 Firebase 用户控制台向我的 Android 设备发送通知.

Thanks to this code https://github.com/firebase/quickstart-android/tree/master/messaging I was able to send notifications from my Firebase User Console to my Android device.

是否有任何 API 或方法可以在不使用 Firebase 控制台的情况下发送通知?我的意思是,例如,一个 PHP API 或类似的东西,可以直接从我自己的服务器创建通知.

Is there any API or way to send a notification without use the Firebase console? I mean, for example, a PHP API or something like that, to create notifications from my own server directly.

推荐答案

Firebase Cloud Messaging 有一个服务器端 API,您可以调用它来发送消息.请参阅 https://firebase.google.com/docs/cloud-messaging/server.

Firebase Cloud Messaging has a server-side APIs that you can call to send messages. See https://firebase.google.com/docs/cloud-messaging/server.

发送消息可以像使用 curl 调用 HTTP 端点一样简单.请参阅 https://firebase.google.com/docs/cloud-messaging/server#implementing-http-connection-server-protocol

Sending a message can be as simple as using curl to call a HTTP end-point. See https://firebase.google.com/docs/cloud-messaging/server#implementing-http-connection-server-protocol

curl -X POST --header "Authorization: key=<API_ACCESS_KEY>" \
    --Header "Content-Type: application/json" \
    https://fcm.googleapis.com/fcm/send \
    -d "{\"to\":\"<YOUR_DEVICE_ID_TOKEN>\",\"notification\":{\"title\":\"Hello\",\"body\":\"Yellow\"}}"

这篇关于如何在不使用 Firebase 控制台的情况下发送 Firebase 云消息传递通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆