captcha

package
v0.0.0-...-d8850a5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRedisExpiration 默认过期时间
	DefaultRedisExpiration = 300
	// DefaultRedisPrefixKey 默认前缀
	DefaultRedisPrefixKey = "captcha"
)

Variables

This section is empty.

Functions

func Generate

func Generate(ctx context.Context, captchaInfo map[string]interface{}) (id, b64s string, err error)

Generate 生成验证码 格式:captchaHelper.Generate(ctx, map[string]string{"type": "digit", "store": "redis", "storeDbName": "default", "width":240, "height":80, "length":6}) 验证码类型type:audio-语音、string-字符串、math-数学、chinese-中文、digit-数字 存储store:redis,默认是 base64Captcha.DefaultMemStore 存储storeDbName:连接的存储库,如redis连接redis.yaml文件中的default配置

id, b64s, cErr := captchaHelper.Generate(c.GCtx, map[string]interface{}{
	"type":        "digit",                // audio-语音、string-字符串、math-数学、chinese-中文、digit-数字,不存在或者空着默认digit
	"store":       "redis",                // redis存储,不存在或者空着默认使用base64Captcha.DefaultMemStore
	"storeDbName": "default",              // redis连接实例
	"width":       constant.CaptchaWidth,  // 宽度,不存在或者空着默认240
	"height":      constant.CaptchaHeight, // 高度,不存在或者空着默认80
	"length":      constant.CaptchaLength, // 长度,不存在或者空着默认6
})

func GetDriver

func GetDriver(captchaInfo map[string]interface{}) base64Captcha.Driver

GetDriver 获取driver

func GetStore

func GetStore(ctx context.Context, captchaInfo map[string]interface{}) base64Captcha.Store

GetStore 获取存储store

func NewRedisStore

func NewRedisStore(ctx context.Context, dbName string) (base64Captcha.Store, error)

NewRedisStore redis客户端实例

func Verify

func Verify(ctx context.Context, id, value string, captchaInfo map[string]interface{}) bool

Verify 验证验证码是否正确 格式:captchaHelper.Verify(ctx, map[string]string{"store": "redis", "storeDbName": "default"}) 存储store:redis,默认是 base64Captcha.DefaultMemStore 存储storeDbName:连接的存储库,如redis连接redis.yaml文件中的default配置

res := captchaHelper.Verify(c.GCtx, captchaId, Captcha, map[string]interface{}{
	"store":       "redis",   // redis存储,不存在或者空着默认使用base64Captcha.DefaultMemStore
	"storeDbName": "default", // redis连接实例
})

Types

This section is empty.

Jump to

Keyboard shortcuts

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