forked from WeixinCloud/wxcloudrun-wxcomponent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthorizers.go
100 lines (88 loc) · 3.09 KB
/
authorizers.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
package wx
import (
"fmt"
"github.com/WeixinCloud/wxcloudrun-wxcomponent/comm/log"
wxbase "github.com/WeixinCloud/wxcloudrun-wxcomponent/comm/wx/base"
)
type getAuthorizerInfoReq struct {
ComponentAppid string `wx:"component_appid"`
AuthorizerAppid string `wx:"authorizer_appid"`
}
type idItem struct {
Id int `wx:"id"`
}
type funcInfo struct {
FuncscopeCategory idItem `wx:"funcscope_category"`
}
type authorizationInfo struct {
AuthorizationAppid string `wx:"authorization_appid"`
RawFuncInfo []funcInfo `wx:"func_info"`
StrFuncInfo string
}
type networkInfo struct {
RequestDomain []string `wx:"RequestDomain"`
WsRequestDomain []string `wx:"WsRequestDomain"`
UploadDomain []string `wx:"UploadDomain"`
DownloadDomain []string `wx:"DownloadDomain"`
BizDomain []string `wx:"BizDomain"`
UDPDomain []string `wx:"UDPDomain"`
}
type categorieInfo struct {
First string `wx:"first"`
Second string `wx:"second"`
}
type miniProgramInfo struct {
Network networkInfo `wx:"network"`
Categories []categorieInfo `wx:"categories"`
}
// AuthorizerBasicConfig 授权账号的基础配置结构体
type AuthorizerBasicConfig struct {
IsPhoneConfigured bool `json:"isPhoneConfigured" wx:"is_phone_configured"`
IsEmailConfigured bool `json:"isEmailConfigured" wx:"is_email_configured"`
}
type authorizerInfo struct {
NickName string `wx:"nick_name"`
HeadImg string `wx:"head_img"`
Appid string `wx:"appid"`
ServiceType idItem `wx:"service_type_info"`
VerifyInfo idItem `wx:"verify_type_info"`
UserName string `wx:"user_name"`
PrincipalName string `wx:"principal_name"`
QrcodeUrl string `wx:"qrcode_url"`
MiniProgramInfo *miniProgramInfo `wx:"MiniProgramInfo"`
RegisterType int `wx:"register_type"`
AccountStatus int `wx:"account_status"`
BasicConfig *AuthorizerBasicConfig `wx:"basic_config"`
AppType int
}
// AuthorizerInfoResp 授权账号信息结构体
type AuthorizerInfoResp struct {
AuthorizationInfo authorizationInfo `wx:"authorization_info"`
AuthorizerInfo authorizerInfo `wx:"authorizer_info"`
}
// GetAuthorizerInfo 获取授权账号信息
func GetAuthorizerInfo(appid string, resp *AuthorizerInfoResp) error {
req := getAuthorizerInfoReq{
ComponentAppid: wxbase.GetAppid(),
AuthorizerAppid: appid,
}
_, body, err := PostWxJsonWithComponentToken("/cgi-bin/component/api_get_authorizer_info", "", req)
if err != nil {
log.Error(err)
return err
}
if err := WxJson.Unmarshal(body, &resp); err != nil {
log.Errorf("Unmarshal err, %v", err)
return err
}
funcListStr := ""
for _, v := range resp.AuthorizationInfo.RawFuncInfo {
funcListStr = fmt.Sprintf("%s|%d", funcListStr, v.FuncscopeCategory.Id)
}
resp.AuthorizationInfo.StrFuncInfo = funcListStr
resp.AuthorizerInfo.AppType = 0 // 小程序
if resp.AuthorizerInfo.MiniProgramInfo == nil {
resp.AuthorizerInfo.AppType = 1 // 公众号
}
return nil
}