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/wechatminiprogram/cgi-bin.token.go

36 lines
1.2 KiB

2 years ago
package wechatminiprogram
import (
"encoding/json"
"fmt"
)
// AuthGetAccessTokenResponse 返回参数
type AuthGetAccessTokenResponse struct {
2 years ago
AccessToken string `json:"access_token"` // 获取到的凭证
ExpiresIn int `json:"expires_in"` // 凭证有效时间单位秒。目前是7200秒之内的值
Errcode int `json:"errcode"` // 错误码
Errmsg string `json:"errmsg"` // 错误信息
}
// NewAuthGetAccessTokenResult 构造函数
func NewAuthGetAccessTokenResult(result AuthGetAccessTokenResponse, byte []byte, err error) *Result {
return &Result{
AuthGetAccessTokenResponse: result,
Byte: byte,
Err: err,
}
}
// AuthGetAccessToken
// 接口调用凭证
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
func (app *App) AuthGetAccessToken() *Result {
2 years ago
// request
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{}{}, "GET")
// 定义
var response AuthGetAccessTokenResponse
err = json.Unmarshal(body, &response)
return NewAuthGetAccessTokenResult(response, body, err)
2 years ago
}