$ go get -u -v github.com/LyricTian/jpush-go
push.go
package main
import (
"context"
"fmt"
"github.com/LyricTian/jpush-go"
)
func main() {
jpush.Init(2,
jpush.SetAppKey("b1ccd0dd04ec36b66c75e99f"),
jpush.SetMasterSecret("ed431429270144d3ed53555b"),
)
defer jpush.Terminate()
payload := &jpush.Payload{
Platform: jpush.NewPlatform().All(),
Audience: jpush.NewAudience().All(),
Notification: jpush.NewNotification().SetAlert("通知测试"),
Options: jpush.NewOptions().SetSendNO(1),
}
err := jpush.Push(context.Background(), payload, func(result *jpush.PushResult, err error) {
if err != nil {
panic(err)
}
fmt.Println(result.String())
})
if err != nil {
panic(err)
}
}
$ go build push.go
$ ./push
输出结果
{"sendno":"1","msg_id":"3866336947"}
Copyright (c) 2018 Lyric