-
Notifications
You must be signed in to change notification settings - Fork 0
/
intercept_rule.go
138 lines (128 loc) · 3.83 KB
/
intercept_rule.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
133
134
135
136
137
138
package externalcontact
import (
"encoding/json"
"fmt"
"github.com/EricJSanchez/wecom/util"
)
const (
//获取客户群详情
addInterceptRuleAddr = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_intercept_rule?access_token=%s"
updateInterceptRuleAddr = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_intercept_rule?access_token=%s"
delInterceptRuleAddr = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_intercept_rule?access_token=%s"
)
type AddInterceptRuleOptions struct {
RuleName string `json:"rule_name"`
WordList []string `json:"word_list"`
SemanticsList []int `json:"semantics_list"`
InterceptType int `json:"intercept_type"`
ApplicableRange ApplicableRange `json:"applicable_range"`
}
type ApplicableRange struct {
UserList []string `json:"user_list"`
DepartmentList []int `json:"department_list"`
}
type InterceptRuleSchema struct {
util.CommonError
RuleId string `json:"rule_id"`
}
func (r *Client) AddInterceptRule(options AddInterceptRuleOptions) (info InterceptRuleSchema, err error) {
var (
accessToken string
data []byte
)
_ = util.Record(r.cache, addInterceptRuleAddr)
accessToken, err = r.ctx.GetAccessToken()
if err != nil {
return
}
optionJson, err := json.Marshal(options)
if err != nil {
return
}
data, err = util.HTTPPost(fmt.Sprintf(addInterceptRuleAddr, accessToken), string(optionJson))
if err != nil {
return
}
if err = json.Unmarshal(data, &info); err != nil {
return
}
if info.ErrCode != 0 {
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
}
return info, nil
}
type UpdateInterceptRuleOptions struct {
RuleID string `json:"rule_id"`
RuleName string `json:"rule_name"`
WordList []string `json:"word_list"`
ExtraRule ExtraRule `json:"extra_rule"`
InterceptType int `json:"intercept_type"`
AddApplicableRange AddApplicableRange `json:"add_applicable_range,omitempty"`
RemoveApplicableRange RemoveApplicableRange `json:"remove_applicable_range,omitempty"`
}
type ExtraRule struct {
SemanticsList []int `json:"semantics_list"`
}
type AddApplicableRange struct {
UserList []string `json:"user_list,omitempty"`
DepartmentList []int `json:"department_list,omitempty"`
}
type RemoveApplicableRange struct {
UserList []string `json:"user_list,omitempty"`
DepartmentList []int `json:"department_list,omitempty"`
}
func (r *Client) UpdateInterceptRule(options UpdateInterceptRuleOptions) (info util.CommonError, err error) {
var (
accessToken string
data []byte
)
_ = util.Record(r.cache, updateInterceptRuleAddr)
accessToken, err = r.ctx.GetAccessToken()
if err != nil {
return
}
optionJson, err := json.Marshal(options)
if err != nil {
return
}
data, err = util.HTTPPost(fmt.Sprintf(updateInterceptRuleAddr, accessToken), string(optionJson))
if err != nil {
return
}
if err = json.Unmarshal(data, &info); err != nil {
return
}
if info.ErrCode != 0 {
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
}
return info, nil
}
type DelInterceptRuleOptions struct {
RuleID string `json:"rule_id"`
}
func (r *Client) DelInterceptRule(options DelInterceptRuleOptions) (info util.CommonError, err error) {
var (
accessToken string
data []byte
)
_ = util.Record(r.cache, delInterceptRuleAddr)
accessToken, err = r.ctx.GetAccessToken()
if err != nil {
return
}
optionJson, err := json.Marshal(options)
if err != nil {
return
}
data, err = util.HTTPPost(fmt.Sprintf(delInterceptRuleAddr, accessToken), string(optionJson))
if err != nil {
return
}
if err = json.Unmarshal(data, &info); err != nil {
return
}
if info.ErrCode != 0 {
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
}
return info, nil
}