-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_push.go
96 lines (88 loc) · 2.15 KB
/
client_push.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
package jpushclient
import (
"bytes"
"encoding/json"
"strconv"
)
func (c *Client) Push(push *PushRequest) (map[string]any, error) {
link := c.pushUrl + "/v3/push"
buf, err := json.Marshal(push)
if err != nil {
return nil, err
}
resp, err := c.request("POST", link, bytes.NewReader(buf), false)
if err != nil {
return nil, err
}
return resp.Map()
}
func (c *Client) GetCidPool(count int, cidType string) (map[string]any, error) {
link := c.pushUrl + "/v3/push/cid?"
if count > 0 {
link += "count=" + strconv.Itoa(count)
}
if cidType != "" {
link += "type=" + cidType
}
resp, err := c.request("GET", link, nil, false)
if err != nil {
return nil, err
}
return resp.Map()
}
func (c *Client) GroupPush(push *PushRequest) (map[string]any, error) {
link := c.pushUrl + "/v3/grouppush"
buf, err := json.Marshal(push)
if err != nil {
return nil, err
}
resp, err := c.request("POST", link, bytes.NewReader(buf), true)
if err != nil {
return nil, err
}
return resp.Map()
}
func (c *Client) Validate(req *PushRequest) (map[string]any, error) {
link := c.pushUrl + "/v3/push/validate"
buf, err := json.Marshal(req)
if err != nil {
return nil, err
}
resp, err := c.request("POST", link, bytes.NewReader(buf), false)
if err != nil {
return nil, err
}
return resp.Map()
}
func (c *Client) BatchPushByRegId(push *PushSingleRequest) (map[string]any, error) {
link := c.pushUrl + "/v3/push/batch/regid/single"
buf, err := json.Marshal(push)
if err != nil {
return nil, err
}
resp, err := c.request("POST", link, bytes.NewReader(buf), false)
if err != nil {
return nil, err
}
return resp.Map()
}
func (c *Client) BatchPushByAlias(push *PushSingleRequest) (map[string]any, error) {
link := c.pushUrl + "/v3/push/batch/alias/single"
buf, err := json.Marshal(push)
if err != nil {
return nil, err
}
resp, err := c.request("POST", link, bytes.NewReader(buf), false)
if err != nil {
return nil, err
}
return resp.Map()
}
func (c *Client) DeletePush(msgId string) ([]byte, error) {
link := c.pushUrl + "/v3/push/" + msgId
resp, err := c.request("DELETE", link, nil, false)
if err != nil {
return nil, err
}
return resp.Bytes(), nil
}