v1
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
v1 "management/internal/erpserver/service/v1"
|
||||
"management/internal/pkg/config"
|
||||
"management/internal/pkg/gin/gu"
|
||||
"management/internal/pkg/render"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type app struct {
|
||||
@@ -29,14 +30,14 @@ type Response struct {
|
||||
OpenCaptcha int `json:"open_captcha"`
|
||||
}
|
||||
|
||||
func (a *app) captcha(w http.ResponseWriter, _ *http.Request) {
|
||||
func (a *app) captcha(ctx *gin.Context) {
|
||||
id, b64s, _, err := a.captchaService.Generate(
|
||||
a.config.Captcha.ImgHeight,
|
||||
a.config.Captcha.ImgWidth,
|
||||
a.config.Captcha.KeyLong,
|
||||
0.7, 80)
|
||||
if err != nil {
|
||||
a.render.JSONErr(w, "获取验证码失败")
|
||||
gu.Failed(ctx, "获取验证码失败")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -46,5 +47,5 @@ func (a *app) captcha(w http.ResponseWriter, _ *http.Request) {
|
||||
CaptchaLength: a.config.Captcha.KeyLong,
|
||||
OpenCaptcha: a.config.Captcha.OpenCaptcha,
|
||||
}
|
||||
a.render.JSONObj(w, "ok", rsp)
|
||||
gu.Ok(ctx, rsp)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"management/internal/pkg/config"
|
||||
"management/internal/pkg/render"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -14,7 +14,7 @@ type Config struct {
|
||||
CaptchaService v1.CaptchaService
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
func Routes(r *gin.RouterGroup, cfg Config) {
|
||||
app := newApp(cfg.Conf, cfg.Render, cfg.CaptchaService)
|
||||
r.Get("/captcha", app.captcha)
|
||||
r.GET("/captcha", app.captcha)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user