set_authorizer_option.go 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. "errors"
  15. "net/url"
  16. "gitee.com/yansen_zh/wxcomponent/config"
  17. "gitee.com/yansen_zh/wxcomponent/utils/request"
  18. )
  19. const (
  20. apiSetAuthorizerOption = "https://apies.weixin.qq.com/cgi-bin/component/api_set_authorizer_option"
  21. )
  22. // SetAuthorizerOption 设置授权方选项信息
  23. func SetAuthorizerOption(authorizerAppID, optionName, optionValue string) error {
  24. if authorizerAppID == "" {
  25. return errors.New("设置授权方选项信息 第三方平台的 appid 不能为空")
  26. }
  27. if optionName == "" {
  28. return errors.New("设置授权方选项信息 选项名称 不能为空")
  29. }
  30. if optionValue == "" {
  31. return errors.New("设置授权方选项信息 设置的选项值 不能为空")
  32. }
  33. queryParam := url.Values{}
  34. queryParam.Set("component_access_token", config.GetAccessToken())
  35. data := map[string]string{
  36. "component_appid": config.GetAppID(),
  37. "authorizer_appid": authorizerAppID,
  38. "option_name": optionName,
  39. "option_value": optionValue,
  40. }
  41. _, err := request.PostJSON(apiSetAuthorizerOption, &queryParam, data)
  42. return err
  43. }