doujiao7483
2016-11-19 10:11
浏览 406
已采纳

如何使用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

图片转代码服务由CSDN问答提供 功能建议

我正在使用Cordova fcm插件执行离子应用程序,我获取了设备令牌。现在,我想从 go server。请帮助我将go用作fcm服务器。我需要一些实现示例

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 打赏 评论
  • dtu1747 2016-11-24 09:12

    Your question is vague and you could have answered it by simply googling fcm golang or something around the line. Basically here's a list of libraries:

    https://golanglibs.com/top?q=firebase

    It seems like most of them have some examples + docs. I'd generally speaking go with the most popular:

    https://github.com/zabawaba99/firego

    Because you can inspire yourself from github issues and the docs are kind of decent:

    https://godoc.org/gopkg.in/zabawaba99/firego.v1

    Small note, if any go library seems to lack examples/docs try running godocs in the folder or (even faster), try to first look for a GoDocs link on the github page.

    点赞 打赏 评论

相关推荐 更多相似问题