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.
|
|
|
|
package wechatminiprogram
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// AuthGetAccessTokenResult 返回参数
|
|
|
|
|
type AuthGetAccessTokenResult struct {
|
|
|
|
|
AccessToken string `json:"access_token"` // 获取到的凭证
|
|
|
|
|
ExpiresIn int `json:"expires_in"` // 凭证有效时间,单位:秒。目前是7200秒之内的值
|
|
|
|
|
Errcode int `json:"errcode"` // 错误码
|
|
|
|
|
Errmsg string `json:"errmsg"` // 错误信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *App) AuthGetAccessToken() (result AuthGetAccessTokenResult, err error) {
|
|
|
|
|
// 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")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err = json.Unmarshal(body, &result); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|