sys_captcha.go 1020 B

123456789101112131415161718192021222324252627282930313233343536
  1. package v1
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/utils"
  6. "github.com/dchest/captcha"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // 获取图片验证码id
  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. captchaId := captcha.NewLen(global.GVA_CONFIG.Captcha.KeyLong)
  19. response.Result(response.SUCCESS, gin.H{
  20. "captchaId": captchaId,
  21. "picPath": "/base/captcha/" + captchaId + ".png",
  22. }, "验证码获取成功", c)
  23. }
  24. // @Tags base
  25. // @Summary 生成验证码图片路径
  26. // @Security ApiKeyAuth
  27. // @accept application/json
  28. // @Produce application/json
  29. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  30. // @Router /base/captcha/:captchaId [get]
  31. func CaptchaImg(c *gin.Context) {
  32. utils.GinCaptchaServeHTTP(c.Writer, c.Request)
  33. }