加载 go get github.com/mojocn/base64Captcha import github.com/mojocn/base64Captcha var store = base64Captcha.DefaultMemStore func GetCaptcha(context *gin.Context){ driver := base64Captcha.NewDriverDigit(80, 240, 5, 0.7, 80) captcha := base64Captcha.NewCaptcha(driver, store) id, content, err := captcha.Generate() context.JSON(http.StatusOK,gin.H{ "id":id, "content":content, }) } 验证 func CheckCaptche(context *gin.Context){ id:=DefaultQuery("id","") captcheVal:=context.DefaultQuery("content","") res :=store.Verify(id,captcheVal,true) context.JSON(http.StatusOK,gin.H{ "data":res }) }