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.

35 lines
1.0 KiB

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