123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
-
-
- package authorizer
-
- import (
- "encoding/json"
- "errors"
- "net/url"
-
- wxerr "gitee.com/yansen_zh/wxcomponent/errors"
- "gitee.com/yansen_zh/wxcomponent/utils/request"
- )
-
-
- type AuthorizerListParam struct {
- ComponentAppId string `json:"component_appid"`
- Offset int `json:"offset"`
- Count int `json:"count"`
- }
-
-
- type AuthorizerListResult struct {
- wxerr.Error
- TotalCount int `json:"total_count"`
- List []AuthorizerBasicInfo `json:"list"`
- }
-
- const (
- apiGetAuthorizerList = "https://apies.weixin.qq.com/cgi-bin/component/api_get_authorizer_list"
- )
-
-
- func GetAuthorizerList(componentAccessToken string, data AuthorizerListParam) (*AuthorizerListResult, error) {
- if componentAccessToken == "" {
- return nil, errors.New("拉取所有已授权的帐号信息 第三方平台的 component_access_token 不能为空")
- }
-
- if data.ComponentAppId == "" {
- return nil, errors.New("拉取所有已授权的帐号信息 第三方平台的 appid 不能为空")
- }
-
- if data.Offset < 0 {
- data.Offset = 0
- }
-
- if data.Count < 0 {
- data.Count = 100
- }
-
- if data.Count > 500 {
- data.Count = 500
- }
-
- queryParam := url.Values{}
- queryParam.Set("component_access_token", componentAccessToken)
-
- resp, e2 := request.PostJSON(apiGetAuthorizerList, &queryParam, data)
- if e2 != nil {
- return nil, e2
- }
-
- result := AuthorizerListResult{}
- if err := json.Unmarshal(resp, &result); err != nil {
- return nil, err
- }
-
- return &result, nil
- }
|