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.
wechatopen/cgi-bin.component.api_query...

66 lines
2.9 KiB

2 years ago
package wechatopen
import (
2 years ago
"context"
2 years ago
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
"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
2 years ago
func (c *Client) CgiBinComponentApiQueryAuth(ctx context.Context, authorizationCode string) (*CgiBinComponentApiQueryAuthResult, error) {
// 检查
err := c.checkComponentIsConfig()
if err != nil {
return nil, err
}
2 years ago
// 参数
2 years ago
param := gorequest.NewParams()
2 years ago
param["component_appid"] = c.GetComponentAppId() // 第三方平台 appid
param["authorization_code"] = authorizationCode // 授权码, 会在授权成功时返回给第三方平台
2 years ago
params := gorequest.NewParamsWith(param)
2 years ago
// 请求
2 years ago
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/cgi-bin/component/api_query_auth?component_access_token=%v", c.GetComponentAccessToken(ctx)), params, http.MethodPost)
2 years ago
if err != nil {
return nil, err
}
2 years ago
// 定义
var response CgiBinComponentApiQueryAuthResponse
err = json.Unmarshal(request.ResponseBody, &response)
2 years ago
if err != nil {
return nil, err
}
return newCgiBinComponentApiQueryAuthResult(response, request.ResponseBody, request), nil
2 years ago
}