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

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

问题描述

我现在开始使用新的Google服务进行通知, Firebase Cloud Messaging



感谢此代码 https:// github .com / firebase / quickstart-android / tree / master / messaging 我可以从我的 Firebase用户控制台发送通知到我的Android设备。



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

解决方案

消息传递有一个服务器端的API,你可以调用发送消息。请参阅 https://firebase.google.com/docs/cloud-messaging/server。发送一条消息就像使用 curl 来调用一个HTTP终点一样简单。请参阅 https://firebase.google.com/

$ $ p $ curl -X POST - -headerAuthorization:key =< API_ACCESS_KEY> \
--HeaderContent-Type:application / json\
https://fcm.googleapis.com/fcm/send \
-d{\ to\ :\ < YOUR_DEVICE_ID_TOKEN> \,\ notification\:{\ body\:\ Yellow\},\ priority\: 10}


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

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.

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 has a server-side APIs that you can call to send messages. See https://firebase.google.com/docs/cloud-messaging/server.

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\":{\"body\":\"Yellow\"},\"priority\":10}"

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

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