12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
-
-
- package authorizer
-
- import (
- "encoding/json"
- "errors"
- "net/url"
-
- "gitee.com/yansen_zh/wxcomponent/config"
- wxerr "gitee.com/yansen_zh/wxcomponent/errors"
- "gitee.com/yansen_zh/wxcomponent/utils/request"
- )
-
-
- type GetAuthorizerOptionResult struct {
- wxerr.Error
- AuthorizerAppID string `json:"authorizer_appid"`
- OptionName string `json:"option_name"`
- OptionValue string `json:"option_value"`
- }
-
- const (
- apiGetAuthorizerOption = "https://apies.weixin.qq.com/cgi-bin/component/api_get_authorizer_option"
- )
-
-
- func GetAuthorizerOption(authorizerAppID string, optionName string) (*GetAuthorizerOptionResult, error) {
- if authorizerAppID == "" {
- return nil, errors.New("获取授权方选项信息 第三方平台的 appid 不能为空")
- }
-
- if optionName == "" {
- return nil, errors.New("获取授权方选项信息 选项名称 不能为空")
- }
-
- queryParam := url.Values{}
- queryParam.Set("component_access_token", config.GetAccessToken())
-
- data := map[string]string{
- "component_appid": config.GetAppID(),
- "authorizer_appid": authorizerAppID,
- "option_name": optionName,
- }
-
- resp, e2 := request.PostJSON(apiGetAuthorizerOption, &queryParam, data)
- if e2 != nil {
- return nil, e2
- }
-
- result := GetAuthorizerOptionResult{}
- if err := json.Unmarshal(resp, &result); err != nil {
- return nil, err
- }
-
- return &result, nil
- }
|