You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.0 KiB

  1. package v1
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model/response"
  5. "github.com/gin-gonic/gin"
  6. "github.com/mojocn/base64Captcha"
  7. "go.uber.org/zap"
  8. )
  9. var store = base64Captcha.DefaultMemStore
  10. // @Tags Base
  11. // @Summary 生成验证码
  12. // @Security ApiKeyAuth
  13. // @accept application/json
  14. // @Produce application/json
  15. // @Success 200 {string} string "{"success":true,"data":{},"msg":"验证码获取成功"}"
  16. // @Router /base/captcha [post]
  17. func Captcha(c *gin.Context) {
  18. //字符,公式,验证码配置
  19. // 生成默认数字的driver
  20. driver := base64Captcha.NewDriverDigit(global.GVA_CONFIG.Captcha.ImgHeight, global.GVA_CONFIG.Captcha.ImgWidth, global.GVA_CONFIG.Captcha.KeyLong, 0.7, 80)
  21. cp := base64Captcha.NewCaptcha(driver, store)
  22. if id, b64s, err := cp.Generate(); err != nil {
  23. global.GVA_LOG.Error("验证码获取失败!", zap.Any("err", err))
  24. response.FailWithMessage("验证码获取失败", c)
  25. } else {
  26. response.OkWithDetailed(response.SysCaptchaResponse{
  27. CaptchaId: id,
  28. PicPath: b64s,
  29. }, "验证码获取成功", c)
  30. }
  31. }