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

  1. package api
  2. import (
  3. "gin-vue-admin/config"
  4. "gin-vue-admin/controller/servers"
  5. "github.com/dchest/captcha"
  6. "github.com/gin-gonic/gin"
  7. )
  8. // 获取图片验证码id
  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(config.GinVueAdminconfig.Captcha.KeyLong)
  18. servers.ReportFormat(c, true, "验证码获取成功", gin.H{
  19. "captchaId": captchaId,
  20. "picPath": "/base/captcha/" + captchaId + ".png",
  21. })
  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. servers.GinCapthcaServeHTTP(c.Writer, c.Request)
  32. }