Documentation
¶
Index ¶
- type Challenge
- type ChineseConfig
- type ClickCaptchaData
- type ClickConfig
- type Config
- type DigitConfig
- type Driver
- type DriverType
- type MathConfig
- type Option
- func WithChineseChars(chars []string) Option
- func WithChineseConfig(config *ChineseConfig) Option
- func WithChineseCount(count int) Option
- func WithChineseDotCount(count int) Option
- func WithChineseHeight(height int) Option
- func WithChineseSource(source string) Option
- func WithChineseWidth(width int) Option
- func WithClickCaptchaCount(count int) Option
- func WithClickChars(chars string) Option
- func WithClickConfig(config *ClickConfig) Option
- func WithClickLanguage(language string) Option
- func WithClickMasterSize(width, height int) Option
- func WithClickShadow(display bool, color string, offsetX, offsetY int) Option
- func WithClickThumbSize(width, height int) Option
- func WithClickVerifyCount(count int) Option
- func WithDigitConfig(config *DigitConfig) Option
- func WithDigitCount(count int) Option
- func WithDigitDotCount(count int) Option
- func WithDigitHeight(height int) Option
- func WithDigitMaxSkew(skew float64) Option
- func WithDigitWidth(width int) Option
- func WithDriverType(driverType DriverType) Option
- func WithExpire(expire time.Duration) Option
- func WithKeyPrefix(prefix string) Option
- func WithMathConfig(config *MathConfig) Option
- func WithMathDotCount(count int) Option
- func WithMathHeight(height int) Option
- func WithMathWidth(width int) Option
- func WithRotateConfig(config *RotateConfig) Option
- func WithRotateMasterSize(width, height int) Option
- func WithRotateThumbSize(width, height int) Option
- func WithSlideConfig(config *SlideConfig) Option
- func WithSlideJigsawRadius(radius int) Option
- func WithSlideMasterSize(width, height int) Option
- func WithSlideShadow(offsetX, offsetY, blur int) Option
- func WithSlideTileRadius(radius int) Option
- func WithSlideTileSize(width, height int) Option
- func WithStringConfig(config *StringConfig) Option
- func WithStringCount(count int) Option
- func WithStringDotCount(count int) Option
- func WithStringHeight(height int) Option
- func WithStringSource(source string) Option
- func WithStringWidth(width int) Option
- type RotateCaptchaData
- type RotateConfig
- type SlideCaptchaData
- type SlideConfig
- type StringConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Challenge ¶
type Challenge struct {
ID string // 验证码 ID
Payload string // 图片 base64 或行为验证码 JSON(base64)
Answer string // 服务端答案,不对外返回
}
Challenge 表示驱动内部生成结果,Answer 只允许写入服务端缓存。
type ChineseConfig ¶
type ChineseConfig struct {
Height int `json:"height"` // 图片高度
Width int `json:"width"` // 图片宽度
CaptchaCount int `json:"captcha_count"` // 验证码字符数量
DotCount int `json:"dot_count"` // 干扰点数量
Source string `json:"source"` // 中文字符源,支持逗号分隔
CaptchaLen int `json:"captcha_len"` // 验证码长度(兼容字段)
}
ChineseConfig 中文验证码配置
type ClickCaptchaData ¶
type ClickCaptchaData struct {
Type string `json:"type"` // 验证码类型
Image string `json:"image"` // 主图 base64
Thumb string `json:"thumb"` // 缩略图 base64
Width int `json:"width"` // 主图展示宽度
Height int `json:"height"` // 主图展示高度
ThumbWidth int `json:"thumbWidth"` // 缩略图展示宽度
ThumbHeight int `json:"thumbHeight"` // 缩略图展示高度
}
ClickCaptchaData 点击验证码数据结构。
type ClickConfig ¶
type ClickConfig struct {
MasterWidth int `json:"master_width"` // 主图宽度
MasterHeight int `json:"master_height"` // 主图高度
ThumbWidth int `json:"thumb_width"` // 缩略图宽度
ThumbHeight int `json:"thumb_height"` // 缩略图高度
CaptchaCount int `json:"captcha_count"` // 主图字符数量
VerifyCount int `json:"verify_count"` // 验证字符数量
DisplayShadow bool `json:"display_shadow"` // 是否显示阴影
ShadowColor string `json:"shadow_color"` // 阴影颜色
ShadowOffsetX int `json:"shadow_offset_x"` // 阴影X偏移
ShadowOffsetY int `json:"shadow_offset_y"` // 阴影Y偏移
Chars string `json:"chars"` // 字符集
Language string `json:"language"` // 语言类型 zh, en
}
ClickConfig 点击文字验证码配置
type Config ¶
type Config struct {
DriverType DriverType `json:"driver_type"` // 驱动类型
Expire time.Duration `json:"expire"` // 过期时间
KeyPrefix string `json:"key_prefix"` // 缓存 key 前缀
DigitConfig *DigitConfig `json:"digit_config"` // 数字配置
StringConfig *StringConfig `json:"string_config"` // 字符串配置
MathConfig *MathConfig `json:"math_config"` // 算术配置
ChineseConfig *ChineseConfig `json:"chinese_config"` // 中文配置
SlideConfig *SlideConfig `json:"slide_config"` // 滑动拼图配置
ClickConfig *ClickConfig `json:"click_config"` // 点击文字配置
RotateConfig *RotateConfig `json:"rotate_config"` // 旋转配置
}
Config 验证码总配置
type DigitConfig ¶
type DigitConfig struct {
Height int `json:"height"` // 图片高度
Width int `json:"width"` // 图片宽度
CaptchaCount int `json:"captcha_count"` // 验证码字符数量
MaxSkew float64 `json:"max_skew"` // 最大倾斜度
DotCount int `json:"dot_count"` // 干扰点数量
BgColorR uint8 `json:"bg_color_r"` // 背景色R
BgColorG uint8 `json:"bg_color_g"` // 背景色G
BgColorB uint8 `json:"bg_color_b"` // 背景色B
FontColorR uint8 `json:"font_color_r"` // 字体色R
FontColorG uint8 `json:"font_color_g"` // 字体色G
FontColorB uint8 `json:"font_color_b"` // 字体色B
CaptchaLen int `json:"captcha_len"` // 验证码长度(兼容字段)
}
DigitConfig 数字验证码配置
type DriverType ¶
type DriverType string
DriverType 表示验证码驱动类型。
const ( // DriverDigit 表示数字验证码。 DriverDigit DriverType = "digit" // DriverString 表示字符串验证码。 DriverString DriverType = "string" // DriverMath 表示算术验证码。 DriverMath DriverType = "math" // DriverChinese 表示中文验证码。 DriverChinese DriverType = "chinese" // DriverSlide 表示滑动拼图验证码。 DriverSlide DriverType = "slide" // DriverClick 表示点击文字验证码。 DriverClick DriverType = "click" // DriverRotate 表示旋转验证码。 DriverRotate DriverType = "rotate" )
type MathConfig ¶
type MathConfig struct {
Height int `json:"height"` // 图片高度
Width int `json:"width"` // 图片宽度
CaptchaCount int `json:"captcha_count"` // 验证码字符数量
MaxSkew float64 `json:"max_skew"` // 最大倾斜度
DotCount int `json:"dot_count"` // 干扰点数量
BgColorR uint8 `json:"bg_color_r"` // 背景色R
BgColorG uint8 `json:"bg_color_g"` // 背景色G
BgColorB uint8 `json:"bg_color_b"` // 背景色B
FontColorR uint8 `json:"font_color_r"` // 字体色R
FontColorG uint8 `json:"font_color_g"` // 字体色G
FontColorB uint8 `json:"font_color_b"` // 字体色B
CaptchaLen int `json:"captcha_len"` // 验证码长度(兼容字段)
}
MathConfig 算术验证码配置
type Option ¶
type Option func(*Config)
Option 表示验证码配置选项函数。
func WithChineseConfig ¶
func WithChineseConfig(config *ChineseConfig) Option
WithChineseConfig 设置中文验证码配置
func WithChineseDotCount ¶
WithChineseDotCount 设置中文验证码干扰点数量
func WithClickCaptchaCount ¶
WithClickCaptchaCount 设置点击验证码主图字符数量
func WithClickMasterSize ¶
WithClickMasterSize 设置点击验证码主图尺寸
func WithClickShadow ¶
WithClickShadow 设置点击验证码阴影效果
func WithClickThumbSize ¶
WithClickThumbSize 设置点击验证码缩略图尺寸
func WithClickVerifyCount ¶
WithClickVerifyCount 设置点击验证码验证字符数量
func WithRotateConfig ¶
func WithRotateConfig(config *RotateConfig) Option
WithRotateConfig 设置旋转验证码配置
func WithRotateMasterSize ¶
WithRotateMasterSize 设置旋转验证码主图尺寸
func WithRotateThumbSize ¶
WithRotateThumbSize 设置旋转验证码缩略图尺寸
func WithSlideJigsawRadius ¶
WithSlideJigsawRadius 设置滑动拼图缺口圆角半径
func WithSlideMasterSize ¶
WithSlideMasterSize 设置滑动拼图主图尺寸
func WithSlideShadow ¶
WithSlideShadow 设置滑动拼图阴影效果
func WithSlideTileRadius ¶
WithSlideTileRadius 设置滑动拼图滑块圆角半径
func WithSlideTileSize ¶
WithSlideTileSize 设置滑动拼图滑块尺寸
func WithStringConfig ¶
func WithStringConfig(config *StringConfig) Option
WithStringConfig 设置字符串验证码配置
func WithStringDotCount ¶
WithStringDotCount 设置字符串验证码干扰点数量
type RotateCaptchaData ¶
type RotateCaptchaData struct {
Type string `json:"type"` // 验证码类型
Image string `json:"image"` // 主图 base64(需要旋转的图片)
Thumb string `json:"thumb"` // 缩略图 base64(提示目标方向)
Width int `json:"width"` // 主图展示宽度
Height int `json:"height"` // 主图展示高度
ThumbSize int `json:"thumbSize"` // 内圈展示尺寸
}
RotateCaptchaData 旋转验证码数据结构。
type RotateConfig ¶
type RotateConfig struct {
MasterWidth int `json:"master_width"` // 主图宽度
MasterHeight int `json:"master_height"` // 主图高度
ThumbWidth int `json:"thumb_width"` // 缩略图宽度
ThumbHeight int `json:"thumb_height"` // 缩略图高度
}
RotateConfig 旋转验证码配置
type SlideCaptchaData ¶
type SlideCaptchaData struct {
Type string `json:"type"` // 验证码类型
Image string `json:"image"` // 主图 base64
Thumb string `json:"thumb"` // 滑块图 base64
Width int `json:"width"` // 主图展示宽度
Height int `json:"height"` // 主图展示高度
ThumbX int `json:"thumbX"` // 滑块初始展示横坐标
ThumbY int `json:"thumbY"` // 滑块初始展示纵坐标
ThumbWidth int `json:"thumbWidth"` // 滑块展示宽度
ThumbHeight int `json:"thumbHeight"` // 滑块展示高度
}
SlideCaptchaData 滑动验证码数据结构。
type SlideConfig ¶
type SlideConfig struct {
MasterWidth int `json:"master_width"` // 主图宽度
MasterHeight int `json:"master_height"` // 主图高度
TileWidth int `json:"tile_width"` // 滑块宽度
TileHeight int `json:"tile_height"` // 滑块高度
TileRadius int `json:"tile_radius"` // 滑块圆角半径
JigsawRadius int `json:"jigsaw_radius"` // 拼图缺口圆角半径
ShadowOffsetX int `json:"shadow_offset_x"` // 阴影X偏移
ShadowOffsetY int `json:"shadow_offset_y"` // 阴影Y偏移
ShadowBlur int `json:"shadow_blur"` // 阴影模糊度
}
SlideConfig 滑动拼图验证码配置
type StringConfig ¶
type StringConfig struct {
Height int `json:"height"` // 图片高度
Width int `json:"width"` // 图片宽度
CaptchaCount int `json:"captcha_count"` // 验证码字符数量
MaxSkew float64 `json:"max_skew"` // 最大倾斜度
DotCount int `json:"dot_count"` // 干扰点数量
BgColorR uint8 `json:"bg_color_r"` // 背景色R
BgColorG uint8 `json:"bg_color_g"` // 背景色G
BgColorB uint8 `json:"bg_color_b"` // 背景色B
FontColorR uint8 `json:"font_color_r"` // 字体色R
FontColorG uint8 `json:"font_color_g"` // 字体色G
FontColorB uint8 `json:"font_color_b"` // 字体色B
Source string `json:"source"` // 字符源
CaptchaLen int `json:"captcha_len"` // 验证码长度(兼容字段)
}
StringConfig 字符串验证码配置