forked from Scorpio69t/jpush-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcid.go
58 lines (45 loc) · 1.17 KB
/
cid.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
package jpush
import (
"encoding/json"
"fmt"
)
type CidRequest struct {
Count int `json:"count,omitempty"` // 数值类型,不传则默认为 1。范围为 [1, 1000]
Type string `json:"type,omitempty"` // CID 类型。取值:push(默认),schedule
}
type CidResponse struct {
CidList []string `json:"cidlist,omitempty"` // CID 列表
}
func (c CidRequest) String() string {
return fmt.Sprintf("CidRequest{Count: %d, Type: %s}", c.Count, c.Type)
}
func (c CidResponse) String() string {
return fmt.Sprintf("CidResponse{CidList: %v}", c.CidList)
}
// NewCidRequest 创建 CidRequest 对象
func NewCidRequest(count int, push_type string) *CidRequest {
c := &CidRequest{}
if count <= 0 || count > 1000 {
c.Count = 1
} else {
c.Count = count
}
if push_type == "" {
c.Type = "push"
} else {
c.Type = push_type
}
return c
}
// GetCidList 获取 CID 列表
func (c *CidRequest) GetCidList(key, secret string) (*CidResponse, error) {
resp := &CidResponse{}
jc := NewJPushClient(key, secret)
data, err := jc.GetCid(c.Count, c.Type)
if err != nil {
return nil, err
}
fmt.Printf("%+v\n", string(data))
err = json.Unmarshal(data, resp)
return resp, err
}