-
Notifications
You must be signed in to change notification settings - Fork 1
/
push_api.go
132 lines (122 loc) · 3.64 KB
/
push_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package getuipush
import (
"github.com/tidwall/gjson"
"github.com/zituocn/getui-push/models"
)
// pushSingleByCid 推送给单个用户
// cid在param中设置
func pushSingleByCid(appId, token string, param *models.PushParam) (*models.Response, error) {
bodyByte, err := makeReqBody(param)
if err != nil {
return nil, err
}
resp, err := RequestAPI("POST", appId+"/push/single/cid", token, bodyByte)
if err != nil {
return nil, err
}
return resp, nil
}
// pushSingleByAlias 推送给单个用户
// alias在param中设置
func pushSingleByAlias(appId, token string, param *models.PushParam) (*models.Response, error) {
bodyByte, err := makeReqBody(param)
if err != nil {
return nil, err
}
resp, err := RequestAPI("POST", appId+"/push/single/alias", token, bodyByte)
if err != nil {
return nil, err
}
return resp, nil
}
// pushApp 推给所有
func pushApp(appId, token string, param *models.PushParam) (*models.Response, error) {
bodyByte, err := makeReqBody(param)
if err != nil {
return nil, err
}
resp, err := RequestAPI("POST", appId+"/push/all", token, bodyByte)
if err != nil {
return nil, err
}
return resp, nil
}
// pushAppByClient 推给不同客户端
// 客户端指android或ios
// 是android还是ios,从param中区别
func pushAppByClient(appId, token string, param *models.PushParam) (*models.Response, error) {
bodyByte, err := makeReqBody(param)
if err != nil {
return nil, err
}
resp, err := RequestAPI("POST", appId+"/push/tag", token, bodyByte)
if err != nil {
return nil, err
}
return resp, nil
}
// pushAppByTag 推给不同的tag
// 自定义tag
func pushAppByTag(appId, token string, param *models.PushParam) (*models.Response, error) {
bodyByte, err := makeReqBody(param)
if err != nil {
return nil, err
}
resp, err := RequestAPI("POST", appId+"/push/tag", token, bodyByte)
if err != nil {
return nil, err
}
return resp, nil
}
// pushAppByFastCustomTag 使用标签快速推送
func pushAppByFastCustomTag(appId, token string, param *models.PushParam) (*models.Response, error) {
bodyByte, err := makeReqBody(param)
if err != nil {
return nil, err
}
resp, err := RequestAPI("POST", appId+"/push/fast_custom_tag", token, bodyByte)
if err != nil {
return nil, err
}
return resp, nil
}
// createPushMessage 此接口用来创建消息体,并返回taskid,为批量推的前置步骤
// taskid 任务编号,用于执行cid批量推和执行别名批量推,此taskid可以多次使用,有效期为离线时间
func createPushMessage(appId, token string, param *models.PushParam) (*models.Response, error) {
bodyByte, err := makeReqBody(param)
if err != nil {
return nil, err
}
b, err := HttpRequest("POST", appId+"/push/list/message", token, bodyByte)
if err != nil {
return nil, err
}
resp := &models.Response{
Code: int(gjson.GetBytes(b, "code").Int()),
Msg: gjson.GetBytes(b, "msg").String(),
Data: gjson.GetBytes(b, "data.taskid").String(),
}
return resp, nil
}
// pushListByCid 按cid群推
// 使用前,请先调用 CreatePushMessage 后返回的taskid
func pushListByCid(appId, token string, param *models.PushListParam) (*models.Response, error) {
bodyByte, err := makeReqBody(param)
if err != nil {
return nil, err
}
resp, err := RequestAPI("POST", appId+"/push/list/cid", token, bodyByte)
if err != nil {
return nil, err
}
return resp, nil
}
// stopTask 停止任务
// 对正处于推送状态,或者未接收的消息停止下发(只支持批量推和群推任务)
func stopTask(appId, token, taskId string) (*models.Response, error) {
resp, err := RequestAPI("DELETE", appId+"/task/"+taskId, token, nil)
if err != nil {
return nil, err
}
return resp, nil
}