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
993 B

  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. // @Tags base
  10. // @Summary 生成验证码
  11. // @Security ApiKeyAuth
  12. // @accept application/json
  13. // @Produce application/json
  14. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  15. // @Router /base/captcha [post]
  16. func Captcha(c *gin.Context) {
  17. captchaId := captcha.NewLen(global.GVA_CONFIG.Captcha.KeyLong)
  18. response.Result(response.SUCCESS, gin.H{
  19. "captchaId": captchaId,
  20. "picPath": "/base/captcha/" + captchaId + ".png",
  21. }, "验证码获取成功", c)
  22. }
  23. // @Tags base
  24. // @Summary 生成验证码图片路径
  25. // @Security ApiKeyAuth
  26. // @accept application/json
  27. // @Produce application/json
  28. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  29. // @Router /base/captcha/:captchaId [get]
  30. func CaptchaImg(c *gin.Context) {
  31. utils.GinCaptchaServeHTTP(c.Writer, c.Request)
  32. }