forked from shenghui0779/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
externalcontact.go
183 lines (155 loc) · 4.94 KB
/
externalcontact.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package school
import (
"encoding/json"
"strconv"
"github.com/chenghonour/wechat-sdk/urls"
"github.com/chenghonour/wechat-sdk/wx"
)
type ResultSubscribeQRCode struct {
QRCodeBig string `json:"qrcode_big"`
QRCodeMiddle string `json:"qrcode_middle"`
QRCodeThumb string `json:"qrcode_thumb"`
}
// GetSubscribeQRCode 获取「学校通知」二维码
func GetSubscribeQRCode(result *ResultSubscribeQRCode) wx.Action {
return wx.NewGetAction(urls.CorpSchoolGetSubscribeQRCode,
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsSubscribeModeSet struct {
SubscribeMode int `json:"subscribe_mode"`
}
// SetSubscribeMode 设置关注「学校通知」的模式
func SetSubscribeMode(mode int) wx.Action {
params := &ParamsSubscribeModeSet{
SubscribeMode: mode,
}
return wx.NewPostAction(urls.CorpSchoolSetSubscribeMode,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
)
}
type ResultSubscribeModeGet struct {
SubscribeMode int `json:"subscribe_mode"`
}
// GetSubscribeMode 获取关注「学校通知」的模式
func GetSubscribeMode(result *ResultSubscribeModeGet) wx.Action {
return wx.NewGetAction(urls.CorpSchoolGetSubscribeMode,
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ExternalContact struct {
ExternalUserID string `json:"external_userid"`
Name string `json:"name"`
ForeignKey string `json:"foreign_key"`
Position string `json:"position"`
Avatar string `json:"avatar"`
CorpName string `json:"corp_name"`
CorpFullName string `json:"corp_full_name"`
Type int `json:"type"`
Gender int `json:"gender"`
UnionID string `json:"unionid"`
IsSubscribe int `json:"is_subscribe"`
SubscriberInfo *SubscriberInfo `json:"subscriber_info"`
ExternalProfile *ExternalProfile `json:"external_profile"`
}
type SubscriberInfo struct {
TagID []string `json:"tag_id"`
RemarkMobiles []string `json:"remark_mobiles"`
Remark string `json:"remark"`
}
type ExternalProfile struct {
ExternalAttr []*Attr `json:"external_attr"`
}
type Attr struct {
Type int `json:"type"`
Name string `json:"name"`
Text *AttrText `json:"text"`
Web *AttrWeb `json:"web"`
Miniprogram *AttrMinip `json:"miniprogram"`
}
type AttrText struct {
Value string `json:"value"`
}
type AttrWeb struct {
Title string `json:"title"`
URL string `json:"url"`
}
type AttrMinip struct {
Title string `json:"title"`
AppID string `json:"appid"`
PagePath string `json:"pagepath"`
}
type FollowUser struct {
UserID string `json:"userid"`
Remark string `json:"remark"`
Description string `json:"description"`
CreateTime int64 `json:"createtime"`
RemarkCorpName string `json:"remark_corp_name"`
RemarkMobiles []string `json:"remark_mobiles"`
State string `json:"state"`
Tags []*FollowTag `json:"tags"`
}
type FollowTag struct {
GroupName string `json:"group_name"`
TagName string `json:"tag_name"`
TagID string `json:"tag_id"`
Type int `json:"type"`
}
type ResultExternalContact struct {
ExternalContact *ExternalContact `json:"external_contact"`
FollowUser []*FollowUser `json:"follow_user"`
}
// GetExternalContact 获取外部联系人详情
func GetExternalContact(externalUserID string, result *ResultExternalContact) wx.Action {
return wx.NewGetAction(urls.CorpExternalContactGet,
wx.WithQuery("external_userid", externalUserID),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsOpenIDConvert struct {
ExternalUserID string `json:"external_userid"`
}
type ResultOpenIDConvert struct {
OpenID string `json:"openid"`
}
// ConvertToOpenID 外部联系人openid转换
func ConvertToOpenID(userID string, result *ResultOpenIDConvert) wx.Action {
params := &ParamsOpenIDConvert{
ExternalUserID: userID,
}
return wx.NewPostAction(urls.CorpExternalContactConvertToOpenID,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ResultAgentAllowScope struct {
AllowScope *AgentAllowScope `json:"allow_scope"`
}
type AgentAllowScope struct {
Students []*AgentAllowStudent `json:"students"`
Departments []int64 `json:"departments"`
}
type AgentAllowStudent struct {
UserID string `json:"userid"`
}
// GetAgentAllowScope 获取可使用的家长范围
func GetAgentAllowScope(agentID int64, result *ResultAgentAllowScope) wx.Action {
return wx.NewGetAction(urls.CorpSchoolGetAgentAllowScope,
wx.WithQuery("agentid", strconv.FormatInt(agentID, 10)),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}