소스 검색

图片验证码接口

runningwater 1 년 전
부모
커밋
63abe7812b
3개의 변경된 파일32개의 추가작업 그리고 1개의 파일을 삭제
  1. 26 0
      app/http/controllers/api/v1/auth/verify_code_controller.go
  2. 4 1
      gohub.http
  3. 2 0
      routes/api.go

+ 26 - 0
app/http/controllers/api/v1/auth/verify_code_controller.go

@@ -0,0 +1,26 @@
+package auth
+
+import (
+	"github.com/gin-gonic/gin"
+
+	v1 "github.com/runningwater/gohub/app/http/controllers/api/v1"
+	"github.com/runningwater/gohub/pkg/captcha"
+	"github.com/runningwater/gohub/pkg/logger"
+)
+
+type VerifyCodeController struct {
+	v1.BaseApiController
+}
+
+// ShowCaptcha 显示图片验证码
+func (vc *VerifyCodeController) ShowCaptcha(c *gin.Context) {
+	// 生成验证码
+	id, b64s, answer, err := captcha.NewCaptcha().GenerateCaptcha()
+	logger.LogIf(err)
+	logger.DebugString("captchaController", "captcha id: ", id)
+	logger.DebugString("captchaController", "captcha answer: ", answer)
+	c.JSON(200, gin.H{
+		"captcha_id":    id,
+		"captcha_image": b64s,
+	})
+}

+ 4 - 1
gohub.http

@@ -12,4 +12,7 @@ Content-Type: application/json
 
 {
   "email": "ynwdlxm@163.com"
-}
+}
+### POST /verify_code/captcha 图片验证码
+POST {{base_url}}/v1/auth/verify_code/captcha HTTP/1.1
+Content-Type: application/json

+ 2 - 0
routes/api.go

@@ -18,6 +18,8 @@ func RegisterAPIRoutes(router *gin.Engine) {
 			authGroup.POST("/signup/phone/exist", suc.IsPhoneExist)
 			// 注册邮箱是否已存在
 			authGroup.POST("/signup/email/exist", suc.IsEmailExist)
+			// 显示图片验证码
+			authGroup.POST("/verify_code/captcha", new(auth.VerifyCodeController).ShowCaptcha)
 		}
 	}
 }