From 77daace2dd33ef301e50b06344e625421c220999 Mon Sep 17 00:00:00 2001 From: Aqiling <742161455@qq.com> Date: Mon, 13 Mar 2017 11:47:15 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=B7=BB=E5=8A=A0msg=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++++---- common/structures.go | 2 ++ common/util.go | 2 +- device/alias.go | 2 +- device/device.go | 2 +- device/tag.go | 2 +- jpush.go | 10 +++++----- jpush_test.go | 4 ++-- push/audience.go | 2 +- push/notification.go | 2 +- push/options.go | 2 +- push/platform.go | 2 +- push/platform_test.go | 2 +- push/push.go | 6 +++++- report/report.go | 2 +- 15 files changed, 29 insertions(+), 22 deletions(-) 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..237e2cb 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/Aqiling/jpush-api-go-client/common" ) type GetAliasUsersResult struct { diff --git a/device/device.go b/device/device.go index 16520c8..378efca 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/Aqiling/jpush-api-go-client/common" ) type QueryDeviceResult struct { diff --git a/device/tag.go b/device/tag.go index 01aaf26..d9f24a2 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/Aqiling/jpush-api-go-client/common" ) // 查询标签列表请求结果 diff --git a/jpush.go b/jpush.go index 82cb694..26023db 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/Aqiling/jpush-api-go-client/common" + "github.com/Aqiling/jpush-api-go-client/device" + "github.com/Aqiling/jpush-api-go-client/httplib" + "github.com/Aqiling/jpush-api-go-client/push" + "github.com/Aqiling/jpush-api-go-client/report" ) // JPush 的 Golang 推送客户端 diff --git a/jpush_test.go b/jpush_test.go index 5e57ef9..c1b93b0 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/Aqiling/jpush-api-go-client/device" + "github.com/Aqiling/jpush-api-go-client/push" ) const ( diff --git a/push/audience.go b/push/audience.go index df0e917..7f11e2b 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/Aqiling/jpush-api-go-client/common" // 推送设备对象,表示一条推送可以被推送到哪些设备列表。 // 确认推送设备对象,JPush 提供了多种方式,比如:别名、标签、注册ID、分群、广播等。 diff --git a/push/notification.go b/push/notification.go index 18ca6e3..45c75fe 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/Aqiling/jpush-api-go-client/common" ) // “通知”对象,是一条推送的实体内容对象之一(另一个是“消息”) diff --git a/push/options.go b/push/options.go index 9307b38..ad17890 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/Aqiling/jpush-api-go-client/common" // 推送可选项。 type Options struct { diff --git a/push/platform.go b/push/platform.go index da8c9fe..84fe2e0 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/Aqiling/jpush-api-go-client/common" type Platform struct { value []string diff --git a/push/platform_test.go b/push/platform_test.go index 5f272ce..8ed5f62 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/Aqiling/jpush-api-go-client/common" ) func Test_has(t *testing.T) { diff --git a/push/push.go b/push/push.go index 0ef315b..82ba2e5 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/Aqiling/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..12c0797 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/Aqiling/jpush-api-go-client/common" ) type ReceivedReportNode struct { From dd8ab778fac2f171bfc304ff64dd6683b583e691 Mon Sep 17 00:00:00 2001 From: "742161455@qq.com" <742161455@qq.com> Date: Tue, 8 Aug 2017 10:53:37 +0800 Subject: [PATCH 2/8] rename to jukylin by zjh --- .gitignore | 29 +++++------------------------ device/alias.go | 2 +- device/device.go | 2 +- device/tag.go | 2 +- jpush.go | 10 +++++----- jpush_test.go | 4 ++-- push/audience.go | 2 +- push/notification.go | 2 +- push/options.go | 2 +- push/platform.go | 2 +- push/platform_test.go | 2 +- push/push.go | 2 +- report/report.go | 2 +- 13 files changed, 22 insertions(+), 41 deletions(-) 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/device/alias.go b/device/alias.go index 237e2cb..ffb664c 100644 --- a/device/alias.go +++ b/device/alias.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "github.com/Aqiling/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 378efca..c1bbf7d 100644 --- a/device/device.go +++ b/device/device.go @@ -5,7 +5,7 @@ import ( "fmt" "net/http" - "github.com/Aqiling/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 d9f24a2..02a594c 100644 --- a/device/tag.go +++ b/device/tag.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "github.com/Aqiling/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) // 查询标签列表请求结果 diff --git a/jpush.go b/jpush.go index 26023db..d072630 100644 --- a/jpush.go +++ b/jpush.go @@ -5,11 +5,11 @@ import ( "strconv" "strings" - "github.com/Aqiling/jpush-api-go-client/common" - "github.com/Aqiling/jpush-api-go-client/device" - "github.com/Aqiling/jpush-api-go-client/httplib" - "github.com/Aqiling/jpush-api-go-client/push" - "github.com/Aqiling/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 c1b93b0..ca3eb9a 100644 --- a/jpush_test.go +++ b/jpush_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" - "github.com/Aqiling/jpush-api-go-client/device" - "github.com/Aqiling/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 7f11e2b..c32ceac 100644 --- a/push/audience.go +++ b/push/audience.go @@ -1,6 +1,6 @@ package push -import "github.com/Aqiling/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 45c75fe..f025939 100644 --- a/push/notification.go +++ b/push/notification.go @@ -3,7 +3,7 @@ package push import ( "encoding/json" - "github.com/Aqiling/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) // “通知”对象,是一条推送的实体内容对象之一(另一个是“消息”) diff --git a/push/options.go b/push/options.go index ad17890..12563ec 100644 --- a/push/options.go +++ b/push/options.go @@ -1,6 +1,6 @@ package push -import "github.com/Aqiling/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 84fe2e0..c9f195b 100644 --- a/push/platform.go +++ b/push/platform.go @@ -1,6 +1,6 @@ package push -import "github.com/Aqiling/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 8ed5f62..5a2753b 100644 --- a/push/platform_test.go +++ b/push/platform_test.go @@ -3,7 +3,7 @@ package push import ( "testing" - "github.com/Aqiling/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 82ba2e5..b722fd8 100644 --- a/push/push.go +++ b/push/push.go @@ -6,7 +6,7 @@ import ( "net/http" "strconv" - "github.com/Aqiling/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) type Validator interface { diff --git a/report/report.go b/report/report.go index 12c0797..0a64eec 100644 --- a/report/report.go +++ b/report/report.go @@ -5,7 +5,7 @@ import ( "fmt" "net/http" - "github.com/Aqiling/jpush-api-go-client/common" + "github.com/jukylin/jpush-api-go-client/common" ) type ReceivedReportNode struct { From 25b2e346765754e7d13ed9ca478055736d6e935a Mon Sep 17 00:00:00 2001 From: "742161455@qq.com" <742161455@qq.com> Date: Tue, 8 Aug 2017 12:00:46 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=AE=89=E5=8D=93=E6=96=B0=E7=89=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httplib/http.go | 2 ++ push/notification.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/httplib/http.go b/httplib/http.go index ed25915..3df12c1 100644 --- a/httplib/http.go +++ b/httplib/http.go @@ -12,6 +12,7 @@ import ( "strconv" "strings" "time" + "fmt" ) // HTTP methods we support @@ -103,6 +104,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) + fmt.Println(string(payload)) if err != nil { return nil, err } diff --git a/push/notification.go b/push/notification.go index f025939..3b84f97 100644 --- a/push/notification.go +++ b/push/notification.go @@ -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 { From a735276efb67c4c031dcc64742f8796efeb6276a Mon Sep 17 00:00:00 2001 From: 742161455 <742161455@qq.com> Date: Wed, 9 Aug 2017 10:08:12 +0800 Subject: [PATCH 4/8] =?UTF-8?q?ios10=E6=8E=A8=E9=80=81=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- push/notification.go | 1 + 1 file changed, 1 insertion(+) diff --git a/push/notification.go b/push/notification.go index 3b84f97..0cddabf 100644 --- a/push/notification.go +++ b/push/notification.go @@ -64,6 +64,7 @@ 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 { From 3478aa13f6609ee9cc649ad0e48916cb9c2410a6 Mon Sep 17 00:00:00 2001 From: 742161455 <742161455@qq.com> Date: Fri, 11 Aug 2017 19:20:26 +0800 Subject: [PATCH 5/8] =?UTF-8?q?ios10=E6=8E=A8=E9=80=81=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- push/notification.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/push/notification.go b/push/notification.go index 0cddabf..d4a1720 100644 --- a/push/notification.go +++ b/push/notification.go @@ -64,7 +64,7 @@ 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"` + MutableContent bool `json:"mutable-content,omitempty"` } func NewIosNotification(alert string) *IosNotification { From 35edc9d2d7e11045c4c533f6a0f8c7c1ec7581a3 Mon Sep 17 00:00:00 2001 From: 742161455 <742161455@qq.com> Date: Fri, 11 Aug 2017 19:23:23 +0800 Subject: [PATCH 6/8] =?UTF-8?q?ios10=E6=8E=A8=E9=80=81=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httplib/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httplib/http.go b/httplib/http.go index 3df12c1..0a7102b 100644 --- a/httplib/http.go +++ b/httplib/http.go @@ -104,7 +104,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) - fmt.Println(string(payload)) + if err != nil { return nil, err } From 2d305f00fdf628c702b50311ce49e01b17741586 Mon Sep 17 00:00:00 2001 From: 742161455 <742161455@qq.com> Date: Fri, 11 Aug 2017 19:27:12 +0800 Subject: [PATCH 7/8] remove fmt --- httplib/http.go | 1 - 1 file changed, 1 deletion(-) diff --git a/httplib/http.go b/httplib/http.go index 0a7102b..1f2debc 100644 --- a/httplib/http.go +++ b/httplib/http.go @@ -12,7 +12,6 @@ import ( "strconv" "strings" "time" - "fmt" ) // HTTP methods we support From bf481cd6c10ad4f51e56970195a14aa318837fad Mon Sep 17 00:00:00 2001 From: 742161455 <742161455@qq.com> Date: Mon, 14 Aug 2017 17:24:32 +0800 Subject: [PATCH 8/8] =?UTF-8?q?ios=E5=89=AF=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- push/notification.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/push/notification.go b/push/notification.go index d4a1720..86737cc 100644 --- a/push/notification.go +++ b/push/notification.go @@ -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"` } @@ -67,7 +67,7 @@ type IosNotification struct { 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