oauth

package
v2.0.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Oauth

type Oauth struct {
	*context.Context
}

Oauth 保存用户授权信息

func NewOauth

func NewOauth(context *context.Context) *Oauth

NewOauth 实例化授权信息

func (*Oauth) CheckAccessToken

func (oauth *Oauth) CheckAccessToken(accessToken, openID string) (b bool, err error)

CheckAccessToken 检验access_token是否有效

func (*Oauth) GetQyRedirectURL

func (oauth *Oauth) GetQyRedirectURL(redirectURI, agentid, scope, state string) (string, error)

GetQyRedirectURL 获取企业微信跳转的url地址

func (*Oauth) GetQyUserDetailUserTicket

func (oauth *Oauth) GetQyUserDetailUserTicket(userTicket string) (result QyUserDetail, err error)

GetQyUserDetailUserTicket 根据user_ticket获取到用户详情

func (*Oauth) GetQyUserInfoByCode

func (oauth *Oauth) GetQyUserInfoByCode(code string) (result QyUserInfo, err error)

GetQyUserInfoByCode 根据code获取企业user_info

func (*Oauth) GetRedirectURL

func (oauth *Oauth) GetRedirectURL(redirectURI, scope, state string) (string, error)

GetRedirectURL 获取跳转的url地址

func (*Oauth) GetUserAccessToken

func (oauth *Oauth) GetUserAccessToken(code string) (result ResAccessToken, err error)

GetUserAccessToken 通过网页授权的code 换取access_token(区别于context中的access_token)

func (*Oauth) GetUserInfo

func (oauth *Oauth) GetUserInfo(accessToken, openID string) (result UserInfo, err error)

GetUserInfo 如果scope为 snsapi_userinfo 则可以通过此方法获取到用户基本信息

func (*Oauth) GetWebAppRedirectURL

func (oauth *Oauth) GetWebAppRedirectURL(redirectURI, scope, state string) (string, error)

GetWebAppRedirectURL 获取网页应用跳转的url地址

func (*Oauth) Redirect

func (oauth *Oauth) Redirect(writer http.ResponseWriter, req *http.Request, redirectURI, scope, state string) error

Redirect 跳转到网页授权

func (*Oauth) RefreshAccessToken

func (oauth *Oauth) RefreshAccessToken(refreshToken string) (result ResAccessToken, err error)

RefreshAccessToken 刷新access_token

type QyUserDetail

type QyUserDetail struct {
	util.CommonError

	UserID string `json:"UserId"`
	Name   string `json:"name"`
	Mobile string `json:"mobile"`
	Gender string `json:"gender"`
	Email  string `json:"email"`
	Avatar string `json:"avatar"`
	QrCode string `json:"qr_code"`
}

QyUserDetail 到用户详情

type QyUserInfo

type QyUserInfo struct {
	util.CommonError

	UserID     string `json:"UserId"`
	DeviceID   string `json:"DeviceId"`
	UserTicket string `json:"user_ticket"`
	ExpiresIn  int64  `json:"expires_in"`
}

QyUserInfo 用户授权获取到用户信息

type ResAccessToken

type ResAccessToken struct {
	util.CommonError

	AccessToken  string `json:"access_token"`
	ExpiresIn    int64  `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	OpenID       string `json:"openid"`
	Scope        string `json:"scope"`

	// UnionID 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
	// 公众号文档 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
	UnionID string `json:"unionid"`
}

ResAccessToken 获取用户授权access_token的返回结果

type UserInfo

type UserInfo struct {
	util.CommonError

	OpenID     string   `json:"openid"`
	Nickname   string   `json:"nickname"`
	Sex        int32    `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 用户授权获取到用户信息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL