1 Star 0 Fork 0

linxing / youye-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
captcha.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
Mark 提交于 2023-12-23 11:58 . init
package captcha
import (
"image/color"
"github.com/google/uuid"
"github.com/mojocn/base64Captcha"
)
// SetStore 设置store
func SetStore(s base64Captcha.Store) {
base64Captcha.DefaultMemStore = s
}
// configJsonBody json request body.
type configJsonBody struct {
Id string
CaptchaType string
VerifyValue string
DriverAudio *base64Captcha.DriverAudio
DriverString *base64Captcha.DriverString
DriverChinese *base64Captcha.DriverChinese
DriverMath *base64Captcha.DriverMath
DriverDigit *base64Captcha.DriverDigit
}
func DriverStringFunc() (id, b64s string, err error) {
e := configJsonBody{}
e.Id = uuid.New().String()
e.DriverString = base64Captcha.NewDriverString(
46, 140, 2, 2, 4,
"234567890abcdefghjkmnpqrstuvwxyz", &color.RGBA{240, 240, 246, 246}, base64Captcha.DefaultEmbeddedFonts, []string{"wqy-microhei.ttc"})
driver := e.DriverString.ConvertFonts()
cap := base64Captcha.NewCaptcha(driver, base64Captcha.DefaultMemStore)
id, b64s, _, err = cap.Generate()
return
}
func DriverDigitFunc() (id, b64s string, err error) {
e := configJsonBody{}
e.Id = uuid.New().String()
e.DriverDigit = base64Captcha.NewDriverDigit(80, 240, 4, 0.7, 80)
driver := e.DriverDigit
cap := base64Captcha.NewCaptcha(driver, base64Captcha.DefaultMemStore)
id, b64s, _, err = cap.Generate()
return
}
// Verify 校验验证码
func Verify(id, code string, clear bool) bool {
return base64Captcha.DefaultMemStore.Verify(id, code, clear)
}
1
https://gitee.com/linxing_3/youye-core.git
git@gitee.com:linxing_3/youye-core.git
linxing_3
youye-core
youye-core
v0.0.1-202405061706

搜索帮助