authorizer_info.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 authorization
  13. import (
  14. "encoding/json"
  15. "errors"
  16. "net/url"
  17. "gitee.com/yansen_zh/wxcomponent/config"
  18. wxerr "gitee.com/yansen_zh/wxcomponent/errors"
  19. "gitee.com/yansen_zh/wxcomponent/utils/request"
  20. )
  21. // AuthorizerInfoResult 获取授权帐号信息结果
  22. type AuthorizerInfoResult struct {
  23. wxerr.Error
  24. AuthorizationInfo AuthorizationInfo `json:"authorization_info"`
  25. AuthorizerInfo AuthorizerInfo `json:"authorizer_info"`
  26. }
  27. const (
  28. apiGetAuthorizerInfo = "https://apies.weixin.qq.com/cgi-bin/component/api_get_authorizer_info"
  29. )
  30. // GetAuthorizerInfo 获取授权帐号信息
  31. func GetAuthorizerInfo(authorizerAppID string) (*AuthorizerInfoResult, error) {
  32. if authorizerAppID == "" {
  33. return nil, errors.New("获取授权帐号信息 授权方 appid 不能为空")
  34. }
  35. queryParam := url.Values{}
  36. queryParam.Set("component_access_token", config.GetAccessToken())
  37. data := map[string]string{
  38. "component_appid": config.GetAppID(),
  39. "authorizer_appid": authorizerAppID,
  40. }
  41. resp, e2 := request.PostJSON(apiGetAuthorizerInfo, &queryParam, data)
  42. if e2 != nil {
  43. return nil, e2
  44. }
  45. result := AuthorizerInfoResult{}
  46. if err := json.Unmarshal(resp, &result); err != nil {
  47. return nil, err
  48. }
  49. return &result, nil
  50. }