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.
41 lines
1.8 KiB
41 lines
1.8 KiB
2 years ago
|
package wechatopen
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
2 years ago
|
"go.dtapp.net/library/gorequest"
|
||
2 years ago
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type CgiBinComponentApiComponentTokenResponse struct {
|
||
|
ComponentAccessToken string `json:"component_access_token"` // 第三方平台 access_token
|
||
|
ExpiresIn int64 `json:"expires_in"` // 有效期,单位:秒
|
||
|
}
|
||
|
|
||
|
type CgiBinComponentApiComponentTokenResult struct {
|
||
|
Result CgiBinComponentApiComponentTokenResponse // 结果
|
||
|
Body []byte // 内容
|
||
2 years ago
|
Http gorequest.Response // 请求
|
||
2 years ago
|
Err error // 错误
|
||
|
}
|
||
|
|
||
2 years ago
|
func NewCgiBinComponentApiComponentTokenResult(result CgiBinComponentApiComponentTokenResponse, body []byte, http gorequest.Response, err error) *CgiBinComponentApiComponentTokenResult {
|
||
|
return &CgiBinComponentApiComponentTokenResult{Result: result, Body: body, Http: http, Err: err}
|
||
2 years ago
|
}
|
||
|
|
||
|
// CgiBinComponentApiComponentToken 令牌
|
||
|
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/component_access_token.html
|
||
|
func (app *App) CgiBinComponentApiComponentToken() *CgiBinComponentApiComponentTokenResult {
|
||
|
// 参数
|
||
|
param := NewParams()
|
||
2 years ago
|
param["component_appid"] = app.componentAppId // 第三方平台 appid
|
||
|
param["component_appsecret"] = app.componentAppSecret // 第三方平台 appsecret
|
||
|
param["component_verify_ticket"] = app.GetComponentVerifyTicket() // 微信后台推送的 ticket
|
||
2 years ago
|
params := app.NewParamsWith(param)
|
||
|
// 请求
|
||
2 years ago
|
request, err := app.request("https://api.weixin.qq.com/cgi-bin/component/api_component_token", params, http.MethodPost)
|
||
2 years ago
|
// 定义
|
||
|
var response CgiBinComponentApiComponentTokenResponse
|
||
2 years ago
|
err = json.Unmarshal(request.ResponseBody, &response)
|
||
|
return NewCgiBinComponentApiComponentTokenResult(response, request.ResponseBody, request, err)
|
||
2 years ago
|
}
|