1 Star 0 Fork 0

GoMods / wechat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
get_access_token.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
wanglelecc 提交于 2022-01-11 18:47 . first commit
package auth
import (
"context"
"gitee.com/gomods/wechat/request"
)
const apiGetAccessToken = "/cgi-bin/token"
type GetAccessTokenRequest struct {
// 必填 填写 client_credential
GrantType string `query:"grant_type"`
// 必填 小程序唯一凭证,即 AppID,可在「微信公众平台 - 设置 - 开发设置」页中获得。(需要已经成为开发者,且帐号没有异常状态)
Appid string `query:"appid"`
// 必填 小程序唯一凭证密钥,即 AppSecret,获取方式同 appid
Secret string `query:"secret"`
}
type GetAccessTokenResponse struct {
request.CommonError
// 获取到的凭证
AccessToken string `json:"access_token"`
// 凭证有效时间,单位:秒。目前是7200秒之内的值。
ExpiresIn int64 `json:"expires_in"`
}
// 获取小程序全局唯一后台接口调用凭据
// 通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。
func (cli *Auth) GetAccessToken(ctx context.Context, req *GetAccessTokenRequest) (*GetAccessTokenResponse, error) {
api, err := cli.conbineURI(ctx, apiGetAccessToken, req, false)
if err != nil {
return nil, err
}
res := new(GetAccessTokenResponse)
err = cli.request.Get(ctx, api, res)
if err != nil {
return nil, err
}
return res, nil
}
1
https://gitee.com/gomods/wechat.git
git@gitee.com:gomods/wechat.git
gomods
wechat
wechat
v0.0.1

搜索帮助