From ffb05847e0285d012e836d50130e9d31afdf4864 Mon Sep 17 00:00:00 2001 From: lixxxww <941403820@qq.com> Date: Tue, 23 Jan 2024 11:17:50 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0captcha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixxxww <941403820@qq.com> --- kit/captcha/captcha.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 kit/captcha/captcha.go diff --git a/kit/captcha/captcha.go b/kit/captcha/captcha.go new file mode 100644 index 0000000..f8612ee --- /dev/null +++ b/kit/captcha/captcha.go @@ -0,0 +1,28 @@ +package captcha + +import ( + "pandax/kit/biz" + + "github.com/mojocn/base64Captcha" +) + +var store = base64Captcha.DefaultMemStore +var driver base64Captcha.Driver = base64Captcha.NewDriverDigit(80, 240, 4, 0.7, 80) + +// 生成验证码 +func Generate() (string, string, string) { + c := base64Captcha.NewCaptcha(driver, store) + // 获取 + id, b64s, answer, err := c.Generate() + biz.ErrIsNilAppendErr(err, "获取验证码错误: %s") + return id, b64s, answer +} + +// 验证验证码 +func Verify(id string, val string) bool { + if id == "" || val == "" { + return false + } + // 同时清理掉这个图片 + return store.Verify(id, val, true) +}