Skip to content

Scorpio69t/jpush-api-golang-client

Repository files navigation

jpush-api-golang-client

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

Overview

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

Install

go get github.com/Scorpio69t/jpush-api-golang-client

Quickstart (Push)

  1. Platform
var pf jpush.Platform
pf.Add(jpush.ANDROID)
pf.Add(jpush.IOS)
pf.Add(jpush.WINPHONE)
// pf.All()
  1. Audience
var at jpush.Audience
at.SetTag([]string{"tag1", "tag2"})
at.SetID([]string{"1", "2"})
// at.All()
  1. 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"
  1. Payload
payload := jpush.NewPayLoad()
payload.SetPlatform(&pf)
payload.SetAudience(&at)
payload.SetNotification(&n)
payload.SetMessage(&m)
  1. 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.

SMS

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.

About

极光推送 Server Golang SDK

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages