captcha.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package captcha
  2. import (
  3. "image/color"
  4. "github.com/google/uuid"
  5. "github.com/mojocn/base64Captcha"
  6. )
  7. var store = base64Captcha.DefaultMemStore
  8. //configJsonBody json request body.
  9. type configJsonBody struct {
  10. Id string
  11. CaptchaType string
  12. VerifyValue string
  13. DriverAudio *base64Captcha.DriverAudio
  14. DriverString *base64Captcha.DriverString
  15. DriverChinese *base64Captcha.DriverChinese
  16. DriverMath *base64Captcha.DriverMath
  17. DriverDigit *base64Captcha.DriverDigit
  18. }
  19. func DriverStringFunc() (id, b64s string, err error) {
  20. e := configJsonBody{}
  21. e.Id = uuid.New().String()
  22. e.DriverString = base64Captcha.NewDriverString(46, 140, 2, 2, 4, "234567890abcdefghjkmnpqrstuvwxyz", &color.RGBA{240, 240, 246, 246}, []string{"wqy-microhei.ttc"})
  23. driver := e.DriverString.ConvertFonts()
  24. cap := base64Captcha.NewCaptcha(driver, store)
  25. return cap.Generate()
  26. }
  27. func DriverDigitFunc() (id, b64s string, err error) {
  28. e := configJsonBody{}
  29. e.Id = uuid.New().String()
  30. e.DriverDigit = base64Captcha.DefaultDriverDigit
  31. driver := e.DriverDigit
  32. cap := base64Captcha.NewCaptcha(driver, store)
  33. return cap.Generate()
  34. }