35 lines
912 B
Go
35 lines
912 B
Go
package common
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"management/internal/config"
|
|
captchaservice "management/internal/service/captcha"
|
|
"management/internal/tpl"
|
|
)
|
|
|
|
type CaptchaResponse struct {
|
|
CaptchaID string `json:"captcha_id"`
|
|
PicPath string `json:"pic_path"`
|
|
CaptchaLength int `json:"captcha_length"`
|
|
OpenCaptcha int `json:"open_captcha"`
|
|
}
|
|
|
|
func Captcha(w http.ResponseWriter, r *http.Request) {
|
|
keyLong := config.File.Captcha.KeyLong
|
|
oc := config.File.Captcha.OpenCaptcha
|
|
id, b64s, _, err := captchaservice.Generate(config.File.Captcha.ImgHeight, config.File.Captcha.ImgWidth, keyLong, 0.7, 80)
|
|
if err != nil {
|
|
tpl.JSON(w, tpl.Response{Success: false, Message: "获取验证码失败"})
|
|
return
|
|
}
|
|
|
|
rsp := CaptchaResponse{
|
|
CaptchaID: id,
|
|
PicPath: b64s,
|
|
CaptchaLength: keyLong,
|
|
OpenCaptcha: oc,
|
|
}
|
|
tpl.JSON(w, tpl.Response{Success: true, Message: "ok", Data: rsp})
|
|
}
|