LyricTian / jpush-go

极光推送Golang客户端,支持异步发送队列
https://docs.jiguang.cn/
MIT License
13 stars 4 forks source link
jpush-go jpushclient

JPush Golang Client

Build Codecov ReportCard GoDoc License

快速开始

下载安装

$ 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"}

特性

MIT License

Copyright (c) 2018 Lyric