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

39 lines
1.4 KiB

2 years ago
package wechatminiprogram
import (
"encoding/json"
"fmt"
2 years ago
"go.dtapp.net/library/utils/gohttp"
"net/http"
2 years ago
)
2 years ago
type CgiBinTokenResponse struct {
2 years ago
AccessToken string `json:"access_token"` // 获取到的凭证
ExpiresIn int `json:"expires_in"` // 凭证有效时间单位秒。目前是7200秒之内的值
Errcode int `json:"errcode"` // 错误码
Errmsg string `json:"errmsg"` // 错误信息
}
2 years ago
type CgiBinTokenResult struct {
Result CgiBinTokenResponse // 结果
Body []byte // 内容
Http gohttp.Response // 请求
Err error // 错误
}
2 years ago
func NewCgiBinTokenResult(result CgiBinTokenResponse, body []byte, http gohttp.Response, err error) *CgiBinTokenResult {
return &CgiBinTokenResult{Result: result, Body: body, Http: http, Err: err}
}
2 years ago
// CgiBinToken
// 接口调用凭证
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
2 years ago
func (app *App) CgiBinToken() *CgiBinTokenResult {
// 请求
request, 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)
// 定义
2 years ago
var response CgiBinTokenResponse
err = json.Unmarshal(request.Body, &response)
2 years ago
return NewCgiBinTokenResult(response, request.Body, request, err)
2 years ago
}