极光推送 Golang 版本服务器端 SDK
JPush's Golang client library for accessing JPush APIs. 极光推送 Golang 版本服务器端 SDK。 该项目参考ylywyn和使用Scorpio69t结合极光推送官方文档而来。(本项目旨在将其完善,方便大家使用,后续会持续更新,不足之处欢迎大家指正,谢谢~) 参考REST API文档
现已支持以下内容
- Push API v3
- Report API v3
- Device API v3
- Schedule API v3
- File API v3
- Image API v3
- Admin API v3
go get github.com/RuiecLab/jpush-golang
// Platform: all
var pf jpush.Platform
pf.Add(jpush.ANDROID)
pf.Add(jpush.IOS)
pf.Add(jpush.WINPHONE)
// pf.All()
// Audience: tag
var at jpush.Audience
s := []string{"tag1", "tag2"}
at.SetTag(s)
id := []string{"1", "2"}
at.SetID(id)
// at.All()
// Notification
var n jpush.Notification
n.SetAlert("alert")
n.SetAndroid(&jpush.AndroidNotification{Alert: "alert", Title: "title"})
n.SetIos(&jpush.IosNotification{Alert: "alert", Badge: 1})
n.SetWinPhone(&jpush.WinPhoneNotification{Alert: "alert"})
// Message
var m jpush.Message
m.MsgContent = "This is a message"
m.Title = "Hello"
// PayLoad
payload := jpush.NewPayLoad()
payload.SetPlatform(&pf)
payload.SetAudience(&at)
payload.SetNotification(&n)
payload.SetMessage(&m)
// Send
c := jpush.NewJPushClient("appKey", "masterSecret") // // appKey和masterSecret可以从 https://www.jiguang.cn/ 官网获取。
data, err := payload.Bytes()
if err != nil {
panic(err)
}
res, err := c.Push(data)
if err != nil {
fmt.Printf("%+v\n", err)
} else {
fmt.Printf("ok: %v\n", res)
}