oauth2

package
v0.0.0-...-aad7e29 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	SexUnknown = 0 // 未知
	SexMale    = 1 // 男性
	SexFemale  = 2 // 女性
)

Variables

View Source
var ErrNoHeadImage = errors.New("没有头像")

Functions

func AuthCodeURL

func AuthCodeURL(appId, redirectURI, scope, state string, redirectURIExt url.Values) string

Types

type Config

type Config struct {
	AppId     string
	AppSecret string

	// 用户授权后跳转的目的地址
	// 用户授权后跳转到 RedirectURI?code=CODE&state=STATE
	// 用户禁止授权跳转到 RedirectURI?state=STATE
	RedirectURI string

	// 应用授权作用域, snsapi_base, snsapi_userinfo
	Scopes []string
}

func NewConfig

func NewConfig(AppId, AppSecret, RedirectURI string, Scope ...string) *Config

func (*Config) AuthCodeURL

func (cfg *Config) AuthCodeURL(state string, redirectURIExt url.Values) string

func (*Config) ExchangeTokenURL

func (cfg *Config) ExchangeTokenURL(code string) string

func (*Config) RefreshTokenURL

func (cfg *Config) RefreshTokenURL(refreshToken string) string

func (*Config) UserInfoURL

func (cfg *Config) UserInfoURL(accessToken, openId, lang string) string

type UserInfo

type UserInfo struct {
	OpenId   string `json:"openid"`   // 用户的唯一标识
	Nickname string `json:"nickname"` // 用户昵称
	Sex      int    `json:"sex"`      // 用户的性别, 值为1时是男性, 值为2时是女性, 值为0时是未知
	City     string `json:"city"`     // 普通用户个人资料填写的城市
	Province string `json:"province"` // 用户个人资料填写的省份
	Country  string `json:"country"`  // 国家, 如中国为CN

	// 用户头像, 最后一个数值代表正方形头像大小(有0, 46, 64, 96, 132数值可选, 0代表640*640正方形头像),
	// 用户没有头像时该项为空
	HeadImageURL string `json:"headimgurl"`

	// 用户特权信息, json 数组, 如微信沃卡用户为(chinaunicom)
	Privilege []string `json:"privilege"`

	// 用户统一标识. 针对一个微信开放平台帐号下的应用, 同一用户的unionid是唯一的.
	UnionId string `json:"unionid"`
}

func (*UserInfo) HeadImageSize

func (info *UserInfo) HeadImageSize() (size int, err error)

获取用户图像的大小, 如果用户没有图像则返回 ErrNoHeadImage 错误.

Jump to

Keyboard shortcuts

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