Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Feature/uri activity #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新增的 ignore 规则,请添加到末尾,保留原来的规则

lastupdate.tmp
*.tar.gz
.com.apple*
.idea
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果要 merge 进来,请把文档地址恢复到 github.com/DeanThompson, 下同

[![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)

# 概述

Expand All @@ -14,15 +14,15 @@ 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
```

# 使用方法

## 1. 创建 JPushClient

```go
import "github.com/DeanThompson/jpush-api-go-client"
import "github.com/Aqiling/jpush-api-go-client"

const (
appKey = ""
Expand All @@ -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 对象
Expand Down Expand Up @@ -187,4 +187,5 @@ if err != nil {

## 4. 更多示例


更多例子可以看这里:[jpush_test.go](jpush_test.go)
2 changes: 2 additions & 0 deletions common/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type ResponseBase struct {
// 频率限制相关
RateLimitInfo *RateLimitInfo

MsgId interface{} `json:"msg_id"`

// 错误相关
Error *ErrorResult `json:"error"`
}
Expand Down
2 changes: 1 addition & 1 deletion common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion device/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/http"

"github.com/DeanThompson/jpush-api-go-client/common"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请修复 import 地址,下同

"github.com/jukylin/jpush-api-go-client/common"
)

type GetAliasUsersResult struct {
Expand Down
2 changes: 1 addition & 1 deletion device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion device/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/http"

"github.com/DeanThompson/jpush-api-go-client/common"
"github.com/jukylin/jpush-api-go-client/common"
)

// 查询标签列表请求结果
Expand Down
1 change: 1 addition & 0 deletions httplib/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions jpush.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 推送客户端
Expand Down
4 changes: 2 additions & 2 deletions jpush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion push/audience.go
Original file line number Diff line number Diff line change
@@ -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、分群、广播等。
Expand Down
11 changes: 8 additions & 3 deletions push/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

// “通知”对象,是一条推送的实体内容对象之一(另一个是“消息”)
Expand All @@ -27,7 +27,7 @@ func (n *Notification) Validate() error {

// 平台通用的通知属性
type platformNotification struct {
Alert string `json:"alert"` // required
Alert interface{} `json:"alert"` // required
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了 Alert 的类型,需要测试

Extras map[string]interface{} `json:"extras,omitempty"`
}

Expand All @@ -44,6 +44,10 @@ type AndroidNotification struct {

Title string `json:"title,omitempty"`
BuilderId int `json:"builder_id,omitempty"`
Style int `json:"style,omitempty"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

提交代码前请执行 gofmt

BigText string `json:"big_text,omitempty"`
Inbox string `json:"inbox,omitempty"`
BigPicPath string `json:"big_pic_path,omitempty"`
}

func NewAndroidNotification(alert string) *AndroidNotification {
Expand All @@ -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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了函数签名,需要测试

a := &IosNotification{}
a.Alert = alert
return a
Expand Down
2 changes: 1 addition & 1 deletion push/options.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion push/platform.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion push/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down