Skip to content

Commit 3bba170

Browse files
committed
增加送达统计接口
1 parent 26ecf5a commit 3bba170

File tree

7 files changed

+93
-16
lines changed

7 files changed

+93
-16
lines changed

Diff for: common/consts.go

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const (
99

1010
push_host = "https://api.jpush.cn"
1111
device_host = "https://device.jpush.cn"
12+
report_host = "https://report.jpush.cn"
1213

1314
PUSH_URL = push_host + "/v3/push"
1415
PUSH_VALIDATE_URL = push_host + "/v3/push/validate"
@@ -28,6 +29,9 @@ const (
2829
QUERY_ALIAS_URL = device_host + "/v3/aliases/%s"
2930
// DELETE /v3/aliases/{alias_value}
3031
DELETE_ALIAS_URL = device_host + "/v3/aliases/%s"
32+
33+
// GET /v3/received
34+
RECEIVED_REPORT_URL = report_host + "/v3/received"
3135
)
3236

3337
var (

Diff for: device/alias.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ func (result *GetAliasUsersResult) FromResponse(resp *http.Response) error {
2323

2424
func (result *GetAliasUsersResult) String() string {
2525
return fmt.Sprintf("<GetAliasUsersResult> RegistrationIds: %v, %v",
26-
result.RegistrationIds, result.ResponseBase)
26+
result.RegistrationIds, result.ResponseBase.String())
2727
}

Diff for: device/consts.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package device
2+
3+
const (
4+
actionAdd = "add"
5+
actionRemove = "remove"
6+
maxAddOrRemoveRegistrationIds = 1000
7+
)

Diff for: device/tag.go

-6
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ func (result *CheckTagUserExistsResult) String() string {
4646
}
4747

4848
// 更新标签(与设备的绑定的关系)请求参数
49-
const (
50-
actionAdd = "add"
51-
actionRemove = "remove"
52-
maxAddOrRemoveRegistrationIds = 1000
53-
)
54-
5549
type UpdateTagUsersArgs struct {
5650
RegistrationIds map[string][]string `json:"registration_ids"`
5751
}

Diff for: jpush.go

+20
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package jpush
22

33
import (
44
"fmt"
5+
"strconv"
56
"strings"
67

78
"github.com/DeanThompson/jpush-api-go-client/common"
89
"github.com/DeanThompson/jpush-api-go-client/device"
910
"github.com/DeanThompson/jpush-api-go-client/httplib"
1011
"github.com/DeanThompson/jpush-api-go-client/push"
12+
"github.com/DeanThompson/jpush-api-go-client/report"
1113
)
1214

1315
// JPush 的 Golang 推送客户端
@@ -143,6 +145,24 @@ func (jpc *JPushClient) DeleteAlias(alias string, platforms []string) (*common.R
143145
return common.ResponseOrError(resp, err)
144146
}
145147

148+
// 送达统计
149+
func (jpc *JPushClient) GetReceivedReport(msgIds []uint64) (*report.ReceiveReport, error) {
150+
ids := make([]string, 0, len(msgIds))
151+
for _, msgId := range msgIds {
152+
ids = append(ids, strconv.FormatUint(msgId, 10))
153+
}
154+
params := map[string]interface{}{"msg_ids": strings.Join(ids, ",")}
155+
156+
resp, err := jpc.http.Get(common.RECEIVED_REPORT_URL, params, jpc.headers)
157+
if err != nil {
158+
return nil, err
159+
}
160+
161+
result := &report.ReceiveReport{}
162+
err = result.FromResponse(resp)
163+
return result, err
164+
}
165+
146166
////////////////////////////////////////////////////////////////////////////////
147167

148168
func addPlatformsToParams(platforms []string) map[string]interface{} {

Diff for: jpush_test.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,27 @@ func test_DeleteAlias(t *testing.T) {
174174
showResultOrError("DeleteAlias", result, err)
175175
}
176176

177+
///////////////////// Report /////////////////////
178+
179+
func test_GetReceivedReport(t *testing.T) {
180+
msgIds := []uint64{1613113584, 1229760629}
181+
result, err := client.GetReceivedReport(msgIds)
182+
showResultOrError("GetReceivedReport", result, err)
183+
}
184+
177185
func Test_Starter(t *testing.T) {
178-
// test_Push(t)
179-
//
180-
// test_QueryDevice(t)
181-
// test_UpdateDevice(t)
182-
//
183-
// test_GetTags(t)
184-
// test_CheckTagUserExists(t)
185-
// test_UpdateTagUsers(t)
186-
// test_DeleteTag(t)
186+
test_Push(t)
187+
188+
test_QueryDevice(t)
189+
test_UpdateDevice(t)
190+
191+
test_GetTags(t)
192+
test_CheckTagUserExists(t)
193+
test_UpdateTagUsers(t)
194+
test_DeleteTag(t)
187195

188196
test_GetAliasUsers(t)
189197
test_DeleteAlias(t)
198+
199+
test_GetReceivedReport(t)
190200
}

Diff for: report/report.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package report
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
8+
"github.com/DeanThompson/jpush-api-go-client/common"
9+
)
10+
11+
type ReceivedReportNode struct {
12+
MsgId uint64 `json:"msg_id"`
13+
AndroidReceived int `json:"android_received"` // Android 送达。如果无此项数据则为 null
14+
IosApnsSent int `json:"ios_apns_sent"` // iOS 推送成功。如果无此项数据则为 null
15+
IosMsgReceived int `json:"ios_msg_received"` // iOS 自定义消息送达数。如果无此项数据则为null
16+
WpMpnsSent int `json:"wp_mpns_sent"` // winphone 通知送达。如果无此项数据则为 null
17+
}
18+
19+
func (node *ReceivedReportNode) String() string {
20+
v, _ := json.Marshal(node)
21+
return string(v)
22+
}
23+
24+
type ReceiveReport struct {
25+
common.ResponseBase
26+
27+
Report []ReceivedReportNode
28+
}
29+
30+
func (report *ReceiveReport) FromResponse(resp *http.Response) error {
31+
report.ResponseBase = common.NewResponseBase(resp)
32+
if !report.Ok() {
33+
return nil
34+
}
35+
return common.RespToJson(resp, &report.Report)
36+
}
37+
38+
func (report *ReceiveReport) String() string {
39+
s, _ := json.Marshal(report.Report)
40+
return fmt.Sprintf("<ReceiveReport> report: %v, %v", string(s),
41+
report.ResponseBase.String())
42+
}

0 commit comments

Comments
 (0)