ferry/tools/captcha/captcha.go

30 lines
758 B
Go
Raw Normal View History

2020-07-13 20:33:20 +08:00
package captcha
import (
"github.com/google/uuid"
"github.com/mojocn/base64Captcha"
)
var store = base64Captcha.DefaultMemStore
2023-11-28 22:18:28 +08:00
// configJsonBody json request body.
2020-07-13 20:33:20 +08:00
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 DriverDigitFunc() (id, b64s string, err error) {
e := configJsonBody{}
e.Id = uuid.New().String()
e.DriverDigit = base64Captcha.NewDriverDigit(80, 240, 4, 0.7, 80)
2020-07-13 20:33:20 +08:00
driver := e.DriverDigit
2023-11-28 22:18:28 +08:00
captcha := base64Captcha.NewCaptcha(driver, store)
return captcha.Generate()
}