Documentation
¶
Index ¶
- func InitGlobalManager(config *Config)
- type ClickCaptcha
- type ClickCaptchaData
- type Config
- type ImageCaptcha
- type ImageCaptchaData
- type Manager
- func (m *Manager) Generate(captchaType Type) (*Result, error)
- func (m *Manager) GenerateClick() (*Result, error)
- func (m *Manager) GenerateImage() (*Result, error)
- func (m *Manager) GeneratePuzzle() (*Result, error)
- func (m *Manager) GenerateSlider() (*Result, error)
- func (m *Manager) Verify(captchaType Type, id string, data interface{}) (bool, error)
- func (m *Manager) VerifyClick(id string, positions []Point) (bool, error)
- func (m *Manager) VerifyImage(id, code string) (bool, error)
- func (m *Manager) VerifyPuzzle(id string, x, y int) (bool, error)
- func (m *Manager) VerifySlider(id string, x, y int) (bool, error)
- type MemoryStore
- func (s *MemoryStore) Delete(id string) error
- func (s *MemoryStore) Get(id string) (interface{}, error)
- func (s *MemoryStore) Set(id string, data interface{}, expires time.Time) error
- func (s *MemoryStore) VerifyWithFunc(id string, input interface{}, compareFunc func(stored, input interface{}) bool) (bool, error)
- type Point
- type PuzzleCaptcha
- type PuzzleCaptchaData
- type Result
- type SliderCaptcha
- type SliderCaptchaData
- type Store
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClickCaptcha ¶
type ClickCaptcha struct {
// contains filtered or unexported fields
}
ClickCaptcha 点击验证码
func NewClickCaptcha ¶
func NewClickCaptcha(width, height, count, tolerance int, expiration time.Duration, store Store) *ClickCaptcha
NewClickCaptcha 创建点击验证码管理器
func (*ClickCaptcha) Generate ¶
func (cc *ClickCaptcha) Generate() (*Result, error)
Generate 生成点击验证码
type ClickCaptchaData ¶
type ClickCaptchaData struct {
Image string `json:"image"` // 图片Base64
Positions []Point `json:"positions"` // 需要点击的位置列表
Count int `json:"count"` // 需要点击的数量
Tolerance int `json:"tolerance"` // 容差(像素)
}
ClickCaptchaData 点击验证码数据
type Config ¶
type Config struct {
// 图形验证码配置
ImageWidth int
ImageHeight int
ImageLength int
// 滑块验证码配置
SliderWidth int
SliderHeight int
SliderSize int
SliderTolerance int
// 点击验证码配置
ClickWidth int
ClickHeight int
ClickCount int
ClickTolerance int
// 拼图验证码配置
PuzzleWidth int
PuzzleHeight int
PuzzleSize int
PuzzleTolerance int
// 通用配置
Expiration time.Duration
Store Store
}
Config 验证码配置
type ImageCaptcha ¶
type ImageCaptcha struct {
// contains filtered or unexported fields
}
ImageCaptcha 图形验证码
func NewImageCaptcha ¶
func NewImageCaptcha(width, height, length int, expiration time.Duration, store Store) *ImageCaptcha
NewImageCaptcha 创建图形验证码管理器
func (*ImageCaptcha) Generate ¶
func (ic *ImageCaptcha) Generate() (*Result, error)
Generate 生成图形验证码
type ImageCaptchaData ¶
type ImageCaptchaData struct {
Image string `json:"image"` // Base64编码的图片
Code string `json:"code"` // 验证码内容(仅用于测试,生产环境不应返回)
}
ImageCaptchaData 图形验证码数据
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 统一验证码管理器
var GlobalManager *Manager
GlobalManager 全局验证码管理器
func (*Manager) GenerateClick ¶
GenerateClick 生成点击验证码
func (*Manager) GenerateImage ¶
GenerateImage 生成图形验证码
func (*Manager) GeneratePuzzle ¶
GeneratePuzzle 生成拼图验证码
func (*Manager) GenerateSlider ¶
GenerateSlider 生成滑块验证码
func (*Manager) VerifyClick ¶
VerifyClick 验证点击验证码
func (*Manager) VerifyImage ¶
VerifyImage 验证图形验证码
func (*Manager) VerifyPuzzle ¶
VerifyPuzzle 验证拼图验证码
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore 内存存储实现
func (*MemoryStore) Delete ¶
func (s *MemoryStore) Delete(id string) error
func (*MemoryStore) Get ¶
func (s *MemoryStore) Get(id string) (interface{}, error)
func (*MemoryStore) Set ¶
func (s *MemoryStore) Set(id string, data interface{}, expires time.Time) error
func (*MemoryStore) VerifyWithFunc ¶
func (s *MemoryStore) VerifyWithFunc(id string, input interface{}, compareFunc func(stored, input interface{}) bool) (bool, error)
type PuzzleCaptcha ¶
type PuzzleCaptcha struct {
// contains filtered or unexported fields
}
PuzzleCaptcha 拼图验证码
func NewPuzzleCaptcha ¶
func NewPuzzleCaptcha(width, height, puzzleSize, tolerance int, expiration time.Duration, store Store) *PuzzleCaptcha
NewPuzzleCaptcha 创建拼图验证码管理器
func (*PuzzleCaptcha) Generate ¶
func (pc *PuzzleCaptcha) Generate() (*Result, error)
Generate 生成拼图验证码
type PuzzleCaptchaData ¶
type PuzzleCaptchaData struct {
BackgroundImage string `json:"background_image"` // 背景图Base64
PuzzleImage string `json:"puzzle_image"` // 拼图块Base64
X int `json:"x"` // 拼图应该移动到的X坐标
Y int `json:"y"` // 拼图应该移动到的Y坐标
Tolerance int `json:"tolerance"` // 容差(像素)
}
PuzzleCaptchaData 拼图验证码数据
type Result ¶
type Result struct {
ID string `json:"id"` // 验证码ID
Type Type `json:"type"` // 验证码类型
Data map[string]interface{} `json:"data"` // 验证码数据(根据类型不同而不同)
Expires time.Time `json:"expires"` // 过期时间
}
Result 验证码生成结果
type SliderCaptcha ¶
type SliderCaptcha struct {
// contains filtered or unexported fields
}
SliderCaptcha 滑块验证码
func NewSliderCaptcha ¶
func NewSliderCaptcha(width, height, sliderSize, tolerance int, expiration time.Duration, store Store) *SliderCaptcha
NewSliderCaptcha 创建滑块验证码管理器
func (*SliderCaptcha) Generate ¶
func (sc *SliderCaptcha) Generate() (*Result, error)
Generate 生成滑块验证码
type SliderCaptchaData ¶
type SliderCaptchaData struct {
BackgroundImage string `json:"background_image"` // 背景图Base64
SliderImage string `json:"slider_image"` // 滑块图Base64
X int `json:"x"` // 滑块应该移动到的X坐标
Y int `json:"y"` // 滑块应该移动到的Y坐标
Width int `json:"width"` // 滑块宽度
Height int `json:"height"` // 滑块高度
Tolerance int `json:"tolerance"` // 容差(像素)
}
SliderCaptchaData 滑块验证码数据
Click to show internal directories.
Click to hide internal directories.