captcha

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Captcha

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

func New

func New(size, exp int, dirverType ...CaptchaType) *Captcha

创建验证码实例

  • {size} 验证码长度
  • {exp} 验证码有效期,单位/秒
  • {dirverType} 验证码类型,可选,默认(数值+字母组合)

func (*Captcha) Check

func (c *Captcha) Check(idKey, code string) bool

Check 校验验证码

  • {idKey} 验证码ID
  • {code} 用户提交的验证码

func (*Captcha) Make

func (c *Captcha) Make(withFormatPrefix bool) (idKey, b64Str string, err error)

Make 生成验证码

  • {withFormatPrefix} 是否携带图片格式前缀

return:

  • {idKey} 验证码ID 校验时要用
  • {b64Str} 验证码图片 base64 字串

type CaptchaType

type CaptchaType func(c *Captcha)

验证码类型项

func WithTypeAudio

func WithTypeAudio(lang ...string) CaptchaType

音频验证码

  • {lang} 音频语言,可用值:"en"英语,"ja"日语,"ru"俄语,"zh"中文,默认"en"

func WithTypeChinese

func WithTypeChinese(w, h int, opt ...*ImageOption) CaptchaType

中文验证码

  • {w},{h} 宽高
  • {opt} 可选项参数

func WithTypeDigit

func WithTypeDigit(w, h int) CaptchaType

纯数字验证码

  • {w},{h} 宽高,最低100x36

func WithTypeMath

func WithTypeMath(w, h int, opt ...*ImageOption) CaptchaType

数学计算验证码

  • {w},{h} 宽高
  • {opt} 可选项参数

func WithTypeString

func WithTypeString(w, h int, opt ...*ImageOption) CaptchaType

数值字母验证码

  • {w},{h} 宽高
  • {opt} 可选项参数

type ImageOption

type ImageOption struct {
	Noise     int         //噪点数,默认32
	LineLevel int         //干扰线强度,范围1-3,-1表示不设置,默认2
	BgColor   *color.RGBA //背景色,默认r10,g20,b50,a10
	Source    string      //取值源
	Font      string      //字体
}

图片类验证码选项参数

Jump to

Keyboard shortcuts

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