我正在开发Ionic应用程序,使用Cordova fcm插件来获取设备标记。现在我想从go服务器发送推送通知。如何将go用作fcm服务器?我需要一些实现示例。
我正在开发Ionic应用程序,使用Cordova fcm插件来获取设备标记。现在我想从go服务器发送推送通知。如何将go用作fcm服务器?我需要一些实现示例。
package main
import (
"fmt"
"github.com/NaySoftware/go-fcm"
)
const (
serverKey = "YOUR-KEY"
)
func main() {
var NP fcm.NotificationPayload
NP.Title="hello"
NP.Body="world"
data := map[string]string{
"msg": "Hello World1",
"sum": "Happy Day",
}
ids := []string{
"token1",
}
xds := []string{
"token5",
"token6",
"token7",
}
c := fcm.NewFcmClient(serverKey)
c.NewFcmRegIdsMsg(ids, data)
c.AppendDevices(xds)
c.SetNotificationPayload(&NP)
status, err := c.Send()
if err == nil {
status.PrintResults()
} else {
fmt.Println(err)`enter code here`
}
}
试试这个,很酷。
你的问题比较模糊,你本可以通过简单地谷歌搜索 fcm golang 或类似的内容来回答它。基本上这里是一个库列表:
https://golanglibs.com/top?q=firebase
看起来大部分都有一些示例和文档。 一般来说,我会选择最受欢迎的:
https://github.com/zabawaba99/firego
因为你可以从Github问题中获得灵感,而文档也相当不错。https://godoc.org/gopkg.in/zabawaba99/firego.v1
小提示:如果某个 Go 库似乎缺乏示例/文档,请在该文件夹中运行 godocs(甚至更快的方法是)尝试首先在 GitHub 页面上查找 GoDocs 链接。