Documentation ¶
Index ¶
- func Signature(params ...string) string
- type CommonError
- type Config
- type JsConfig
- type Service
- type Ticket
- type Token
- type TokenService
- func (s *TokenService) CheckAccessToken(accessToken, openid string) (bool, error)
- func (s *TokenService) FindToken(openid string) (*Token, error)
- func (s *TokenService) GetUserInfo(accessToken, openid string) (*UserInfo, error)
- func (s *TokenService) RefreshAccessToken(openid, refreshToken string) (*Token, error)
- func (s *TokenService) SaveToken(code string, web bool) (*Token, error)
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CommonError ¶
type CommonError struct { ErrCode int `gorm:"-" json:"errcode"` ErrMsg string `gorm:"-" json:"errmsg"` }
CommonError 错误代码
type Config ¶
type Config struct { Appid string // 微信应用代码 AppSecret string // 微信密钥 WebAppid string // 网站微信应用代码 WebAppSecret string // 网站微信密钥 }
Config 配置
type JsConfig ¶
type JsConfig struct { Debug bool `json:"debug"` // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 Appid string `json:"appId"` // 必填,公众号的唯一标识 Timestamp int64 `json:"timestamp"` // 必填,生成签名的时间戳 NonceStr string `json:"nonceStr"` // 必填,生成签名的随机串 Signature string `json:"signature"` // 必填,签名 JsAPIList []string `json:"jsApiList"` // 必填,需要使用的JS接口列表 }
JsConfig js-api配置
type Service ¶
type Service struct { Cache *toolkit.Cache Config *Config TS *TokenService }
Service js服务
type Ticket ¶
type Ticket struct { CommonError ExpiresIn int `json:"expires_in"` Ticket string `json:"ticket"` }
Ticket JS-SDK使用授权
type Token ¶
type Token struct { CommonError Openid string `gorm:"primary_key;size:36" json:"openid"` AccessToken string `gorm:"size:512" json:"access_token"` ExpiresIn int `json:"expires_in"` RefreshToken string `gorm:"size:512" json:"refresh_token"` Scope string `gorm:"size:20" json:"scope"` Unionid string `gorm:"size:36" json:"unionid"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
Token 授权
type TokenService ¶
TokenService 授权服务
func NewTokenService ¶
func NewTokenService(db *gorm.DB, config *Config) *TokenService
NewTokenService 新建授权服务
func (*TokenService) CheckAccessToken ¶
func (s *TokenService) CheckAccessToken(accessToken, openid string) (bool, error)
CheckAccessToken 检验access_token是否有效
func (*TokenService) FindToken ¶
func (s *TokenService) FindToken(openid string) (*Token, error)
FindToken 查找Token
func (*TokenService) GetUserInfo ¶
func (s *TokenService) GetUserInfo(accessToken, openid string) (*UserInfo, error)
GetUserInfo 如果scope为 snsapi_userinfo 则可以通过此方法获取到用户基本信息
func (*TokenService) RefreshAccessToken ¶
func (s *TokenService) RefreshAccessToken(openid, refreshToken string) (*Token, error)
RefreshAccessToken 更新授权
type UserInfo ¶
type UserInfo struct { CommonError Openid string `json:"openid"` Nickname string `json:"nickname"` Sex int `json:"sex"` Province string `json:"province"` City string `json:"city"` Country string `json:"country"` HeadImgURL string `json:"headimgurl"` Privilege []string `json:"privilege"` Unionid string `json:"unionid"` }
UserInfo 用户信息
Click to show internal directories.
Click to hide internal directories.