authorizer_list.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Copyright (c) 2022 Yansen Zhang
  3. * wxcomponent is licensed under Mulan PSL v2.
  4. * You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. * You may obtain a copy of Mulan PSL v2 at:
  6. * http://license.coscl.org.cn/MulanPSL2
  7. * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. * See the Mulan PSL v2 for more details.
  11. **/
  12. package authorizer
  13. import (
  14. "encoding/json"
  15. "net/url"
  16. "gitee.com/yansen_zh/wxcomponent/config"
  17. "gitee.com/yansen_zh/wxcomponent/errors"
  18. "gitee.com/yansen_zh/wxcomponent/utils/request"
  19. )
  20. // AuthorizerListResult 拉取所有已授权的帐号信息结果
  21. type AuthorizerListResult struct {
  22. errors.Error
  23. TotalCount int `json:"total_count"`
  24. List []AuthorizerBasicInfo `json:"list"`
  25. }
  26. const (
  27. apiGetAuthorizerList = "https://apies.weixin.qq.com/cgi-bin/component/api_get_authorizer_list"
  28. )
  29. // GetAuthorizerList 拉取所有已授权的帐号信息
  30. func GetAuthorizerList(offset, count int) (*AuthorizerListResult, error) {
  31. if offset < 0 {
  32. offset = 0
  33. }
  34. if count < 0 {
  35. count = 100
  36. }
  37. if count > 500 {
  38. count = 500
  39. }
  40. queryParam := url.Values{}
  41. queryParam.Set("component_access_token", config.GetAccessToken())
  42. data := map[string]interface{}{
  43. "component_appid": config.GetAppID(),
  44. "offset": offset,
  45. "count": count,
  46. }
  47. resp, e2 := request.PostJSON(apiGetAuthorizerList, &queryParam, data)
  48. if e2 != nil {
  49. return nil, e2
  50. }
  51. result := AuthorizerListResult{}
  52. if err := json.Unmarshal(resp, &result); err != nil {
  53. return nil, err
  54. }
  55. return &result, nil
  56. }