🎨验证码接口
This commit is contained in:
36
http/api/captcha.go
Normal file
36
http/api/captcha.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"wireguard-dashboard/compoment"
|
||||
"wireguard-dashboard/utils"
|
||||
)
|
||||
|
||||
type captcha struct{}
|
||||
|
||||
func Captcha() captcha {
|
||||
return captcha{}
|
||||
}
|
||||
|
||||
// GenerateCaptcha
|
||||
// @description: 生成验证码
|
||||
// @receiver captcha
|
||||
// @param c
|
||||
func (captcha) GenerateCaptcha(c *gin.Context) {
|
||||
math := base64Captcha.DriverMath{Height: 60, Width: 240, Fonts: []string{"ApothecaryFont.ttf", "3Dumb.ttf"}}
|
||||
mathDriver := math.ConvertFonts()
|
||||
|
||||
capt := base64Captcha.NewCaptcha(mathDriver, compoment.CaptchaStore{})
|
||||
|
||||
id, base64Str, _, err := capt.Generate()
|
||||
if err != nil {
|
||||
utils.GinResponse(c).FailedWithErr("生成验证码失败: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.GinResponse(c).OKWithData(map[string]any{
|
||||
"id": id,
|
||||
"captcha": base64Str,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user