这是JPush REST API 的 go 版本封装开发包,仅支持最新的REST API v3功能。 REST API 文档:http://docs.jpush.cn/display/dev/Push-API-v3
go get github.com/ylywyn/jpush-api-go-client
//Platform
var pf jpushclient.Platform
pf.Add(jpushclient.ANDROID)
pf.Add(jpushclient.IOS)
pf.Add(jpushclient.WINPHONE)
//pf.All()
//Audience
var ad jpushclient.Audience
s := []string{"t1", "t2", "t3"}
ad.SetTag(s)
id := []string{"1", "2", "3"}
ad.SetID(id)
//ad.All()
//Notice
var notice jpushclient.Notice
notice.SetAlert("alert_test")
notice.SetAndroidNotice(&jpushclient.AndroidNotice{Alert: "AndroidNotice"})
notice.SetIOSNotice(&jpushclient.IOSNotice{Alert: "IOSNotice"})
notice.SetWinPhoneNotice(&jpushclient.WinPhoneNotice{Alert: "WinPhoneNotice"})
//jpushclient.Message
var msg jpushclient.Message
msg.Title = "Hello"
msg.Content = "你是ylywn"
payload := jpushclient.NewPushPayLoad()
payload.SetPlatform(&pf)
payload.SetAudience(&ad)
payload.SetMessage(&msg)
payload.SetNotice(¬ice)
c := jpushclient.NewPushClient(secret, appKey)
r, err := c.Send(bytes)
if err != nil {
fmt.Printf("err:%s", err.Error())
} else {
fmt.Printf("ok:%s", r)
}
package main
import (
"fmt"
"github.com/ylywyn/jpush-api-go-client"
)
const (
appKey = "you jpush appkey"
secret = "you jpush secret"
)
func main() {
//Platform
var pf jpushclient.Platform
pf.Add(jpushclient.ANDROID)
pf.Add(jpushclient.IOS)
pf.Add(jpushclient.WINPHONE)
//pf.All()
//Audience
var ad jpushclient.Audience
s := []string{"1", "2", "3"}
ad.SetTag(s)
ad.SetAlias(s)
ad.SetID(s)
//ad.All()
//Notice
var notice jpushclient.Notice
notice.SetAlert("alert_test")
notice.SetAndroidNotice(&jpushclient.AndroidNotice{Alert: "AndroidNotice"})
notice.SetIOSNotice(&jpushclient.IOSNotice{Alert: "IOSNotice"})
notice.SetWinPhoneNotice(&jpushclient.WinPhoneNotice{Alert: "WinPhoneNotice"})
var msg jpushclient.Message
msg.Title = "Hello"
msg.Content = "你是ylywn"
payload := jpushclient.NewPushPayLoad()
payload.SetPlatform(&pf)
payload.SetAudience(&ad)
payload.SetMessage(&msg)
payload.SetNotice(¬ice)
bytes, _ := payload.ToBytes()
fmt.Printf("%s\r\n", string(bytes))
//push
c := jpushclient.NewPushClient(secret, appKey)
str, err := c.Send(bytes)
if err != nil {
fmt.Printf("err:%s", err.Error())
} else {
fmt.Printf("ok:%s", str)
}
}
官网
https://www.engagelab.com/zh_CN
在线文档
https://jiguang-docs.yuque.com/staff-mg3p4r/vc4ysl/dl7ez50kztn6kc6l
package main
import (
"fmt"
jpushclient "github.com/hub500/jpush-api-engagelab"
)
const (
appKey = "your key"
secret = "your secret"
)
func main() {
// Platform
var pf jpushclient.Platform
// pf.Add(jpushclient.ANDROID)
// pf.Add(jpushclient.IOS)
pf.All()
// Audience
var ad jpushclient.Audience
// s := []string{"1", "2", "3"}
// ad.SetTag(s)
// ad.SetAlias(s)
// ad.SetID([]string{"120c83f76036354eee9"})
ad.All()
// Notice
var notice jpushclient.Notice
notice.SetAlert("Hi, Push!")
notice.SetAndroidNotice(jpushclient.NewAndroidNotice("Hi, Push!", "Send to Android"))
notice.SetIOSNotice(jpushclient.NewIOSNotice("IOSNotice"))
var msg jpushclient.Message
msg.Title = "push msg title"
msg.Content = "push msg content"
payload := jpushclient.NewPushPayLoad()
payload.SetRequestId("abc123")
payload.SetPlatform(&pf)
payload.SetAudience(&ad)
// Disable push notification and messages at the same time
// payload.SetMessage(&msg)
payload.SetNotice(¬ice)
bytes, _ := payload.ToBytes()
fmt.Printf("%s\r\n", string(bytes))
// push
c := jpushclient.NewPushClient(secret, appKey)
fmt.Println(c)
fmt.Println()
str, err := c.Send(bytes)
if err != nil {
fmt.Printf("err:%s", err.Error())
} else {
fmt.Printf("ok:%s", str)
}
}