You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/service/wechatopen/cgi-bin.component.api_query...

56 lines
3.0 KiB

2 years ago
package wechatopen
import (
2 years ago
"context"
1 year ago
"github.com/dtapps/go-library/utils/gojson"
2 years ago
"github.com/dtapps/go-library/utils/gorequest"
2 years ago
"net/http"
)
type CgiBinComponentApiQueryAuthResponse struct {
AuthorizationInfo struct {
AuthorizerAppid string `json:"authorizer_appid"` // 授权方 appid
AuthorizerAccessToken string `json:"authorizer_access_token"` // 接口调用令牌(在授权的公众号/小程序具备 API 权限时,才有此返回值)
ExpiresIn int64 `json:"expires_in"` // authorizer_access_token 的有效期(在授权的公众号/小程序具备API权限时才有此返回值单位
AuthorizerRefreshToken string `json:"authorizer_refresh_token"` // 刷新令牌在授权的公众号具备API权限时才有此返回值刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。一旦丢失只能让用户重新授权才能再次拿到新的刷新令牌。用户重新授权后之前的刷新令牌会失效
FuncInfo []struct {
FuncscopeCategory struct {
Id int `json:"id"`
} `json:"funcscope_category"`
ConfirmInfo struct {
NeedConfirm int `json:"need_confirm"`
AlreadyConfirm int `json:"already_confirm"`
CanConfirm int `json:"can_confirm"`
} `json:"confirm_info,omitempty"`
} `json:"func_info"`
} `json:"authorization_info"`
}
type CgiBinComponentApiQueryAuthResult struct {
Result CgiBinComponentApiQueryAuthResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
2 years ago
}
func newCgiBinComponentApiQueryAuthResult(result CgiBinComponentApiQueryAuthResponse, body []byte, http gorequest.Response) *CgiBinComponentApiQueryAuthResult {
return &CgiBinComponentApiQueryAuthResult{Result: result, Body: body, Http: http}
2 years ago
}
// CgiBinComponentApiQueryAuth 使用授权码获取授权信息
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/authorization_info.html
12 months ago
func (c *Client) CgiBinComponentApiQueryAuth(ctx context.Context, componentAccessToken, authorizationCode string, notMustParams ...gorequest.Params) (*CgiBinComponentApiQueryAuthResult, error) {
2 years ago
// 参数
params := gorequest.NewParamsWith(notMustParams...)
12 months ago
params.Set("component_appid", c.config.componentAppId) // 第三方平台appid
params.Set("authorization_code", authorizationCode) // 授权码会在授权成功时返回给第三方平台
2 years ago
// 请求
12 months ago
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_query_auth?component_access_token="+componentAccessToken, params, http.MethodPost)
if err != nil {
return newCgiBinComponentApiQueryAuthResult(CgiBinComponentApiQueryAuthResponse{}, request.ResponseBody, request), err
}
2 years ago
// 定义
var response CgiBinComponentApiQueryAuthResponse
1 year ago
err = gojson.Unmarshal(request.ResponseBody, &response)
return newCgiBinComponentApiQueryAuthResult(response, request.ResponseBody, request), err
2 years ago
}