如何在不使用 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\"}}"