doujiao7483 2016-11-19 10:11 采纳率: 0%
浏览 592
已采纳

如何使用Golang FCM服务器发送FCM推送通知

i am doing ionic apps, using cordova fcm plugin i get the device token.Now i want send the push notification from go server.please help me how use go as the fcm server.I need some implementation example

  • 写回答

2条回答 默认 最新

  • doulubashang6936 2016-11-26 11:29
    关注
        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`
            }
    
        }
    

    try this it works cool.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?