1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /**
- * Copyright (c) 2022 Yansen Zhang
- * wxcomponent is licensed under Mulan PSL v2.
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
- * You may obtain a copy of Mulan PSL v2 at:
- * http://license.coscl.org.cn/MulanPSL2
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- * See the Mulan PSL v2 for more details.
- **/
-
- package authorizer
-
- import (
- "encoding/json"
- "errors"
- "net/url"
-
- wxerr "gitee.com/yansen_zh/wxcomponent/errors"
- "gitee.com/yansen_zh/wxcomponent/utils/request"
- )
-
- // AuthorizerListParam 拉取所有已授权的帐号信息参数
- type AuthorizerListParam struct {
- ComponentAppId string `json:"component_appid"`
- Offset int `json:"offset"`
- Count int `json:"count"`
- }
-
- // AuthorizerListResult 拉取所有已授权的帐号信息结果
- 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"
- )
-
- // AuthorizerList 拉取所有已授权的帐号信息
- func AuthorizerList(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)
-
- apiUrl, _ := request.ParseURL(apiGetAuthorizerList, &queryParam)
- resp, e2 := request.PostJSON(apiUrl.String(), data)
- if e2 != nil {
- return nil, e2
- }
-
- result := AuthorizerListResult{}
- if err := json.Unmarshal(resp, &result); err != nil {
- return nil, err
- }
-
- if result.Code != 0 {
- return &result, result.Error
- }
-
- return &result, nil
- }
|