瀏覽代碼

change struct

张延森 3 年之前
父節點
當前提交
d30c842223

+ 0
- 34
api/api.go 查看文件

@@ -1,34 +0,0 @@
1
-package api
2
-
3
-// BindComponentByPC 构建PC端授权链接
4
-const BindComponentByPC = "https://mp.weixin.qq.com/cgi-bin/componentloginpage"
5
-
6
-// BindComponentByH5 构建移动端授权链接
7
-const BindComponentByH5 = "https://mp.weixin.qq.com/safe/bindcomponent"
8
-
9
-// StartPushTicket 启动票据推送服务
10
-const StartPushTicket = "https://api.weixin.qq.com/cgi-bin/component/api_start_push_ticket"
11
-
12
-// ComponentToken 获取令牌
13
-const ComponentToken = "https://api.weixin.qq.com/cgi-bin/component/api_component_token"
14
-
15
-// CreatePreAuthCode 获取预授权码
16
-const CreatePreAuthCode = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode"
17
-
18
-// QueryAuth 获取授权信息
19
-const QueryAuth = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth"
20
-
21
-// AuthorizerToken 获取/刷新接口调用令牌
22
-const AuthorizerToken = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token"
23
-
24
-// GetAuthorizerInfo 获取授权帐号信息
25
-const GetAuthorizerInfo = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info"
26
-
27
-// GetAuthorizerList 拉取所有已授权的帐号信息
28
-const GetAuthorizerList = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list"
29
-
30
-// GetAuthorizerOption 获取授权方选项信息
31
-const GetAuthorizerOption = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option"
32
-
33
-// SetAuthorizerOption 设置授权方选项信息
34
-const SetAuthorizerOption = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option"

service/authorizer_info.go → authorization/authorizer_info.go 查看文件

@@ -1,14 +1,12 @@
1
-package service
1
+package authorization
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"errors"
6 6
 	"net/url"
7 7
 
8
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/api"
9
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/entities"
10
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils"
11
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
8
+	wxerr "gitee.com/yansen_zh/wxcomponent/errors"
9
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
12 10
 )
13 11
 
14 12
 // AuthorizerInfoParam 获取授权帐号信息参数
