Heads-up: this library is being actively refactored to modernize its APIs and structure. Expect changes to land soon; keep an eye on releases/changelog.
English is the default README. 中文说明请见 README.zh.md。
Golang SDK for JPush REST APIs (push, schedule, report, CID, SMS). The current codebase mirrors the official docs with light helpers for HTTP requests and payload builders.
Supported today:
- ✅ Push API v3
- ✅ Report API v3
- ✅ Schedule API v3
- ✅ SMS API v1 (template SMS send)
- ⏳ Not yet: Device API v3, File API v3, Image API v3, Admin API v3
go get github.com/Scorpio69t/jpush-api-golang-client- Platform
var pf jpush.Platform
pf.Add(jpush.ANDROID)
pf.Add(jpush.IOS)
pf.Add(jpush.WINPHONE)
// pf.All()- Audience
var at jpush.Audience
at.SetTag([]string{"tag1", "tag2"})
at.SetID([]string{"1", "2"})
// at.All()- Notification or Message
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"})
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") // obtain from 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)
}See examples/ for full push and CID samples.
Template SMS send is available (see sms_test.go for an end-to-end example). Fill your own appKey/masterSecret and template params before running tests.