123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package service
-
- import (
- "encoding/json"
- "errors"
- "net/url"
-
- "gitee.com/yansen_zh/wechat-oplatform-sdk/api"
- "gitee.com/yansen_zh/wechat-oplatform-sdk/entity"
- "gitee.com/yansen_zh/wechat-oplatform-sdk/utils"
- "gitee.com/yansen_zh/wechat-oplatform-sdk/utils/request"
- )
-
- // GetAuthorizerOptionParam 获取授权方选项信息参数
- type GetAuthorizerOptionParam struct {
- ComponentAppId string `json:"component_appid"`
- AuthorizerAppId string `json:"authorizer_appid"`
- OptionName string `json:"option_name"`
- }
-
- // GetAuthorizerOptionResult 获取授权方选项信息结果
- type GetAuthorizerOptionResult struct {
- entity.Error
- AuthorizerAppId string `json:"authorizer_appid"`
- OptionName string `json:"option_name"`
- OptionValue string `json:"option_value"`
- }
-
- // GetAuthorizerOption 获取授权方选项信息
- func GetAuthorizerOption(componentAccessToken string, param GetAuthorizerOptionParam) (*GetAuthorizerOptionResult, error) {
- if componentAccessToken == "" {
- return nil, errors.New("获取授权方选项信息 第三方平台的 component_access_token 不能为空")
- }
-
- if param.ComponentAppId == "" {
- return nil, errors.New("获取授权方选项信息 授权公众号或小程序的 appid 不能为空")
- }
-
- if param.AuthorizerAppId == "" {
- return nil, errors.New("获取授权方选项信息 第三方平台的 appid 不能为空")
- }
-
- if param.OptionName == "" {
- return nil, errors.New("获取授权方选项信息 选项名称 不能为空")
- }
-
- data, e1 := json.Marshal(param)
- if e1 != nil {
- return nil, e1
- }
-
- queryParam := url.Values{}
- queryParam.Set("component_access_token", componentAccessToken)
-
- apiUrl, _ := utils.ParseURL(api.GetAuthorizerOption, &queryParam)
- resp, e2 := request.PostJSON(apiUrl.String(), data)
- if e2 != nil {
- return nil, e2
- }
-
- result := GetAuthorizerOptionResult{}
- if err := json.Unmarshal(resp, &result); err != nil {
- return nil, err
- }
-
- if result.Code != 0 {
- return &result, result.Error
- }
-
- return &result, nil
- }
-
- // SetAuthorizerOptionParam 设置授权方选项信息参数
- type SetAuthorizerOptionParam struct {
- ComponentAppId string `json:"component_appid"`
- AuthorizerAppId string `json:"authorizer_appid"`
- OptionName string `json:"option_name"`
- OptionValue string `json:"option_value"`
- }
-
- // SetAuthorizerOptionResult 设置授权方选项信息结果
- type SetAuthorizerOptionResult struct {
- entity.Error
- }
-
- // SetAuthorizerOption 设置授权方选项信息
- func SetAuthorizerOption(componentAccessToken string, param SetAuthorizerOptionParam) (*SetAuthorizerOptionResult, error) {
- if componentAccessToken == "" {
- return nil, errors.New("设置授权方选项信息 第三方平台的 component_access_token 不能为空")
- }
-
- if param.ComponentAppId == "" {
- return nil, errors.New("设置授权方选项信息 授权公众号或小程序的 appid 不能为空")
- }
-
- if param.AuthorizerAppId == "" {
- return nil, errors.New("设置授权方选项信息 第三方平台的 appid 不能为空")
- }
-
- if param.OptionName == "" {
- return nil, errors.New("设置授权方选项信息 选项名称 不能为空")
- }
-
- if param.OptionValue == "" {
- return nil, errors.New("设置授权方选项信息 设置的选项值 不能为空")
- }
-
- data, e1 := json.Marshal(param)
- if e1 != nil {
- return nil, e1
- }
-
- queryParam := url.Values{}
- queryParam.Set("component_access_token", componentAccessToken)
-
- apiUrl, _ := utils.ParseURL(api.SetAuthorizerOption, &queryParam)
- resp, e2 := request.PostJSON(apiUrl.String(), data)
- if e2 != nil {
- return nil, e2
- }
-
- result := SetAuthorizerOptionResult{}
- if err := json.Unmarshal(resp, &result); err != nil {
- return nil, err
- }
-
- if result.Code != 0 {
- return &result, result.Error
- }
-
- return &result, nil
- }
|