vee*_*eer 6 go firebase-cloud-messaging
我正在做 Ionic 应用程序,使用 Cordova fcm 插件我获得了设备令牌。现在我想从 go 服务器发送推送通知。如何使用go作为fcm服务器?我需要一些实施示例。
小智 5
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`
}
}
Run Code Online (Sandbox Code Playgroud)
试试这个,效果很酷。
| 归档时间: |
|
| 查看次数: |
8010 次 |
| 最近记录: |