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.

36 lines
1.0 KiB

  1. package v1
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/global/response"
  5. resp "gin-vue-admin/model/response"
  6. "gin-vue-admin/utils"
  7. "github.com/dchest/captcha"
  8. "github.com/gin-gonic/gin"
  9. )
  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.OkDetailed(resp.SysCaptchaResponse{
  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. }