-
Notifications
You must be signed in to change notification settings - Fork 4
/
admin.go
90 lines (81 loc) · 2.28 KB
/
admin.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
package jpush
import (
"bytes"
"encoding/json"
)
// AdminAppRequest admin app request
type AdminAppRequest struct {
AppName string `json:"app_name"`
AndroidPackage string `json:"android_package"`
GroupName string `json:"group_name"`
}
// AdminCertificateRequest admin certificate
type AdminCertificateRequest struct {
DevCertificatePassword string `json:"devCertificatePassword,omitempty"`
ProCertificatePassword string `json:"proCertificatePassword,omitempty"`
DevCertificateFile []byte `json:"devCertificateFile,omitempty"`
ProCertificateFile []byte `json:"proCertificateFile,omitempty"`
}
// AdminAppResponse new app response
type AdminAppResponse struct {
AppKey string `json:"app_key"`
AndroidPackage string `json:"android_package"`
IsNewCreated bool `json:"is_new_created"`
}
// AdminSuccessResponse success response
type AdminSuccessResponse struct {
Success string `json:"success"`
}
// AdminApp admin app point
// POST /v1/admin/app
func (j *JPush) AdminApp(req **AdminAppRequest) (*AdminAppResponse, error) {
url := j.GetURL("admin") + "app"
buf, err := json.Marshal(req)
if err != nil {
return nil, err
}
resp, err := j.request("POST", url, bytes.NewReader(buf), nil)
if err != nil {
return nil, err
}
ret := new(AdminAppResponse)
err = json.Unmarshal(resp, ret)
if err != nil {
return nil, err
}
return ret, nil
}
// AdminAppDelete delete app
// POST /v1/app/{appkey}/delete
func (j *JPush) AdminAppDelete(appkey string) (*AdminSuccessResponse, error) {
url := j.GetURL("admin") + "app/" + appkey + "/delete"
resp, err := j.request("POST", url, nil, nil)
if err != nil {
return nil, err
}
ret := new(AdminSuccessResponse)
err = json.Unmarshal(resp, ret)
if err != nil {
return nil, err
}
return ret, nil
}
// AdminAppCert admin certificate
// POST /v1/app/{appKey}/certificate
func (j *JPush) AdminAppCert(appkey string, req *AdminCertificateRequest) (*AdminSuccessResponse, error) {
url := j.GetURL("admin") + "app/" + appkey + "/certificate"
buf, err := json.Marshal(req)
if err != nil {
return nil, err
}
resp, err := j.request("POST", url, bytes.NewReader(buf), nil)
if err != nil {
return nil, err
}
ret := new(AdminSuccessResponse)
err = json.Unmarshal(resp, ret)
if err != nil {
return nil, err
}
return ret, nil
}