verify_code_controller.go 726 B

12345678910111213141516171819202122232425262728
  1. package auth
  2. import (
  3. "github.com/gin-gonic/gin"
  4. v1 "github.com/runningwater/gohub/app/http/controllers/api/v1"
  5. "github.com/runningwater/gohub/pkg/captcha"
  6. "github.com/runningwater/gohub/pkg/logger"
  7. "github.com/runningwater/gohub/pkg/response"
  8. )
  9. type VerifyCodeController struct {
  10. v1.BaseApiController
  11. }
  12. // ShowCaptcha 显示图片验证码
  13. func (vc *VerifyCodeController) ShowCaptcha(c *gin.Context) {
  14. // 生成验证码
  15. id, b64s, answer, err := captcha.NewCaptcha().GenerateCaptcha()
  16. logger.LogIf(err)
  17. logger.DebugString("captchaController", "captcha id: ", id)
  18. logger.DebugString("captchaController", "captcha answer: ", answer)
  19. response.JSON(c, gin.H{
  20. "captcha_id": id,
  21. "captcha_image": b64s,
  22. })
  23. }