Documentation
¶
Index ¶
- Constants
- func GetNonceStr(length int) string
- func GetSha1(data string) string
- type BaseOauthConfig
- type BaseOauthHandler
- type CommonErrResp
- type MiniOauthDataDecrypt
- type QQErrResp
- type QQMiniOauthHandler
- type QQMiniOauthUserInfo
- type QQMiniSessionKey
- type QQOauthHandler
- func (q *QQOauthHandler) GetAccessToken(ctx context.Context, code string) (*QQOauthToken, error)
- func (q *QQOauthHandler) GetOpenid(ctx context.Context, accessToken string) (*QQOauthMe, error)
- func (q *QQOauthHandler) GetRedirectUrl(state string, forMobile bool) (string, error)
- func (q *QQOauthHandler) GetUserInfo(ctx context.Context, openid, accessToken string) (*QQOauthUserInfo, error)
- type QQOauthMe
- type QQOauthRefreshToken
- type QQOauthToken
- type QQOauthUserInfo
- type UrlHelper
- type WatermarkInfo
- type WechatOauthHandler
- func (w *WechatOauthHandler) CheckToken(ctx context.Context, accessToken, openId string) error
- func (w *WechatOauthHandler) GetAccessToken(ctx context.Context, code string) (*WechatOauthToken, error)
- func (w *WechatOauthHandler) GetAuthorizeCodeUrl(ctx context.Context, state string) (string, error)
- func (w *WechatOauthHandler) GetQrCodeRedirectUrl(state string) (string, error)
- func (w *WechatOauthHandler) GetUserInfo(ctx context.Context, openId, accessToken string) (*WechatOauthUserInfo, error)
- func (w *WechatOauthHandler) RefreshToken(ctx context.Context, refreshToken string) (*WechatOauthToken, error)
- type WechatOauthToken
- type WechatOauthUserInfo
- type WxMiniOauthGetPhoneInfoReq
- type WxMiniOauthHandler
- func (w *WxMiniOauthHandler) CodeToSessionKey(ctx context.Context, code string) (*WxMiniSessionKey, error)
- func (w *WxMiniOauthHandler) GetAccessToken(ctx context.Context) (*WxMiniOauthToken, error)
- func (w *WxMiniOauthHandler) GetUserInfo(sessionKey, encryptedData, iv string) (*WxMiniOauthUserInfo, error)
- func (w *WxMiniOauthHandler) GetUserPhone(ctx context.Context, code, accessToken string) (*WxMiniOauthUserPhone, error)
- type WxMiniOauthPhoneInfo
- type WxMiniOauthToken
- type WxMiniOauthUserInfo
- type WxMiniOauthUserPhone
- type WxMiniSessionKey
- type WxOfficialAccessToken
- type WxOfficialHandler
- func (w *WxOfficialHandler) CheckExpire() bool
- func (w *WxOfficialHandler) GetAccessToken(ctx context.Context) (*WxOfficialAccessToken, error)
- func (w *WxOfficialHandler) GetJsApiConfig(ctx context.Context, ticket, url string) *WxOfficialJsApiConfig
- func (w *WxOfficialHandler) GetJsApiTicket(ctx context.Context, accessToken string) (*WxOfficialJsApiTicket, error)
- func (w *WxOfficialHandler) RefreshAccessTokenAndTicketToMemCache(ctx context.Context) error
- type WxOfficialJsApiConfig
- type WxOfficialJsApiTicket
Constants ¶
const ( SourceWxMini = "WxMini" SourceWechat = "Wechat" SourceQQ = "QQ" SourceQQMini = "QQMini" )
const ( Unknown = iota Male Female )
性别
const ( NanoIdAlphbet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" NonceStrLength = 15 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseOauthConfig ¶
type BaseOauthConfig struct {
// contains filtered or unexported fields
}
BaseOauthConfig 基础授权配置信息
type BaseOauthHandler ¶
type BaseOauthHandler struct{}
func (*BaseOauthHandler) GetGenderByInt ¶
func (b *BaseOauthHandler) GetGenderByInt(gender int) int
GetGenderByInt 微信、微信小程序的性别都是int,一样的值,不需要转换
func (*BaseOauthHandler) GetGenderByString ¶
func (b *BaseOauthHandler) GetGenderByString(gender string) int
GetGenderByString qq的性别是中文,需要转换
type CommonErrResp ¶
CommonErrResp 微信通用错误响应结构
type MiniOauthDataDecrypt ¶
func NewMiniOauthDataDecrypt ¶
func NewMiniOauthDataDecrypt(sessionKey, encryptedData, iv string) *MiniOauthDataDecrypt
func (*MiniOauthDataDecrypt) Decrypt ¶
func (m *MiniOauthDataDecrypt) Decrypt() (string, error)
Decrypt 解密用户信息
func (*MiniOauthDataDecrypt) PKCS7UnPadding ¶
func (m *MiniOauthDataDecrypt) PKCS7UnPadding(plantText []byte) []byte
PKCS7UnPadding return un padding []Byte plantText
type QQErrResp ¶
type QQErrResp struct { Error int `json:"error"` ErrorDescription string `json:"error_description"` }
QQErrResp QQ授权错误结构
type QQMiniOauthHandler ¶
type QQMiniOauthHandler struct { *BaseOauthHandler BaseOauthConfig }
func NewQQMiniOauthHandler ¶
func NewQQMiniOauthHandler(appId, appSecret string) *QQMiniOauthHandler
NewQQMiniOauthHandler QQ小程序授权工具
func (*QQMiniOauthHandler) CodeToSessionKey ¶
func (w *QQMiniOauthHandler) CodeToSessionKey(ctx context.Context, code string) (*QQMiniSessionKey, error)
CodeToSessionKey 小程序触发qq.login()获取code,再获取QQ小程序授权凭证
func (*QQMiniOauthHandler) GetUserInfo ¶
func (w *QQMiniOauthHandler) GetUserInfo(sessionKey, encryptedData, iv string) (*QQMiniOauthUserInfo, error)
GetUserInfo 小程序qq.getUserInfo()获取加密信息,解密加密串,获取QQ小程序授权用户的信息
type QQMiniOauthUserInfo ¶
type QQMiniOauthUserInfo struct { OpenId string `json:"openId"` UnionId string `json:"unionId"` NickName string `json:"nickName"` Language string `json:"language"` Gender int `json:"gender"` // 0未知 1为男性,2为女性 Province string `json:"province"` City string `json:"city"` Country string `json:"country"` AvatarUrl string `json:"avatarUrl"` Watermark *WatermarkInfo `json:"watermark"` }
type QQMiniSessionKey ¶
type QQMiniSessionKey struct { CommonErrResp SessionKey string `json:"session_key"` Openid string `json:"openid"` Unionid string `json:"unionid"` }
type QQOauthHandler ¶
type QQOauthHandler struct { *BaseOauthHandler BaseOauthConfig // contains filtered or unexported fields }
func NewQQOauthHandler ¶
func NewQQOauthHandler(appId, appSecret, redirectUrl string) *QQOauthHandler
NewQQOauthHandler QQ授权工具
func (*QQOauthHandler) GetAccessToken ¶
func (q *QQOauthHandler) GetAccessToken(ctx context.Context, code string) (*QQOauthToken, error)
GetAccessToken code换取QQ授权的accessToken
func (*QQOauthHandler) GetRedirectUrl ¶
func (q *QQOauthHandler) GetRedirectUrl(state string, forMobile bool) (string, error)
GetRedirectUrl 获取授权重定向地址,state可以使用唯一凭证, forMobile = true 表示移动端授权,不传则默认为 PC
func (*QQOauthHandler) GetUserInfo ¶
func (q *QQOauthHandler) GetUserInfo(ctx context.Context, openid, accessToken string) (*QQOauthUserInfo, error)
GetUserInfo 获取QQ授权用户的信息
type QQOauthRefreshToken ¶
type QQOauthToken ¶
type QQOauthUserInfo ¶
type UrlHelper ¶
type UrlHelper struct {
// contains filtered or unexported fields
}
func NewUrlHelper ¶
type WatermarkInfo ¶
func (*WatermarkInfo) WatermarkValidate ¶
func (w *WatermarkInfo) WatermarkValidate(appId string) bool
WatermarkValidate 校验 appId与watermark里的 是否一致
type WechatOauthHandler ¶
type WechatOauthHandler struct { *BaseOauthHandler BaseOauthConfig // contains filtered or unexported fields }
func NewWechatOauthHandler ¶
func NewWechatOauthHandler(appId, appSecret, redirectUrl string) *WechatOauthHandler
NewWechatOauthHandler 微信授权工具
func (*WechatOauthHandler) CheckToken ¶
func (w *WechatOauthHandler) CheckToken(ctx context.Context, accessToken, openId string) error
CheckToken 检查accessToken是否有效
func (*WechatOauthHandler) GetAccessToken ¶
func (w *WechatOauthHandler) GetAccessToken(ctx context.Context, code string) (*WechatOauthToken, error)
GetAccessToken code换取微信授权的accessToken
func (*WechatOauthHandler) GetAuthorizeCodeUrl ¶
GetAuthorizeCodeUrl 微信内部H5登录获取code
func (*WechatOauthHandler) GetQrCodeRedirectUrl ¶
func (w *WechatOauthHandler) GetQrCodeRedirectUrl(state string) (string, error)
GetQrCodeRedirectUrl 获取微信授权重定向地址进行扫码,state可以使用唯一凭证
func (*WechatOauthHandler) GetUserInfo ¶
func (w *WechatOauthHandler) GetUserInfo(ctx context.Context, openId, accessToken string) (*WechatOauthUserInfo, error)
GetUserInfo 获取微信授权用户的信息
func (*WechatOauthHandler) RefreshToken ¶
func (w *WechatOauthHandler) RefreshToken(ctx context.Context, refreshToken string) (*WechatOauthToken, error)
RefreshToken 刷新accessToken有效期
type WechatOauthToken ¶
type WechatOauthUserInfo ¶
type WechatOauthUserInfo struct { CommonErrResp Openid string `json:"openid"` Unionid string `json:"unionid"` Nickname string `json:"nickname"` Sex int `json:"sex"` // 0未知 1为男性,2为女性 Province string `json:"province"` City string `json:"city"` Country string `json:"country"` Headimgurl string `json:"headimgurl"` Privilege []string `json:"privilege"` }
type WxMiniOauthGetPhoneInfoReq ¶
type WxMiniOauthGetPhoneInfoReq struct {
Code string `json:"code"`
}
type WxMiniOauthHandler ¶
type WxMiniOauthHandler struct { *BaseOauthHandler BaseOauthConfig }
func NewWxMiniOauthHandler ¶
func NewWxMiniOauthHandler(appId, appSecret string) *WxMiniOauthHandler
NewWxMiniOauthHandler 微信小程序授权工具
func (*WxMiniOauthHandler) CodeToSessionKey ¶
func (w *WxMiniOauthHandler) CodeToSessionKey(ctx context.Context, code string) (*WxMiniSessionKey, error)
CodeToSessionKey 小程序触发wx.login()获取code,再获取微信小程序授权凭证
func (*WxMiniOauthHandler) GetAccessToken ¶
func (w *WxMiniOauthHandler) GetAccessToken(ctx context.Context) (*WxMiniOauthToken, error)
GetAccessToken 获取微信小程序后台调用accessToken
func (*WxMiniOauthHandler) GetUserInfo ¶
func (w *WxMiniOauthHandler) GetUserInfo(sessionKey, encryptedData, iv string) (*WxMiniOauthUserInfo, error)
GetUserInfo 小程序wx.getUserProfile()获取加密信息,解密加密串,获取微信小程序授权用户的信息
func (*WxMiniOauthHandler) GetUserPhone ¶
func (w *WxMiniOauthHandler) GetUserPhone(ctx context.Context, code, accessToken string) (*WxMiniOauthUserPhone, error)
GetUserPhone 获取微信小程序授权用户的手机
type WxMiniOauthPhoneInfo ¶
type WxMiniOauthPhoneInfo struct { PhoneNumber string `json:"phoneNumber"` PurePhoneNumber string `json:"purePhoneNumber"` CountryCode int `json:"countryCode"` Watermark *WatermarkInfo `json:"watermark"` }
type WxMiniOauthToken ¶
type WxMiniOauthToken struct { CommonErrResp AccessToken string `json:"access_token"` ExpiresIn int `json:"expires_in"` }
type WxMiniOauthUserInfo ¶
type WxMiniOauthUserInfo struct { OpenId string `json:"openId"` UnionId string `json:"unionId"` NickName string `json:"nickName"` Language string `json:"language"` Gender int `json:"gender"` // 0未知 1为男性,2为女性 Province string `json:"province"` City string `json:"city"` Country string `json:"country"` AvatarUrl string `json:"avatarUrl"` Watermark *WatermarkInfo `json:"watermark"` }
type WxMiniOauthUserPhone ¶
type WxMiniOauthUserPhone struct { CommonErrResp PhoneInfo *WxMiniOauthPhoneInfo `json:"phone_info"` }
type WxMiniSessionKey ¶
type WxMiniSessionKey struct { CommonErrResp SessionKey string `json:"session_key"` Openid string `json:"openid"` Unionid string `json:"unionid"` }
type WxOfficialAccessToken ¶ added in v0.2.0
type WxOfficialAccessToken struct { CommonErrResp AccessToken string `json:"access_token"` ExpiresIn int `json:"expires_in"` }
type WxOfficialHandler ¶ added in v0.2.0
type WxOfficialHandler struct { BaseOauthConfig AccessToken string JsapiTicket string // contains filtered or unexported fields }
WxOfficialHandler 微信公众号
func NewWxOfficialHandler ¶ added in v0.2.0
func NewWxOfficialHandler(appId, appSecret string) *WxOfficialHandler
NewWxOfficialHandler 微信公众号授权工具
func (*WxOfficialHandler) CheckExpire ¶ added in v0.2.0
func (w *WxOfficialHandler) CheckExpire() bool
func (*WxOfficialHandler) GetAccessToken ¶ added in v0.2.0
func (w *WxOfficialHandler) GetAccessToken(ctx context.Context) (*WxOfficialAccessToken, error)
GetAccessToken 获取公众号的accessToken
func (*WxOfficialHandler) GetJsApiConfig ¶ added in v0.2.0
func (w *WxOfficialHandler) GetJsApiConfig(ctx context.Context, ticket, url string) *WxOfficialJsApiConfig
GetJsApiConfig 获取js-sdk的config
func (*WxOfficialHandler) GetJsApiTicket ¶ added in v0.2.0
func (w *WxOfficialHandler) GetJsApiTicket(ctx context.Context, accessToken string) (*WxOfficialJsApiTicket, error)
GetJsApiTicket 获取js-sdk的ticket
func (*WxOfficialHandler) RefreshAccessTokenAndTicketToMemCache ¶ added in v0.2.0
func (w *WxOfficialHandler) RefreshAccessTokenAndTicketToMemCache(ctx context.Context) error
RefreshAccessTokenAndTicketToMemCache 如果有redis缓存,建议使用redis分布式缓存,单服务部署则直接使用
type WxOfficialJsApiConfig ¶ added in v0.2.0
type WxOfficialJsApiTicket ¶ added in v0.2.0
type WxOfficialJsApiTicket struct { CommonErrResp Ticket string `json:"ticket"` ExpiresIn int `json:"expires_in"` }