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/wechatunion/cgi_bin.token.go

43 lines
1.4 KiB

3 years ago
package wechatunion
import (
"encoding/json"
"fmt"
"net/http"
)
type authGetAccessTokenResult struct {
Byte []byte // 内容
Result authGetAccessTokenResponse // 结果
Err error // 错误
}
// NewAuthGetAccessTokenResult 实例化
func NewAuthGetAccessTokenResult(byte []byte, result authGetAccessTokenResponse, err error) *authGetAccessTokenResult {
return &authGetAccessTokenResult{
Byte: byte,
Result: result,
Err: err,
}
3 years ago
}
// AuthGetAccessToken
// 接口调用凭证
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
func (app *App) AuthGetAccessToken() *authGetAccessTokenResult {
3 years ago
// 请求
body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", app.AppId, app.AppSecret), map[string]interface{}{}, http.MethodGet)
// 定义
var response authGetAccessTokenResponse
err = json.Unmarshal(body, &response)
return NewAuthGetAccessTokenResult(body, response, err)
}
// 返回参数
type authGetAccessTokenResponse struct {
AccessToken string `json:"access_token"` // 获取到的凭证
ExpiresIn int `json:"expires_in"` // 凭证有效时间单位秒。目前是7200秒之内的值
Errcode int `json:"errcode"` // 错误码
Errmsg string `json:"errmsg"` // 错误信息
3 years ago
}