sys_captcha.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // @Param data body modelInterface.PageInfo true "生成验证码"
  14. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  15. // @Router /base/captcha [post]
  16. func Captcha(c *gin.Context) {
  17. id := captcha.NewLen(6)
  18. captcha.Server(captcha.StdWidth,captcha.StdHeight)
  19. servers.ReportFormat(c,true,"test",gin.H{
  20. "id":id,
  21. "picPath":"/base/captcha/"+id+".png",
  22. })
  23. }
  24. // @Tags base
  25. // @Summary 生成验证码图片路径
  26. // @Security ApiKeyAuth
  27. // @accept application/json
  28. // @Produce application/json
  29. // @Param data body modelInterface.PageInfo true "生成验证码图片路径"
  30. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  31. // @Router /base/captcha/:id [get]
  32. func CaptchaImg(c *gin.Context) {
  33. servers.GinCapthcaServeHTTP(c.Writer, c.Request)
  34. }