xlogin

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause-Clear Imports: 10 Imported by: 0

Documentation

Overview

三方登录服务

提供三方登录的一些授权标识、认证标识等 目前支持三方登录:WPS 此服务会注册一个三方授权表,用于存储三方授权的一些必要信息

Index

Constants

View Source
const (
	TypesWps    uint8 = iota + 1 // WPS登录
	TypesWechat                  // 微信公众号登录【H5】

)

定义三方登录所支持的类型

Variables

This section is empty.

Functions

func Bind

func Bind(openid string, typ uint8, user_id uint) error

Openid绑定

openid	三方唯一标识
typ		所属三方
user_id	待绑定的用户ID

func GetUrl

func GetUrl(urls string, typ uint8, state string) string

根据三方类型返回三方授权码

urls	回调跳转地址【会携带code等参数进行回调】
typ		三方类型
state	附加参数

func NsqRefToken

func NsqRefToken(param []byte) error

刷新Token信息

NSQ	xlogin.ref-token	<CodeToken>

func Regedit

func Regedit(conf *Config)

注入配置项

func UnBind

func UnBind(openid string, typ uint8) error

Openid解绑

openid	三方唯一标识
typ		所属三方

Types

type CodeToken

type CodeToken struct {
	AppId        string `json:"appid"`         // 用户的APPID,可能为空
	AccessToken  string `json:"access_token"`  // 网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同
	ExpiresIn    int    `json:"expires_in"`    // 必填,若三方返回的此值json对应错误,请手动重赋值给此值
	RefreshToken string `json:"refresh_token"` // 用户刷新access_token
	Openid       string `json:"openid"`        // 用户唯一标识,请注意,在未关注公众号时,用户访问公众号的网页,也会产生一个用户和公众号唯一的OpenID
	Scope        string `json:"scope"`         // 用户授权的作用域,使用逗号(,)分隔
	Unionid      string `json:"unionid"`       // 用户统一标识(针对一个微信开放平台账号下的应用,同一用户的 unionid 是唯一的),只有当scope为"snsapi_userinfo"时返回
	XloginType   uint8  `json:"xlogin_type"`   // 登录类型
}

func Code2token

func Code2token(code string, typ uint8) (*CodeToken, error)

根据code换取token

code	Code标识

func Openid2Token

func Openid2Token(openid string, typ uint8) (*CodeToken, error)

使用Openid换取Token【此服务依赖cache缓存和nsq刷新】

type Config

type Config struct {
	DB        *gorm.DB             // 数据库连接
	TableName string               // 三方登录的表名信息
	Conf      map[uint8]OpenConfig // 三方登录的具体配置详情
}

type OpenConfig

type OpenConfig struct {
	AppId     string // 配置项的key(必填,不能为空,此值为空则会忽略掉此项配置)
	AppSecret string // 配置项的SECRET(部分平台中也叫AppKey)
}

type OpenLogin

type OpenLogin struct {
	Id        uint64 `gorm:"column:id;primaryKey;type:BIGINT UNSIGNED;not null;autoIncrement" json:"id" form:"id"`              // 条目ID
	UserId    uint   `gorm:"column:user_id;not null;comment:绑定用户ID;index:user_id" json:"user_id" form:"user_id"`                // 绑定用户ID
	Nickname  string `gorm:"column:nickname;type:varchar(200);comment:三方昵称" json:"nickname" form:"nickname"`                    // 三方昵称
	Sex       string `gorm:"column:sex;type:varchar(50);comment:三方性别" json:"sex" form:"sex"`                                    // 三方性别
	Avatar    string `gorm:"column:avatar;type:varchar(200);comment:三方头像" json:"avatar" form:"avatar"`                          // 三方头像
	OpenID    string `gorm:"column:openid;type:VARCHAR(100);comment:三方返回的OPENID;index:openid" json:"openid" form:"openid"`      // OPENID
	UnionId   string `gorm:"column:unionid;type:VARCHAR(100);comment:三方返回的UNIONID;index:unionid" json:"unionid" form:"unionid"` // unionid
	Types     uint8  `gorm:"column:types;type:TINYINT UNSIGNED;comment:所属三方类型;index:types" json:"types" form:"types"`           // 所属三方类型
	CreatedAt string `gorm:"column:created_at;type:DATETIME;comment:创建时间" json:"created_at" form:"created_at"`                  //错误发生时间
}

三方登录的结构体类型

func GetBind added in v0.1.30

func GetBind(uid uint) ([]OpenLogin, error)

获取我已绑定的账号信息

uid	用户ID

func Openid2info

func Openid2info(openid string, typ uint8) (*OpenLogin, error)

openid换取个人信息【依次从缓存、数据库、三方进行读取,user_id为0表示未绑定】

openid	三方返回的唯一标识
typ		三方类型

func (*OpenLogin) TableName

func (a *OpenLogin) TableName() string

三方登录的表名

Jump to

Keyboard shortcuts

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