@@ -19,34 +17,33 @@ type AuthorizerInfoParam struct {
19 17
 
20 18
 // AuthorizerInfoResult 获取授权帐号信息结果
21 19
 type AuthorizerInfoResult struct {
22
-	entities.Error
23
-	AuthorizationInfo entities.AuthorizationInfo `json:"authorization_info"`
24
-	AuthorizerInfo    entities.AuthorizerInfo    `json:"authorizer_info"`
20
+	wxerr.Error
21
+	AuthorizationInfo AuthorizationInfo `json:"authorization_info"`
22
+	AuthorizerInfo    AuthorizerInfo    `json:"authorizer_info"`
25 23
 }
26 24
 
25
+const (
26
+	apiGetAuthorizerInfo = "https://apies.weixin.qq.com/cgi-bin/component/api_get_authorizer_info"
27
+)
28
+
27 29
 // GetAuthorizerInfo 获取授权帐号信息
28
-func GetAuthorizerInfo(componentAccessToken string, param AuthorizerInfoParam) (*AuthorizerInfoResult, error) {
30
+func GetAuthorizerInfo(componentAccessToken string, data AuthorizerInfoParam) (*AuthorizerInfoResult, error) {
29 31
 	if componentAccessToken == "" {
30 32
 		return nil, errors.New("获取授权帐号信息 第三方平台的 component_access_token 不能为空")
31 33
 	}
32 34
 
33
-	if param.ComponentAppId == "" {
35
+	if data.ComponentAppId == "" {
34 36
 		return nil, errors.New("获取授权帐号信息 第三方平台的 appid 不能为空")
35 37
 	}
36 38
 
37
-	if param.AuthorizerAppId == "" {
39
+	if data.AuthorizerAppId == "" {
38 40
 		return nil, errors.New("获取授权帐号信息 授权方 appid 不能为空")
39 41
 	}
40 42
 
41
-	data, e1 := json.Marshal(param)
42
-	if e1 != nil {
43
-		return nil, e1
44
-	}
45
-
46 43
 	queryParam := url.Values{}
47 44
 	queryParam.Set("component_access_token", componentAccessToken)
48 45
 
49
-	apiUrl, _ := utils.ParseURL(api.GetAuthorizerInfo, &queryParam)
46
+	apiUrl, _ := request.ParseURL(apiGetAuthorizerInfo, &queryParam)
50 47
 	resp, e2 := request.PostJSON(apiUrl.String(), data)
51 48
 	if e2 != nil {
52 49
 		return nil, e2

service/authorizer_token.go → authorization/authorizer_token.go 查看文件

@@ -1,14 +1,12 @@
1
-package service
1
+package authorization
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"errors"
6 6
 	"net/url"
7 7
 
8
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/api"
9
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/entities"
10
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils"
11
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
8
+	wxerr "gitee.com/yansen_zh/wxcomponent/errors"
9
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
12 10
 )
13 11
 
14 12
 // AuthorizerTokenParam 获取/刷新接口调用令牌参数
@@ -20,39 +18,38 @@ type AuthorizerTokenParam struct {
20 18
 
21 19
 // AuthorizerTokenResult 获取/刷新接口调用令牌结果
22 20
 type AuthorizerTokenResult struct {
23
-	entities.Error
21
+	wxerr.Error
24 22
 	AuthorizerAccessToken  string  `json:"authorizer_access_token"`
25 23
 	ExpiresIn              float64 `json:"expires_in"`
26 24
 	AuthorizerRefreshToken string  `json:"authorizer_refresh_token"`
27 25
 }
28 26
 
27
+const (
28
+	apiAuthorizerToken = "https://apies.weixin.qq.com/cgi-bin/component/api_authorizer_token"
29
+)
30
+
29 31
 // AuthorizerToken 获取/刷新接口调用令牌
30
-func AuthorizerToken(componentAccessToken string, param AuthorizerTokenParam) (*AuthorizerTokenResult, error) {
32
+func AuthorizerToken(componentAccessToken string, data AuthorizerTokenParam) (*AuthorizerTokenResult, error) {
31 33
 	if componentAccessToken == "" {
32 34
 		return nil, errors.New("获取/刷新接口调用令牌 第三方平台的 component_access_token 不能为空")
33 35
 	}
34 36
 
35
-	if param.ComponentAppId == "" {
37
+	if data.ComponentAppId == "" {
36 38
 		return nil, errors.New("获取/刷新接口调用令牌 第三方平台的 appid 不能为空")
37 39
 	}
38 40
 
39
-	if param.AuthorizerAppId == "" {
41
+	if data.AuthorizerAppId == "" {
40 42
 		return nil, errors.New("获取/刷新接口调用令牌 授权方 appid 不能为空")
41 43
 	}
42 44
 
43
-	if param.AuthorizerRefreshToken == "" {
45
+	if data.AuthorizerRefreshToken == "" {
44 46
 		return nil, errors.New("获取/刷新接口调用令牌 刷新令牌 不能为空")
45 47
 	}
46 48
 
47
-	data, e1 := json.Marshal(param)
48
-	if e1 != nil {
49
-		return nil, e1
50
-	}
51
-
52 49
 	queryParam := url.Values{}
53 50
 	queryParam.Set("component_access_token", componentAccessToken)
54 51
 
55
-	apiUrl, _ := utils.ParseURL(api.AuthorizerToken, &queryParam)
52
+	apiUrl, _ := request.ParseURL(apiAuthorizerToken, &queryParam)
56 53
 	resp, e2 := request.PostJSON(apiUrl.String(), data)
57 54
 	if e2 != nil {
58 55
 		return nil, e2

service/bind_component.go → authorization/bind_component.go 查看文件

@@ -1,12 +1,11 @@
1
-package service
1
+package authorization
2 2
 
3 3
 import (
4 4
 	"errors"
5 5
 	"net/url"
6 6
 	"strconv"
7 7
 
8
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/api"
9
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils"
8
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
10 9
 )
11 10
 
12 11
 // BindComponentParam 构建授权链接入参
@@ -20,6 +19,11 @@ type BindComponentParam struct {
20 19
 	BizAppId    string
21 20
 }
22 21
 
22
+const (
23
+	componentloginpage = "https://mp.weixin.qq.com/cgi-bin/componentloginpage"
24
+	bindcomponent      = "https://mp.weixin.qq.com/safe/bindcomponent"
25
+)
26
+
23 27
 // BindComponentByPC 构建PC端授权链接
24 28
 func BindComponentByPC(param BindComponentParam) (*url.URL, error) {
25 29
 	return BindComponent("PC", param)
@@ -65,11 +69,11 @@ func BindComponent(client string, param BindComponentParam) (*url.URL, error) {
65 69
 		queryParams.Set("auth_type", strconv.Itoa(param.AuthType))
66 70
 	}
67 71
 
68
-	apiUrl := api.BindComponentByPC
72
+	apiUrl := componentloginpage
69 73
 	if isH5 {
70
-		apiUrl = api.BindComponentByH5
74
+		apiUrl = bindcomponent
71 75
 	}
72
-	u, err := utils.ParseURL(apiUrl, &queryParams)
76
+	u, err := request.ParseURL(apiUrl, &queryParams)
73 77
 	if err != nil {
74 78
 		return nil, err
75 79
 	}

service/component_token.go → authorization/component_token.go 查看文件

@@ -1,12 +1,11 @@
1
-package service
1
+package authorization
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"errors"
6 6
 
7
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/api"
8
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/entities"
9
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
7
+	wxerr "gitee.com/yansen_zh/wxcomponent/errors"
8
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
10 9
 )
11 10
 
12 11
 // ComponentTokenParam 获取令牌参数
@@ -18,31 +17,30 @@ type ComponentTokenParam struct {
18 17
 
19 18
 // ComponentTokenResult 获取令牌结果
20 19
 type ComponentTokenResult struct {
21
-	entities.Error
20
+	wxerr.Error
22 21
 	ComponentAccessToken string  `json:"component_access_token"`
23 22
 	ExpiresIn            float64 `json:"expires_in"`
24 23
 }
25 24
 
25
+const (
26
+	apiComponentToken = "https://apies.weixin.qq.com/cgi-bin/component/api_component_token"
27
+)
28
+
26 29
 // ComponentVerifyTicket 获取令牌
27
-func ComponentToken(param ComponentTokenParam) (*ComponentTokenResult, error) {
28
-	if param.ComponentAppId == "" {
30
+func ComponentToken(data ComponentTokenParam) (*ComponentTokenResult, error) {
31
+	if data.ComponentAppId == "" {
29 32
 		return nil, errors.New("获取令牌 第三方平台的 appid 不能为空")
30 33
 	}
31 34
 
32
-	if param.ComponentAppSecret == "" {
35
+	if data.ComponentAppSecret == "" {
33 36
 		return nil, errors.New("获取令牌 第三方平台的 appsecret 不能为空")
34 37
 	}
35 38
 
36
-	if param.ComponentVerifyTicket == "" {
39
+	if data.ComponentVerifyTicket == "" {
37 40
 		return nil, errors.New("获取令牌 推送 ticket 不能为空")
38 41
 	}
39 42
 
40
-	data, e1 := json.Marshal(param)
41
-	if e1 != nil {
42
-		return nil, e1
43
-	}
44
-
45
-	resp, e2 := request.PostJSON(api.ComponentToken, data)
43
+	resp, e2 := request.PostJSON(apiComponentToken, data)
46 44
 	if e2 != nil {
47 45
 		return nil, e2
48 46
 	}

service/pre_auth_code.go → authorization/pre_auth_code.go 查看文件

@@ -1,14 +1,12 @@
1
-package service
1
+package authorization
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"errors"
6 6
 	"net/url"
7 7
 
8
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/api"
9
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/entities"
10
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils"
11
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
8
+	wxerr "gitee.com/yansen_zh/wxcomponent/errors"
9
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
12 10
 )
13 11
 
14 12
 // PreAuthCodeParam 获取预授权码参数
@@ -18,30 +16,29 @@ type PreAuthCodeParam struct {
18 16
 
19 17
 // PreAuthCodeResult 获取预授权码结果
20 18
 type PreAuthCodeResult struct {
21
-	entities.Error
19
+	wxerr.Error
22 20
 	PreAuthCode string  `json:"pre_auth_code"`
23 21
 	ExpiresIn   float64 `json:"expires_in"`
24 22
 }
25 23
 
24
+const (
25
+	apiCreatePreauthcode = "https://apies.weixin.qq.com/cgi-bin/component/api_create_preauthcode"
26
+)
27
+
26 28
 // CreatePreAuthCode 获取预授权码
27
-func CreatePreAuthCode(componentAccessToken string, param PreAuthCodeParam) (*PreAuthCodeResult, error) {
29
+func CreatePreAuthCode(componentAccessToken string, data PreAuthCodeParam) (*PreAuthCodeResult, error) {
28 30
 	if componentAccessToken == "" {
29 31
 		return nil, errors.New("获取预授权码 第三方平台的 component_access_token 不能为空")
30 32
 	}
31 33
 
32
-	if param.ComponentAppId == "" {
34
+	if data.ComponentAppId == "" {
33 35
 		return nil, errors.New("获取预授权码 第三方平台的 appid 不能为空")
34 36
 	}
35 37
 
36
-	data, e1 := json.Marshal(param)
37
-	if e1 != nil {
38
-		return nil, e1
39
-	}
40
-
41 38
 	queryParam := url.Values{}
42 39
 	queryParam.Set("component_access_token", componentAccessToken)
43 40
 
44
-	apiUrl, _ := utils.ParseURL(api.CreatePreAuthCode, &queryParam)
41
+	apiUrl, _ := request.ParseURL(apiCreatePreauthcode, &queryParam)
45 42
 	resp, e2 := request.PostJSON(apiUrl.String(), data)
46 43
 	if e2 != nil {
47 44
 		return nil, e2

service/push_ticket.go → authorization/push_ticket.go 查看文件

@@ -1,12 +1,11 @@
1
-package service
1
+package authorization
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"errors"
6 6
 
7
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/api"
8
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/entities"
9
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
7
+	wxerr "gitee.com/yansen_zh/wxcomponent/errors"
8
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
10 9
 )
11 10
 
12 11
 // PushTicketParam 启动票据推送服务参数
@@ -17,25 +16,24 @@ type PushTicketParam struct {
17 16
 
18 17
 // PushTicketResult 启动票据推送服务参数
19 18
 type PushTicketResult struct {
20
-	entities.Error
19
+	wxerr.Error
21 20
 }
22 21
 
22
+const (
23
+	apiStartPushTicket = "https://apies.weixin.qq.com/cgi-bin/component/api_start_push_ticket"
24
+)
25
+
23 26
 // StartPushTicket 启动 ticket 推送服务
24
-func StartPushTicket(param PushTicketParam) (*PushTicketResult, error) {
25
-	if param.ComponentAppId == "" {
27
+func StartPushTicket(data PushTicketParam) (*PushTicketResult, error) {
28
+	if data.ComponentAppId == "" {
26 29
 		return nil, errors.New("启动 ticket 推送服务 第三方平台的 appid 不能为空")
27 30
 	}
28 31
 
29
-	if param.ComponentSecret == "" {
32
+	if data.ComponentSecret == "" {
30 33
 		return nil, errors.New("启动 ticket 推送服务 第三方平台的 appsecret 不能为空")
31 34
 	}
32 35
 
33
-	data, e1 := json.Marshal(param)
34
-	if e1 != nil {
35
-		return nil, e1
36
-	}
37
-
38
-	resp, e2 := request.PostJSON(api.StartPushTicket, data)
36
+	resp, e2 := request.PostJSON(apiStartPushTicket, data)
39 37
 	if e2 != nil {
40 38
 		return nil, e2
41 39
 	}

service/query_auth.go → authorization/query_auth.go 查看文件

@@ -1,14 +1,12 @@
1
-package service
1
+package authorization
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"errors"
6 6
 	"net/url"
7 7
 
8
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/api"
9
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/entities"
10
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils"
11
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
8
+	wxerr "gitee.com/yansen_zh/wxcomponent/errors"
9
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
12 10
 )
13 11
 
14 12
 // QueryAuthParam 获取授权信息参数
@@ -19,33 +17,32 @@ type QueryAuthParam struct {
19 17
 
20 18
 // QueryAuthResult 获取授权信息结果
21 19
 type QueryAuthResult struct {
22
-	entities.Error
23
-	AuthorizationInfo entities.AuthorizationInfo `json:"authorization_info"`
20
+	wxerr.Error
21
+	AuthorizationInfo AuthorizationInfo `json:"authorization_info"`
24 22
 }
25 23
 
24
+const (
25
+	apiQueryAuth = "https://apies.weixin.qq.com/cgi-bin/component/api_query_auth"
26
+)
27
+
26 28
 // QueryAuth 获取授权信息
27
-func QueryAuth(componentAccessToken string, param QueryAuthParam) (*QueryAuthResult, error) {
29
+func QueryAuth(componentAccessToken string, data QueryAuthParam) (*QueryAuthResult, error) {
28 30
 	if componentAccessToken == "" {
29 31
 		return nil, errors.New("获取授权信息 第三方平台的 component_access_token 不能为空")
30 32
 	}
31 33
 
32
-	if param.ComponentAppId == "" {
34
+	if data.ComponentAppId == "" {
33 35
 		return nil, errors.New("获取授权信息 第三方平台的 appid 不能为空")
34 36
 	}
35 37
 
36
-	if param.AuthorizationCode == "" {
38
+	if data.AuthorizationCode == "" {
37 39
 		return nil, errors.New("获取授权信息 授权码 不能为空")
38 40
 	}
39 41
 
40
-	data, e1 := json.Marshal(param)
41
-	if e1 != nil {
42
-		return nil, e1
43
-	}
44
-
45 42
 	queryParam := url.Values{}
46 43
 	queryParam.Set("component_access_token", componentAccessToken)
47 44
 
48
-	apiUrl, _ := utils.ParseURL(api.QueryAuth, &queryParam)
45
+	apiUrl, _ := request.ParseURL(apiQueryAuth, &queryParam)
49 46
 	resp, e2 := request.PostJSON(apiUrl.String(), data)
50 47
 	if e2 != nil {
51 48
 		return nil, e2

+ 77
- 0
authorization/types.go 查看文件

@@ -0,0 +1,77 @@
1
+package authorization
2
+
3
+// Enum 通用枚举类型
4
+type Enum struct {
5
+	ID float64 `json:"id"`
6
+}
7
+
8
+// BusinessInfo 功能的开通状况(0代表未开通,1代表已开通)
9
+type BusinessInfo struct {
10
+	OpenStore float64 `json:"open_store"`
11
+	OpenScan  float64 `json:"open_scan"`
12
+	OpenPay   float64 `json:"open_pay"`
13
+	OpenCard  float64 `json:"open_card"`
14
+	OpenShake float64 `json:"open_shake"`
15
+}
16
+
17
+// FuncInfo 权限
18
+type FuncInfo struct {
19
+	FuncscopeCategory Enum `json:"funcscope_category"`
20
+}
21
+
22
+// MiniProgramNetwork 小程序配置的合法域名信息
23
+type MiniProgramNetwork struct {
24
+	RequestDomain   []string `json:"RequestDomain"`
25
+	WsRequestDomain []string `json:"WsRequestDomain"`
26
+	UploadDomain    []string `json:"UploadDomain"`
27
+	DownloadDomain  []string `json:"DownloadDomain"`
28
+	BizDomain       []string `json:"BizDomain"`
29
+	UDPDomain       []string `json:"UDPDomain"`
30
+}
31
+
32
+// MiniProgramCategory 小程序配置的类目信息
33
+type MiniProgramCategory struct {
34
+	First  string `json:"first"`
35
+	Second string `json:"second"`
36
+}
37
+
38
+// MiniProgramInfo 小程序配置
39
+type MiniProgramInfo struct {
40
+	Network    MiniProgramNetwork    `json:"network"`
41
+	Categories []MiniProgramCategory `json:"categories"`
42
+}
43
+
44
+// AuthorizerInfo 公众号/小程序帐号信息
45
+type AuthorizerInfo struct {
46
+	NickName        string          `json:"nick_name"`
47
+	HeadImg         string          `json:"head_img"`
48
+	ServiceTypeInfo Enum            `json:"service_type_info"`
49
+	VerifyTypeInfo  Enum            `json:"verify_type_info"`
50
+	UserName        string          `json:"user_name"`
51
+	PrincipalName   string          `json:"principal_name"`
52
+	Signature       string          `json:"signature"`
53
+	Alias           string          `json:"alias"`
54
+	BusinessInfo    BusinessInfo    `json:"business_info"`
55
+	QrcodeUrl       string          `json:"qrcode_url"`
56
+	MiniProgramInfo MiniProgramInfo `json:"MiniProgramInfo"`
57
+}
58
+
59
+// AuthorizationInfo 授权信息
60
+type AuthorizationInfo struct {
61
+	AuthorizerAppId        string     `json:"authorizer_appid"`
62
+	AuthorizerAccessToken  string     `json:"authorizer_access_token"`
63
+	ExpiresIn              float64    `json:"expires_in"`
64
+	AuthorizerRefreshToken string     `json:"authorizer_refresh_token"`
65
+	FuncInfo               []FuncInfo `json:"func_info"`
66
+}
67
+
68
+// AuthorizationChangeNotice 授权变更通知
69
+type AuthorizationChangeNotice struct {
70
+	AppId                        string  `json:"AppId"`
71
+	CreateTime                   float64 `json:"CreateTime"`
72
+	InfoType                     string  `json:"InfoType"`
73
+	AuthorizerAppid              string  `json:"AuthorizerAppid"`
74
+	AuthorizationCode            string  `json:"AuthorizationCode"`
75
+	AuthorizationCodeExpiredTime float64 `json:"AuthorizationCodeExpiredTime"`
76
+	PreAuthCode                  string  `json:"PreAuthCode"`
77
+}

service/verify_ticket.go → authorization/verify_ticket.go 查看文件

@@ -1,9 +1,9 @@
1
-package service
1
+package authorization
2 2
 
3 3
 import (
4 4
 	"encoding/xml"
5 5
 
6
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils/encrypt"
6
+	"gitee.com/yansen_zh/wxcomponent/utils/encrypt"
7 7
 )
8 8
 
9 9
 // ComponentVerifyTicketResult 获取验证票据结果

service/authorizer_list.go → authorizer/authorizer_list.go 查看文件

@@ -1,14 +1,12 @@
1
-package service
1
+package authorizer
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"errors"
6 6
 	"net/url"
7 7
 
8
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/api"
9
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/entities"
10
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils"
11
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
8
+	wxerr "gitee.com/yansen_zh/wxcomponent/errors"
9
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
12 10
 )
13 11
 
14 12
 // AuthorizerListParam 拉取所有已授权的帐号信息参数
@@ -20,42 +18,41 @@ type AuthorizerListParam struct {
20 18
 
21 19
 // AuthorizerListResult 拉取所有已授权的帐号信息结果
22 20
 type AuthorizerListResult struct {
23
-	entities.Error
24
-	TotalCount float64                        `json:"total_count"`
25
-	List       []entities.AuthorizerBasicInfo `json:"list"`
21
+	wxerr.Error
22
+	TotalCount float64               `json:"total_count"`
23
+	List       []AuthorizerBasicInfo `json:"list"`
26 24
 }
27 25
 
26
+const (
27
+	apiGetAuthorizerList = "https://apies.weixin.qq.com/cgi-bin/component/api_get_authorizer_list"
28
+)
29
+
28 30
 // AuthorizerList 拉取所有已授权的帐号信息
29
-func AuthorizerList(componentAccessToken string, param AuthorizerListParam) (*AuthorizerListResult, error) {
31
+func AuthorizerList(componentAccessToken string, data AuthorizerListParam) (*AuthorizerListResult, error) {
30 32
 	if componentAccessToken == "" {
31 33
 		return nil, errors.New("拉取所有已授权的帐号信息 第三方平台的 component_access_token 不能为空")
32 34
 	}
33 35
 
34
-	if param.ComponentAppId == "" {
36
+	if data.ComponentAppId == "" {
35 37
 		return nil, errors.New("拉取所有已授权的帐号信息 第三方平台的 appid 不能为空")
36 38
 	}
37 39
 
38
-	if param.Offset < 0 {
39
-		param.Offset = 0
40
-	}
41
-
42
-	if param.Count < 0 {
43
-		param.Count = 100
40
+	if data.Offset < 0 {
41
+		data.Offset = 0
44 42
 	}
45 43
 
46
-	if param.Count > 500 {
47
-		param.Count = 500
44
+	if data.Count < 0 {
45
+		data.Count = 100
48 46
 	}
49 47
 
50
-	data, e1 := json.Marshal(param)
51
-	if e1 != nil {
52
-		return nil, e1
48
+	if data.Count > 500 {
49
+		data.Count = 500
53 50
 	}
54 51
 
55 52
 	queryParam := url.Values{}
56 53
 	queryParam.Set("component_access_token", componentAccessToken)
57 54
 
58
-	apiUrl, _ := utils.ParseURL(api.GetAuthorizerList, &queryParam)
55
+	apiUrl, _ := request.ParseURL(apiGetAuthorizerList, &queryParam)
59 56
 	resp, e2 := request.PostJSON(apiUrl.String(), data)
60 57
 	if e2 != nil {
61 58
 		return nil, e2

+ 68
- 0
authorizer/get_authorizer_option.go 查看文件

@@ -0,0 +1,68 @@
1
+package authorizer
2
+
3
+import (
4
+	"encoding/json"
5
+	"errors"
6
+	"net/url"
7
+
8
+	wxerr "gitee.com/yansen_zh/wxcomponent/errors"
9
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
10
+)
11
+
12
+// GetAuthorizerOptionParam 获取授权方选项信息参数
13
+type GetAuthorizerOptionParam struct {
14
+	ComponentAppId  string `json:"component_appid"`
15
+	AuthorizerAppId string `json:"authorizer_appid"`
16
+	OptionName      string `json:"option_name"`
17
+}
18
+
19
+// GetAuthorizerOptionResult 获取授权方选项信息结果
20
+type GetAuthorizerOptionResult struct {
21
+	wxerr.Error
22
+	AuthorizerAppId string `json:"authorizer_appid"`
23
+	OptionName      string `json:"option_name"`
24
+	OptionValue     string `json:"option_value"`
25
+}
26
+
27
+const (
28
+	apiGetAuthorizerOption = "https://apies.weixin.qq.com/cgi-bin/component/api_get_authorizer_option"
29
+)
30
+
31
+// GetAuthorizerOption 获取授权方选项信息
32
+func GetAuthorizerOption(componentAccessToken string, data GetAuthorizerOptionParam) (*GetAuthorizerOptionResult, error) {
33
+	if componentAccessToken == "" {
34
+		return nil, errors.New("获取授权方选项信息 第三方平台的 component_access_token 不能为空")
35
+	}
36
+
37
+	if data.ComponentAppId == "" {
38
+		return nil, errors.New("获取授权方选项信息 授权公众号或小程序的 appid 不能为空")
39
+	}
40
+
41
+	if data.AuthorizerAppId == "" {
42
+		return nil, errors.New("获取授权方选项信息 第三方平台的 appid 不能为空")
43
+	}
44
+
45
+	if data.OptionName == "" {
46
+		return nil, errors.New("获取授权方选项信息 选项名称 不能为空")
47
+	}
48
+
49
+	queryParam := url.Values{}
50
+	queryParam.Set("component_access_token", componentAccessToken)
51
+
52
+	apiUrl, _ := request.ParseURL(apiGetAuthorizerOption, &queryParam)
53
+	resp, e2 := request.PostJSON(apiUrl.String(), data)
54
+	if e2 != nil {
55
+		return nil, e2
56
+	}
57
+
58
+	result := GetAuthorizerOptionResult{}
59
+	if err := json.Unmarshal(resp, &result); err != nil {
60
+		return nil, err
61
+	}
62
+
63
+	if result.Code != 0 {
64
+		return &result, result.Error
65
+	}
66
+
67
+	return &result, nil
68
+}

+ 70
- 0
authorizer/set_authorizer_option.go 查看文件

@@ -0,0 +1,70 @@
1
+package authorizer
2
+
3
+import (
4
+	"encoding/json"
5
+	"errors"
6
+	"net/url"
7
+
8
+	wxerr "gitee.com/yansen_zh/wxcomponent/errors"
9
+	"gitee.com/yansen_zh/wxcomponent/utils/request"
10
+)
11
+
12
+// SetAuthorizerOptionParam 设置授权方选项信息参数
13
+type SetAuthorizerOptionParam struct {
14
+	ComponentAppId  string `json:"component_appid"`
15
+	AuthorizerAppId string `json:"authorizer_appid"`
16
+	OptionName      string `json:"option_name"`
17
+	OptionValue     string `json:"option_value"`
18
+}
19
+
20
+// SetAuthorizerOptionResult 设置授权方选项信息结果
21
+type SetAuthorizerOptionResult struct {
22
+	wxerr.Error
23
+}
24
+
25
+const (
26
+	apiSetAuthorizerOption = "https://apies.weixin.qq.com/cgi-bin/component/api_set_authorizer_option"
27
+)
28
+
29
+// SetAuthorizerOption 设置授权方选项信息
30
+func SetAuthorizerOption(componentAccessToken string, data SetAuthorizerOptionParam) (*SetAuthorizerOptionResult, error) {
31
+	if componentAccessToken == "" {
32
+		return nil, errors.New("设置授权方选项信息 第三方平台的 component_access_token 不能为空")
33
+	}
34
+
35
+	if data.ComponentAppId == "" {
36
+		return nil, errors.New("设置授权方选项信息 授权公众号或小程序的 appid 不能为空")
37
+	}
38
+
39
+	if data.AuthorizerAppId == "" {
40
+		return nil, errors.New("设置授权方选项信息 第三方平台的 appid 不能为空")
41
+	}
42
+
43
+	if data.OptionName == "" {
44
+		return nil, errors.New("设置授权方选项信息 选项名称 不能为空")
45
+	}
46
+
47
+	if data.OptionValue == "" {
48
+		return nil, errors.New("设置授权方选项信息 设置的选项值 不能为空")
49
+	}
50
+
51
+	queryParam := url.Values{}
52
+	queryParam.Set("component_access_token", componentAccessToken)
53
+
54
+	apiUrl, _ := request.ParseURL(apiSetAuthorizerOption, &queryParam)
55
+	resp, e2 := request.PostJSON(apiUrl.String(), data)
56
+	if e2 != nil {
57
+		return nil, e2
58
+	}
59
+
60
+	result := SetAuthorizerOptionResult{}
61
+	if err := json.Unmarshal(resp, &result); err != nil {
62
+		return nil, err
63
+	}
64
+
65
+	if result.Code != 0 {
66
+		return &result, result.Error
67
+	}
68
+
69
+	return &result, nil
70
+}

+ 8
- 0
authorizer/types.go 查看文件

@@ -0,0 +1,8 @@
1
+package authorizer
2
+
3
+// AuthorizerBasicInfo 公众号/小程序帐号基本信息
4
+type AuthorizerBasicInfo struct {
5
+	AuthorizerAppid string  `json:"authorizer_appid"`
6
+	RefreshToken    string  `json:"refresh_token"`
7
+	AuthTime        float64 `json:"auth_time"`
8
+}

+ 0
- 12
entities/authorization_change_notice.go 查看文件

@@ -1,12 +0,0 @@
1
-package entities
2
-
3
-// AuthorizationChangeNotice 授权变更通知
4
-type AuthorizationChangeNotice struct {
5
-	AppId                        string  `json:"AppId"`
6
-	CreateTime                   float64 `json:"CreateTime"`
7
-	InfoType                     string  `json:"InfoType"`
8
-	AuthorizerAppid              string  `json:"AuthorizerAppid"`
9
-	AuthorizationCode            string  `json:"AuthorizationCode"`
10
-	AuthorizationCodeExpiredTime float64 `json:"AuthorizationCodeExpiredTime"`
11
-	PreAuthCode                  string  `json:"PreAuthCode"`
12
-}

+ 0
- 10
entities/authorization_info.go 查看文件

@@ -1,10 +0,0 @@
1
-package entities
2
-
3
-// AuthorizationInfo 授权信息
4
-type AuthorizationInfo struct {
5
-	AuthorizerAppId        string     `json:"authorizer_appid"`
6
-	AuthorizerAccessToken  string     `json:"authorizer_access_token"`
7
-	ExpiresIn              float64    `json:"expires_in"`
8
-	AuthorizerRefreshToken string     `json:"authorizer_refresh_token"`
9
-	FuncInfo               []FuncInfo `json:"func_info"`
10
-}

+ 0
- 23
entities/authorizer_info.go 查看文件

@@ -1,23 +0,0 @@
1
-package entities
2
-
3
-// AuthorizerBasicInfo 公众号/小程序帐号基本信息
4
-type AuthorizerBasicInfo struct {
5
-	AuthorizerAppid string  `json:"authorizer_appid"`
6
-	RefreshToken    string  `json:"refresh_token"`
7
-	AuthTime        float64 `json:"auth_time"`
8
-}
9
-
10
-// AuthorizerInfo 公众号/小程序帐号信息
11
-type AuthorizerInfo struct {
12
-	NickName        string          `json:"nick_name"`
13
-	HeadImg         string          `json:"head_img"`
14
-	ServiceTypeInfo Enum            `json:"service_type_info"`
15
-	VerifyTypeInfo  Enum            `json:"verify_type_info"`
16
-	UserName        string          `json:"user_name"`
17
-	PrincipalName   string          `json:"principal_name"`
18
-	Signature       string          `json:"signature"`
19
-	Alias           string          `json:"alias"`
20
-	BusinessInfo    BusinessInfo    `json:"business_info"`
21
-	QrcodeUrl       string          `json:"qrcode_url"`
22
-	MiniProgramInfo MiniProgramInfo `json:"MiniProgramInfo"`
23
-}

+ 0
- 10
entities/business_info.go 查看文件

@@ -1,10 +0,0 @@
1
-package entities
2
-
3
-// BusinessInfo 功能的开通状况(0代表未开通,1代表已开通)
4
-type BusinessInfo struct {
5
-	OpenStore float64 `json:"open_store"`
6
-	OpenScan  float64 `json:"open_scan"`
7
-	OpenPay   float64 `json:"open_pay"`
8
-	OpenCard  float64 `json:"open_card"`
9
-	OpenShake float64 `json:"open_shake"`
10
-}

+ 0
- 6
entities/entity.go 查看文件

@@ -1,6 +0,0 @@
1
-package entities
2
-
3
-// Enum 通用枚举类型
4
-type Enum struct {
5
-	ID float64 `json:"id"`
6
-}

+ 0
- 6
entities/func_info.go 查看文件

@@ -1,6 +0,0 @@
1
-package entities
2
-
3
-// FuncInfo 权限
4
-type FuncInfo struct {
5
-	FuncscopeCategory Enum `json:"funcscope_category"`
6
-}

+ 0
- 23
entities/mini_program_info.go 查看文件

@@ -1,23 +0,0 @@
1
-package entities
2
-
3
-// MiniProgramNetwork 小程序配置的合法域名信息
4
-type MiniProgramNetwork struct {
5
-	RequestDomain   []string `json:"RequestDomain"`
6
-	WsRequestDomain []string `json:"WsRequestDomain"`
7
-	UploadDomain    []string `json:"UploadDomain"`
8
-	DownloadDomain  []string `json:"DownloadDomain"`
9
-	BizDomain       []string `json:"BizDomain"`
10
-	UDPDomain       []string `json:"UDPDomain"`
11
-}
12
-
13
-// MiniProgramCategory 小程序配置的类目信息
14
-type MiniProgramCategory struct {
15
-	First  string `json:"first"`
16
-	Second string `json:"second"`
17
-}
18
-
19
-// MiniProgramInfo 小程序配置
20
-type MiniProgramInfo struct {
21
-	Network    MiniProgramNetwork    `json:"network"`
22
-	Categories []MiniProgramCategory `json:"categories"`
23
-}

entities/error.go → errors/error.go 查看文件

@@ -1,4 +1,4 @@
1
-package entities
1
+package errors
2 2
 
3 3
 import "fmt"
4 4
 

+ 1
- 1
go.mod 查看文件

@@ -1,3 +1,3 @@
1
-module gitee.com/yansen_zh/wechat-oplatform-sdk
1
+module gitee.com/yansen_zh/wxcomponent
2 2
 
3 3
 go 1.17

+ 10
- 0
init.go 查看文件

@@ -0,0 +1,10 @@
1
+package wxcomponent
2
+
3
+import (
4
+	"gitee.com/yansen_zh/wxcomponent/utils/log"
5
+)
6
+
7
+// InitLogger 初始化 Logger
8
+func InitLogger(logger log.Logger) {
9
+	log.SetLogger(logger)
10
+}

+ 0
- 9
interfaces/log.go 查看文件

@@ -1,9 +0,0 @@
1
-package interfaces
2
-
3
-type Logger interface {
4
-	// Error 级别日志
5
-	Error(...interface{})
6
-
7
-	// Info 级别错误
8
-	Info(...interface{})
9
-}

+ 0
- 132
service/authorizer_option.go 查看文件

@@ -1,132 +0,0 @@
1
-package service
2
-
3
-import (
4
-	"encoding/json"
5
-	"errors"
6
-	"net/url"
7
-
8
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/api"
9
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/entities"
10
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils"
11
-	"gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
12
-)
13
-
14
-// GetAuthorizerOptionParam 获取授权方选项信息参数
15
-type GetAuthorizerOptionParam struct {
16
-	ComponentAppId  string `json:"component_appid"`
17
-	AuthorizerAppId string `json:"authorizer_appid"`
18
-	OptionName      string `json:"option_name"`
19
-}
20
-
21
-// GetAuthorizerOptionResult 获取授权方选项信息结果
22
-type GetAuthorizerOptionResult struct {
23
-	entities.Error
24
-	AuthorizerAppId string `json:"authorizer_appid"`
25
-	OptionName      string `json:"option_name"`
26
-	OptionValue     string `json:"option_value"`
27
-}
28
-
29
-// GetAuthorizerOption 获取授权方选项信息
30
-func GetAuthorizerOption(componentAccessToken string, param GetAuthorizerOptionParam) (*GetAuthorizerOptionResult, error) {
31
-	if componentAccessToken == "" {
32
-		return nil, errors.New("获取授权方选项信息 第三方平台的 component_access_token 不能为空")
33
-	}
34
-
35
-	if param.ComponentAppId == "" {
36
-		return nil, errors.New("获取授权方选项信息 授权公众号或小程序的 appid 不能为空")
37
-	}
38
-
39
-	if param.AuthorizerAppId == "" {
40
-		return nil, errors.New("获取授权方选项信息 第三方平台的 appid 不能为空")
41
-	}
42
-
43
-	if param.OptionName == "" {
44
-		return nil, errors.New("获取授权方选项信息 选项名称 不能为空")
45
-	}
46
-
47
-	data, e1 := json.Marshal(param)
48
-	if e1 != nil {
49
-		return nil, e1
50
-	}
51
-
52
-	queryParam := url.Values{}
53
-	queryParam.Set("component_access_token", componentAccessToken)
54
-
55
-	apiUrl, _ := utils.ParseURL(api.GetAuthorizerOption, &queryParam)
56
-	resp, e2 := request.PostJSON(apiUrl.String(), data)
57
-	if e2 != nil {
58
-		return nil, e2
59
-	}
60
-
61
-	result := GetAuthorizerOptionResult{}
62
-	if err := json.Unmarshal(resp, &result); err != nil {
63
-		return nil, err
64
-	}
65
-
66
-	if result.Code != 0 {
67
-		return &result, result.Error
68
-	}
69
-
70
-	return &result, nil
71
-}
72
-
73
-// SetAuthorizerOptionParam 设置授权方选项信息参数
74
-type SetAuthorizerOptionParam struct {
75
-	ComponentAppId  string `json:"component_appid"`
76
-	AuthorizerAppId string `json:"authorizer_appid"`
77
-	OptionName      string `json:"option_name"`
78
-	OptionValue     string `json:"option_value"`
79
-}
80
-
81
-// SetAuthorizerOptionResult 设置授权方选项信息结果
82
-type SetAuthorizerOptionResult struct {
83
-	entities.Error
84
-}
85
-
86
-// SetAuthorizerOption 设置授权方选项信息
87
-func SetAuthorizerOption(componentAccessToken string, param SetAuthorizerOptionParam) (*SetAuthorizerOptionResult, error) {
88
-	if componentAccessToken == "" {
89
-		return nil, errors.New("设置授权方选项信息 第三方平台的 component_access_token 不能为空")
90
-	}
91
-
92
-	if param.ComponentAppId == "" {
93
-		return nil, errors.New("设置授权方选项信息 授权公众号或小程序的 appid 不能为空")
94
-	}
95
-
96
-	if param.AuthorizerAppId == "" {
97
-		return nil, errors.New("设置授权方选项信息 第三方平台的 appid 不能为空")
98
-	}
99
-
100
-	if param.OptionName == "" {
101
-		return nil, errors.New("设置授权方选项信息 选项名称 不能为空")
102
-	}
103
-
104
-	if param.OptionValue == "" {
105
-		return nil, errors.New("设置授权方选项信息 设置的选项值 不能为空")
106
-	}
107
-
108
-	data, e1 := json.Marshal(param)
109
-	if e1 != nil {
110
-		return nil, e1
111
-	}
112
-
113
-	queryParam := url.Values{}
114
-	queryParam.Set("component_access_token", componentAccessToken)
115
-
116
-	apiUrl, _ := utils.ParseURL(api.SetAuthorizerOption, &queryParam)
117
-	resp, e2 := request.PostJSON(apiUrl.String(), data)
118
-	if e2 != nil {
119
-		return nil, e2
120
-	}
121
-
122
-	result := SetAuthorizerOptionResult{}
123
-	if err := json.Unmarshal(resp, &result); err != nil {
124
-		return nil, err
125
-	}
126
-
127
-	if result.Code != 0 {
128
-		return &result, result.Error
129
-	}
130
-
131
-	return &result, nil
132
-}

+ 19
- 0
utils/log/logger.go 查看文件

@@ -0,0 +1,19 @@
1
+package log
2
+
3
+type Logger interface {
4
+	// Error 级别日志
5
+	Error(...interface{})
6
+
7
+	// Info 级别错误
8
+	Info(...interface{})
9
+}
10
+
11
+var inst Logger
12
+
13
+func SetLogger(logger Logger) {
14
+	inst = logger
15
+}
16
+
17
+func GetLogger() Logger {
18
+	return inst
19
+}

+ 19
- 2
utils/request/request.go 查看文件

@@ -2,12 +2,23 @@ package request
2 2
 
3 3
 import (
4 4
 	"bytes"
5
+	"encoding/json"
5 6
 	"errors"
6 7
 	"io"
7 8
 	"net/http"
9
+
10
+	"gitee.com/yansen_zh/wxcomponent/utils/log"
8 11
 )
9 12
 
10 13
 func post(url string, contentType string, body []byte) ([]byte, error) {
14
+
15
+	logger := log.GetLogger()
16
+	logger.Info("发送请求: ", url)
17
+
18
+	if len(body) > 0 {
19
+		logger.Info(body)
20
+	}
21
+
11 22
 	resp, e1 := http.Post(url, contentType, bytes.NewReader(body))
12 23
 	if e1 != nil {
13 24
 		return nil, e1
@@ -23,12 +34,18 @@ func post(url string, contentType string, body []byte) ([]byte, error) {
23 34
 		return nil, e2
24 35
 	}
25 36
 
37
+	logger.Info("微信端返回: ", body)
38
+
26 39
 	return body, nil
27 40
 }
28 41
 
29 42
 // PostJSON 使用 POST 方式发送 json 数据
30
-func PostJSON(url string, body []byte) ([]byte, error) {
43
+func PostJSON(url string, body interface{}) ([]byte, error) {
44
+	data, e1 := json.Marshal(body)
45
+	if e1 != nil {
46
+		return nil, e1
47
+	}
31 48
 
32
-	return post(url, ContentTypeJSON, body)
49
+	return post(url, ContentTypeJSON, data)
33 50
 
34 51
 }

utils/url.go → utils/request/url.go 查看文件

@@ -1,4 +1,4 @@
1
-package utils
1
+package request
2 2
 
3 3
 import "net/url"
4 4