captcha.go 887 B

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