forked from l306287405/wechat3rd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthorizer.go
193 lines (176 loc) · 5.61 KB
/
authorizer.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
184
185
186
187
188
189
190
191
192
193
package wechat3rd
import "github.com/l306287405/wechat3rd/core"
// 授权方信息
const (
AuthorizerInfoUrl = WECHAT_API_URL + "/cgi-bin/component/api_get_authorizer_info?component_access_token=%s"
AuthorizerOptionUrl = WECHAT_API_URL + "/cgi-bin/component/api_get_authorizer_option?component_access_token=%s"
SetAuthorizerOptionUrl = WECHAT_API_URL + "/cgi-bin/component/api_set_authorizer_option?component_access_token=%s"
AuthorizerListUrl = WECHAT_API_URL + "/cgi-bin/component/api_get_authorizer_list?component_access_token=%s"
)
type AuthorizerInfo struct {
}
type AuthorizerInfoReq struct {
ComponentAppid string `json:"component_appid"`
AuthorizerAppid string `json:"authorizer_appid"`
}
type AuthorizerInfoResp struct {
core.Error
AuthorizerInfo struct {
// 小程序独有
Signature string `json:"signature"`
Miniprograminfo struct {
Network struct {
RequestDomain []string `json:"RequestDomain"`
WsRequestDomain []string `json:"WsRequestDomain"`
UploadDomain []string `json:"UploadDomain"`
DownloadDomain []string `json:"DownloadDomain"`
} `json:"network"`
Categories []struct {
First string `json:"first"`
Second string `json:"second"`
} `json:"categories"`
VisitStatus int `json:"visit_status"`
} `json:"miniprograminfo"`
// 都存在的
//昵称
NickName string `json:"nick_name"`
HeadImg string `json:"head_img"`
//公众号类型 --公众号独有
ServiceTypeInfo struct {
ID int `json:"id"`
} `json:"service_type_info"`
// 认证类型
VerifyTypeInfo struct {
ID int `json:"id"`
} `json:"verify_type_info"`
//原始 ID
UserName string `json:"user_name"`
// 主题名称
PrincipalName string `json:"principal_name"`
//用以了解功能的开通状况(0代表未开通,1代表已开通),详见business_info 说明
BusinessInfo struct {
OpenStore int `json:"open_store"`
OpenScan int `json:"open_scan"`
OpenPay int `json:"open_pay"`
OpenCard int `json:"open_card"`
OpenShake int `json:"open_shake"`
} `json:"business_info"`
Alias string `json:"alias"`
//二维码图片的 URL,开发者最好自行也进行保存
QrcodeURL string `json:"qrcode_url"`
} `json:"authorizer_info"`
AuthorizationInfo struct {
AuthorizationAppid string `json:"authorization_appid"`
FuncInfo []struct {
FuncscopeCategory struct {
ID int `json:"id"`
} `json:"funcscope_category"`
} `json:"func_info"`
} `json:"authorization_info"`
}
// 获取授权账号信息
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_get_authorizer_info.html
func (s *Server) AuthorizerInfo(authorizerAppid string) (resp *AuthorizerInfoResp) {
resp = &AuthorizerInfoResp{}
token, err := s.Token()
if err != nil {
resp.Err(err)
return
}
req := &AuthorizerInfoReq{
ComponentAppid: s.cfg.AppID,
AuthorizerAppid: authorizerAppid,
}
resp.Err(core.PostJson(getCompleteUrl(AuthorizerInfoUrl, token), req, resp))
return
}
type AuthorizeOption string
// option类型
//var (
// AuthorizeOptionLocal AuthorizeOption = "location_report"
// AuthorizeOptionVoiceRecognize AuthorizeOption = "voice_recognize"
// AuthorizeOptionCustomerService AuthorizeOption = "customer_service"
//)
type AuthorizerOptionReq struct {
ComponentAppid string `json:"component_appid"`
AuthorizerAppid string `json:"authorizer_appid"`
OptionName AuthorizeOption `json:"option_name"`
}
type AuthorizerOptionResp struct {
core.Error
AuthorizerAppid string `json:"authorizer_appid"`
OptionName string `json:"option_name"`
OptionValue string `json:"option_value"`
}
// 获取选项信息
func (s *Server) AuthorizerOption(authorizerAppid string, optionName AuthorizeOption) (resp *AuthorizerOptionResp) {
resp = &AuthorizerOptionResp{}
token, err := s.Token()
if err != nil {
resp.Err(err)
return
}
req := &AuthorizerOptionReq{
ComponentAppid: s.cfg.AppID,
AuthorizerAppid: authorizerAppid,
OptionName: optionName,
}
resp.Err(core.PostJson(getCompleteUrl(AuthorizerOptionUrl, token), req, resp))
return
}
type SetAuthorizerOptionReq struct {
AuthorizerOptionReq
OptionValue string `json:"option_name"`
}
type SetAuthorizerOptionResp struct {
core.Error
}
// 设置选项信息
func (s *Server) SetAuthorizerOption(authorizerAppid string, optionName AuthorizeOption, optionValue string) (resp *SetAuthorizerOptionResp) {
resp = &SetAuthorizerOptionResp{}
token, err := s.Token()
if err != nil {
resp.Err(err)
return
}
req := &SetAuthorizerOptionReq{
AuthorizerOptionReq: AuthorizerOptionReq{
ComponentAppid: s.cfg.AppID,
AuthorizerAppid: authorizerAppid,
OptionName: optionName,
},
OptionValue: optionValue,
}
resp.Err(core.PostJson(getCompleteUrl(SetAuthorizerOptionUrl, token), req, resp))
return
}
type AuthorizerListReq struct {
ComponentAppid string `json:"component_appid"`
Offset int `json:"offset"`
Count int `json:"count"`
}
type AuthorizerListResp struct {
core.Error
TotalCount int `json:"total_count"`
List []struct {
AuthorizerAppid string `json:"authorizer_appid"`
RefreshToken string `json:"refresh_token"`
AuthTime int `json:"auth_time"`
} `json:"list"`
}
// 拉取用户授权列表
func (s *Server) AuthorizerList(offset, count int) (resp *AuthorizerListResp) {
resp = &AuthorizerListResp{}
token, err := s.Token()
if err != nil {
resp.Err(err)
return
}
req := &AuthorizerListReq{
ComponentAppid: s.cfg.AppID,
Offset: offset,
Count: count,
}
resp.Err(core.PostJson(getCompleteUrl(AuthorizerListUrl, token), req, resp))
return
}