49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package captcha
|
|
|
|
import (
|
|
v1 "management/internal/erpserver/service/v1"
|
|
"management/internal/pkg/config"
|
|
"management/internal/pkg/gin/gu"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type app struct {
|
|
config *config.Config
|
|
captchaService v1.CaptchaService
|
|
}
|
|
|
|
func newApp(config *config.Config, captchaService v1.CaptchaService) *app {
|
|
return &app{
|
|
config: config,
|
|
captchaService: captchaService,
|
|
}
|
|
}
|
|
|
|
type Response struct {
|
|
CaptchaID string `json:"captcha_id"`
|
|
PicPath string `json:"pic_path"`
|
|
CaptchaLength int `json:"captcha_length"`
|
|
OpenCaptcha int `json:"open_captcha"`
|
|
}
|
|
|
|
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 {
|
|
gu.Failed(ctx, "获取验证码失败")
|
|
return
|
|
}
|
|
|
|
rsp := Response{
|
|
CaptchaID: id,
|
|
PicPath: b64s,
|
|
CaptchaLength: a.config.Captcha.KeyLong,
|
|
OpenCaptcha: a.config.Captcha.OpenCaptcha,
|
|
}
|
|
gu.Ok(ctx, rsp)
|
|
}
|