captcha.go 942 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "gogs.baozhida.cn/zoie/OAuth-core/api"
  5. "gogs.baozhida.cn/zoie/OAuth-core/pkg/captcha"
  6. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  7. )
  8. type SystemController struct {
  9. api.Api
  10. }
  11. // GenerateCaptchaHandler 获取验证码
  12. // @Summary 获取验证码
  13. // @Description 获取验证码
  14. // @Tags 登录
  15. // @Success 200 {object} response.Response{data=string,id=string,msg=string} "{"code": 200, "data": [...]}"
  16. // @Router /api/captcha [get]
  17. func (e SystemController) GenerateCaptchaHandler(c *gin.Context) {
  18. err := e.MakeContext(c).Errors
  19. if err != nil {
  20. e.Error(500, err, "服务初始化失败!")
  21. return
  22. }
  23. id, b64s, err := captcha.DriverDigitFunc()
  24. if err != nil {
  25. e.Logger.Errorf("DriverDigitFunc error, %s", err.Error())
  26. e.Error(500, err, "验证码获取失败")
  27. return
  28. }
  29. e.Custom(gin.H{
  30. "code": 200,
  31. "data": b64s,
  32. "id": id,
  33. "msg": "success",
  34. })
  35. }