sys_captcha.go 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package api
  2. import (
  3. "gin-vue-admin/controller/servers"
  4. "github.com/dchest/captcha"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // 获取图片验证码id
  8. // @Tags base
  9. // @Summary 生成验证码
  10. // @Security ApiKeyAuth
  11. // @accept application/json
  12. // @Produce application/json
  13. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  14. // @Router /base/captcha [post]
  15. func Captcha(c *gin.Context) {
  16. captchaId := captcha.NewLen(6)
  17. servers.ReportFormat(c,true,"验证码获取成功",gin.H{
  18. "captchaId":captchaId,
  19. "picPath":"/base/captcha/"+captchaId+".png",
  20. })
  21. }
  22. // @Tags base
  23. // @Summary 生成验证码图片路径
  24. // @Security ApiKeyAuth
  25. // @accept application/json
  26. // @Produce application/json
  27. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  28. // @Router /base/captcha/:captchaId [get]
  29. func CaptchaImg(c *gin.Context) {
  30. servers.GinCapthcaServeHTTP(c.Writer, c.Request)
  31. }