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.
44 lines
2.2 KiB
44 lines
2.2 KiB
2 years ago
|
package wechatopen
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
2 years ago
|
"go.dtapp.net/library/gorequest"
|
||
2 years ago
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type CgiBinComponentApiAuthorizerTokenResponse struct {
|
||
|
AuthorizerAccessToken string `json:"authorizer_access_token"`
|
||
|
ExpiresIn int64 `json:"expires_in"`
|
||
|
AuthorizerRefreshToken string `json:"authorizer_refresh_token"`
|
||
|
}
|
||
|
|
||
|
type CgiBinComponentApiAuthorizerTokenResult struct {
|
||
|
Result CgiBinComponentApiAuthorizerTokenResponse // 结果
|
||
|
Body []byte // 内容
|
||
2 years ago
|
Http gorequest.Response // 请求
|
||
2 years ago
|
Err error // 错误
|
||
|
authorizerAppid string // 授权方 appid
|
||
|
}
|
||
|
|
||
2 years ago
|
func NewCgiBinComponentApiAuthorizerTokenResult(result CgiBinComponentApiAuthorizerTokenResponse, body []byte, http gorequest.Response, err error, authorizerAppid string) *CgiBinComponentApiAuthorizerTokenResult {
|
||
|
return &CgiBinComponentApiAuthorizerTokenResult{Result: result, Body: body, Http: http, Err: err, authorizerAppid: authorizerAppid}
|
||
2 years ago
|
}
|
||
|
|
||
|
// CgiBinComponentApiAuthorizerToken 获取/刷新接口调用令牌
|
||
|
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_authorizer_token.html
|
||
2 years ago
|
func (app *App) CgiBinComponentApiAuthorizerToken(authorizerRefreshToken string) *CgiBinComponentApiAuthorizerTokenResult {
|
||
2 years ago
|
// 参数
|
||
|
param := NewParams()
|
||
2 years ago
|
param["component_appid"] = app.componentAppId // 第三方平台 appid
|
||
|
param["authorizer_appid"] = app.authorizerAppid // 授权方 appid
|
||
|
param["authorizer_refresh_token"] = authorizerRefreshToken // 授权码, 会在授权成功时返回给第三方平台
|
||
2 years ago
|
params := app.NewParamsWith(param)
|
||
|
// 请求
|
||
2 years ago
|
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%v", app.GetComponentAccessToken()), params, http.MethodPost)
|
||
2 years ago
|
// 定义
|
||
|
var response CgiBinComponentApiAuthorizerTokenResponse
|
||
2 years ago
|
err = json.Unmarshal(request.ResponseBody, &response)
|
||
|
return NewCgiBinComponentApiAuthorizerTokenResult(response, request.ResponseBody, request, err, app.authorizerAppid)
|
||
2 years ago
|
}
|