Scorpio69t/jpush-api-golang-client
Fork: 16 Star: 29 (更新于 2024-11-06 02:27:00)
license: MIT
Language: Go .
极光推送 Server Golang SDK
最后发布版本: v1.1.0 ( 2024-04-13 08:45:24)
jpush-api-golang-client
概述
JPush's Golang client library for accessing JPush APIs. 极光推送的 Golang 版本服务器端 SDK。 该项目参考ylywyn结合极光推送官方文档而来。(原项目年久失修,有很多新特性都没有提供,本项目旨在将其完善,方便大家使用,后续会持续更新,不足之处欢迎大家指正,谢谢~)
极光短信
短信这边暂时只实现了发送单条模板短信
现已支持以下内容
- Push API v3
- Report API v3
- Device API v3
- Schedule API v3
- File API v3
- Image API v3
- Admin API v3
- SMS API v1
使用
go get github.com/Scorpio69t/jpush-api-golang-client
推送流程
1.构建要推送的平台:jpush.Platform
// Platform: all
var pf jpush.Platform
pf.Add(jpush.ANDROID)
pf.Add(jpush.IOS)
pf.Add(jpush.WINPHONE)
// pf.All()
2.构建接收目标:jpush.Audience
// 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
// 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
// PayLoad
payload := jpush.NewPayLoad()
payload.SetPlatform(&pf)
payload.SetAudience(&at)
payload.SetNotification(&n)
payload.SetMessage(&m)
5.构建JPushClient,发送推送
// 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
发送短信参见sms_test中的代码
最近版本更新:(数据更新于 2024-09-01 09:30:06)
2024-04-13 08:45:24 v1.1.0
2023-05-31 20:31:16 v1.0.1
2022-01-07 14:52:50 v1.0.0
2022-01-05 20:56:53 v0.0.3
2022-01-04 10:05:03 v0.0.2
2021-12-31 17:37:17 v0.0.1
Scorpio69t/jpush-api-golang-client同语言 Go最近更新仓库
2024-11-05 08:55:31 XTLS/Xray-core
2024-11-05 00:03:47 SagerNet/sing-box
2024-11-04 20:34:19 Permify/permify
2024-11-04 15:07:27 containerd/containerd
2024-11-03 20:10:56 flipped-aurora/gin-vue-admin
2024-11-03 00:46:25 dolthub/dolt