1 Star 0 Fork 0

vibly/wechat-sdk

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
oauth2.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
夏雨天 提交于 2023-05-12 08:37 +08:00 . init
package oauth2
import (
"time"
)
type Endpoint interface {
ExchangeTokenURL(code string) string // 通过code换取access_token的地址
RefreshTokenURL(refreshToken string) string // 刷新access_token的地址
}
type TokenStorage interface {
Token() (*Token, error)
PutToken(*Token) error
}
type Token struct {
AccessToken string `json:"access_token"` // 网页授权接口调用凭证
CreatedAt int64 `json:"created_at"` // access_token 创建时间, unixtime, 分布式系统要求时间同步, 建议使用 NTP
ExpiresIn int64 `json:"expires_in"` // access_token 接口调用凭证超时时间, 单位: 秒
RefreshToken string `json:"refresh_token,omitempty"` // 刷新 access_token 的凭证
OpenId string `json:"openid,omitempty"`
UnionId string `json:"unionid,omitempty"`
Scope string `json:"scope,omitempty"` // 用户授权的作用域, 使用逗号(,)分隔
}
// Expired 判断 token.AccessToken 是否过期, 过期返回 true, 否则返回 false.
func (token *Token) Expired() bool {
return time.Now().Unix() >= token.CreatedAt+token.ExpiresIn
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vibly/wechat-sdk.git
git@gitee.com:vibly/wechat-sdk.git
vibly
wechat-sdk
wechat-sdk
v1.0.0

搜索帮助