auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package auth 小程序登录验证的相关操作

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSessionKey = errors.New("无效的 sessionkey")
	ErrInvalidInitVector = errors.New("无效的 Initization vector")
)

几个错误信息

View Source
var ErrWeappUnauthorization = errors.New("微信未登录")

ErrWeappUnauthorization 表示微信未登录,或是登录已经过期

Functions

This section is empty.

Types

type Response

type Response struct {
	common.Result
	Openid     string `json:"openid"`
	SessionKey string `json:"session_key"`
	UnionID    string `json:"unionid,omitempty"` // 某些情况下存在
	// contains filtered or unexported fields
}

Response 返回的数据

func Authorization

func Authorization(conf *common.Config, jscode string) (*Response, error)

Authorization 执行登录验证,并获取相应的数据

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server 小程序状态管理服务

func NewServer

func NewServer(conf *common.Config, cap int, gctick, expired time.Duration) *Server

NewServer 声明一个新的 Server

cap 表示初始容量。 gctick 表示 GC 的启动频率,根据业务量自定义一个合理的值。

func (*Server) Decode

func (srv *Server) Decode(openid, data, iv string) ([]byte, *Watermark, error)

Decode 解码

func (*Server) New

func (srv *Server) New(jscode string) (*Response, error)

New 申请一个新的登录 token

type Watermark

type Watermark struct {
	Appid     string `json:"appid"`
	Timestamp int64  `json:"timestamp"`
}

Watermark 水印部分的内容

func Decode

func Decode(appid, sessionkey, data, iv string) ([]byte, *Watermark, error)

Decode 解析加密数据

返回的 Watermark 可用以验证数据是否正确

Jump to

Keyboard shortcuts

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