-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ee3f94
commit 4b802cc
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,102 @@ | ||
# jpush-api-golang-client | ||
|
||
|
||
|
||
## 概述 | ||
JPush's Golang client library for accessing JPush APIs. 极光推送的 Golang 版本服务器端 SDK。 | ||
该项目参考[ylywyn](https://github.com/ylywyn/jpush-api-go-client)结合极光推送官方文档而来。(原项目年久失修,有很多新特性都没有提供,本项目旨在将其完善,方便大家使用,后续会持续更新,不足之处欢迎大家指正,谢谢~) | ||
[参考REST API文档](https://docs.jiguang.cn/jpush/server/push/server_overview/) | ||
|
||
**现已支持以下内容** | ||
|
||
- [x] Push API v3 | ||
- [x] Report API v3 | ||
- [ ] Device API v3 | ||
- [x] Schedule API v3 | ||
- [ ] File API v3 | ||
- [ ] Image API v3 | ||
- [ ] Admin API v3 | ||
|
||
## 使用 | ||
`go get github.com/Scorpio69t/jpush-api-golang-client` | ||
|
||
## 推送流程 | ||
|
||
|
||
|
||
### 1.构建要推送的平台:jpush.Platform | ||
```go | ||
// Platform: all | ||
var pf jpush.Platform | ||
pf.Add(jpush.ANDROID) | ||
pf.Add(jpush.IOS) | ||
pf.Add(jpush.WINPHONE) | ||
// pf.All() | ||
``` | ||
|
||
|
||
|
||
### 2.构建接收目标:jpush.Audience | ||
|
||
```go | ||
// Audience: tag | ||
var at jpush.Audience | ||
s := []string{"tag1", "tag2"} | ||
at.SetTag(s) | ||
id := []string{"1", "2"} | ||
at.SetID(id) | ||
// at.All() | ||
``` | ||
|
||
|
||
|
||
### 3.构建通知:jpush.Notification 或者消息:jpush.Message | ||
|
||
```go | ||
// Notification | ||
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"}) | ||
|
||
// Message | ||
var m jpush.Message | ||
m.MsgContent = "This is a message" | ||
m.Title = "Hello" | ||
``` | ||
|
||
|
||
|
||
### 4.构建消息负载:jpush.PayLoad | ||
|
||
```go | ||
// PayLoad | ||
payload := jpush.NewPayLoad() | ||
payload.SetPlatform(&pf) | ||
payload.SetAudience(&at) | ||
payload.SetNotification(&n) | ||
payload.SetMessage(&m) | ||
``` | ||
|
||
|
||
|
||
### 5.构建JPushClient,发送推送 | ||
|
||
```go | ||
// Send | ||
c := jpush.NewJPushClient("appKey", "masterSecret") // appKey and masterSecret can be gotten 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) | ||
} | ||
``` | ||
|
||
### 6.详细例子见examples | ||
|