diff --git a/.gitignore b/.gitignore index daf913b..46fe173 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,5 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof +api.push +lastupdate.tmp +*.tar.gz +.com.apple* +.idea diff --git a/README.md b/README.md index d09a314..50df306 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ JPush API Go Client ==================== -[![GoDoc](https://godoc.org/github.com/DeanThompson/jpush-api-go-client?status.svg)](https://godoc.org/github.com/DeanThompson/jpush-api-go-client) [![Build Status](https://travis-ci.org/DeanThompson/jpush-api-go-client.svg?branch=master)](https://travis-ci.org/DeanThompson/jpush-api-go-client) +[![GoDoc](https://godoc.org/github.com/Aqiling/jpush-api-go-client?status.svg)](https://godoc.org/github.com/Aqiling/jpush-api-go-client) [![Build Status](https://travis-ci.org/Aqiling/jpush-api-go-client.svg?branch=master)](https://travis-ci.org/Aqiling/jpush-api-go-client) # 概述 @@ -14,7 +14,7 @@ JPush API Go Client 使用 go get 安装,无任何第三方依赖: ```sh -go get github.com/DeanThompson/jpush-api-go-client +go get github.com/Aqiling/jpush-api-go-client ``` # 使用方法 @@ -22,7 +22,7 @@ go get github.com/DeanThompson/jpush-api-go-client ## 1. 创建 JPushClient ```go -import "github.com/DeanThompson/jpush-api-go-client" +import "github.com/Aqiling/jpush-api-go-client" const ( appKey = "" @@ -37,7 +37,7 @@ jclient := jpush.NewJPushClient(appKey, masterSecret) 与推送有关的数据结构都在 push 包里 ```go -import "github.com/DeanThompson/jpush-api-go-client/push" +import "github.com/Aqiling/jpush-api-go-client/push" ``` ### 2.1 创建 Platform 对象 @@ -187,4 +187,5 @@ if err != nil { ## 4. 更多示例 + 更多例子可以看这里:[jpush_test.go](jpush_test.go) diff --git a/common/structures.go b/common/structures.go index 0142a67..0f407c8 100644 --- a/common/structures.go +++ b/common/structures.go @@ -45,6 +45,8 @@ type ResponseBase struct { // 频率限制相关 RateLimitInfo *RateLimitInfo + MsgId interface{} `json:"msg_id"` + // 错误相关 Error *ErrorResult `json:"error"` } diff --git a/common/util.go b/common/util.go index 0ec9097..7d151af 100644 --- a/common/util.go +++ b/common/util.go @@ -20,7 +20,7 @@ func RespToJson(resp *http.Response, dest interface{}) error { if err != nil { return err } - println(string(body)) + //println(string(body)) return json.Unmarshal(body, &dest) } diff --git a/device/alias.go b/device/alias.go index 8c268b5..ffb664c 100644 --- a/device/alias.go +++ b/device/alias.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "github.com/DeanThompson/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) type GetAliasUsersResult struct { diff --git a/device/device.go b/device/device.go index 16520c8..c1bbf7d 100644 --- a/device/device.go +++ b/device/device.go @@ -5,7 +5,7 @@ import ( "fmt" "net/http" - "github.com/DeanThompson/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) type QueryDeviceResult struct { diff --git a/device/tag.go b/device/tag.go index 01aaf26..02a594c 100644 --- a/device/tag.go +++ b/device/tag.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "github.com/DeanThompson/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) // 查询标签列表请求结果 diff --git a/httplib/http.go b/httplib/http.go index ed25915..1f2debc 100644 --- a/httplib/http.go +++ b/httplib/http.go @@ -103,6 +103,7 @@ func (c *HTTPClient) PostForm(url string, data map[string]interface{}, headers m func (c *HTTPClient) PostJson(url string, data interface{}, headers map[string]string) (*http.Response, error) { payload, err := json.Marshal(data) + if err != nil { return nil, err } diff --git a/jpush.go b/jpush.go index 82cb694..d072630 100644 --- a/jpush.go +++ b/jpush.go @@ -5,11 +5,11 @@ import ( "strconv" "strings" - "github.com/DeanThompson/jpush-api-go-client/common" - "github.com/DeanThompson/jpush-api-go-client/device" - "github.com/DeanThompson/jpush-api-go-client/httplib" - "github.com/DeanThompson/jpush-api-go-client/push" - "github.com/DeanThompson/jpush-api-go-client/report" + "github.com/jukylin/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/device" + "github.com/jukylin/jpush-api-go-client/httplib" + "github.com/jukylin/jpush-api-go-client/push" + "github.com/jukylin/jpush-api-go-client/report" ) // JPush 的 Golang 推送客户端 diff --git a/jpush_test.go b/jpush_test.go index 5e57ef9..ca3eb9a 100644 --- a/jpush_test.go +++ b/jpush_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" - "github.com/DeanThompson/jpush-api-go-client/device" - "github.com/DeanThompson/jpush-api-go-client/push" + "github.com/jukylin/jpush-api-go-client/device" + "github.com/jukylin/jpush-api-go-client/push" ) const ( diff --git a/push/audience.go b/push/audience.go index df0e917..c32ceac 100644 --- a/push/audience.go +++ b/push/audience.go @@ -1,6 +1,6 @@ package push -import "github.com/DeanThompson/jpush-api-go-client/common" +import "github.com/jukylin/jpush-api-go-client/common" // 推送设备对象,表示一条推送可以被推送到哪些设备列表。 // 确认推送设备对象,JPush 提供了多种方式,比如:别名、标签、注册ID、分群、广播等。 diff --git a/push/notification.go b/push/notification.go index 18ca6e3..86737cc 100644 --- a/push/notification.go +++ b/push/notification.go @@ -3,7 +3,7 @@ package push import ( "encoding/json" - "github.com/DeanThompson/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) // “通知”对象,是一条推送的实体内容对象之一(另一个是“消息”) @@ -27,7 +27,7 @@ func (n *Notification) Validate() error { // 平台通用的通知属性 type platformNotification struct { - Alert string `json:"alert"` // required + Alert interface{} `json:"alert"` // required Extras map[string]interface{} `json:"extras,omitempty"` } @@ -44,6 +44,10 @@ type AndroidNotification struct { Title string `json:"title,omitempty"` BuilderId int `json:"builder_id,omitempty"` + Style int `json:"style,omitempty"` + BigText string `json:"big_text,omitempty"` + Inbox string `json:"inbox,omitempty"` + BigPicPath string `json:"big_pic_path,omitempty"` } func NewAndroidNotification(alert string) *AndroidNotification { @@ -60,9 +64,10 @@ type IosNotification struct { Badge int `json:"badge,omitempty"` ContentAvailable bool `json:"content-available,omitempty"` Category string `json:"category,omitempty"` + MutableContent bool `json:"mutable-content,omitempty"` } -func NewIosNotification(alert string) *IosNotification { +func NewIosNotification(alert map[string]string) *IosNotification { a := &IosNotification{} a.Alert = alert return a diff --git a/push/options.go b/push/options.go index 9307b38..12563ec 100644 --- a/push/options.go +++ b/push/options.go @@ -1,6 +1,6 @@ package push -import "github.com/DeanThompson/jpush-api-go-client/common" +import "github.com/jukylin/jpush-api-go-client/common" // 推送可选项。 type Options struct { diff --git a/push/platform.go b/push/platform.go index da8c9fe..c9f195b 100644 --- a/push/platform.go +++ b/push/platform.go @@ -1,6 +1,6 @@ package push -import "github.com/DeanThompson/jpush-api-go-client/common" +import "github.com/jukylin/jpush-api-go-client/common" type Platform struct { value []string diff --git a/push/platform_test.go b/push/platform_test.go index 5f272ce..5a2753b 100644 --- a/push/platform_test.go +++ b/push/platform_test.go @@ -3,7 +3,7 @@ package push import ( "testing" - "github.com/DeanThompson/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) func Test_has(t *testing.T) { diff --git a/push/push.go b/push/push.go index 0ef315b..b722fd8 100644 --- a/push/push.go +++ b/push/push.go @@ -4,8 +4,9 @@ import ( "encoding/json" "fmt" "net/http" + "strconv" - "github.com/DeanThompson/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) type Validator interface { @@ -88,6 +89,9 @@ type PushResult struct { // 失败: {"msg_id": 1035959738, "error": {"message": "app_key does not exist", "code": 1008}} func (pr *PushResult) FromResponse(resp *http.Response) error { pr.ResponseBase = common.NewResponseBase(resp) + if pr.ResponseBase.MsgId != nil { + pr.MsgId = strconv.FormatFloat(pr.ResponseBase.MsgId.(float64), 'g', 64, 64) + } if !pr.Ok() { return nil } diff --git a/report/report.go b/report/report.go index aab2917..0a64eec 100644 --- a/report/report.go +++ b/report/report.go @@ -5,7 +5,7 @@ import ( "fmt" "net/http" - "github.com/DeanThompson/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) type ReceivedReportNode struct {