forked from lxh/go-wxhelper
35 lines
770 B
Go
35 lines
770 B
Go
package login
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/mojocn/base64Captcha"
|
|
"wechat-robot/model/vo/login"
|
|
"wechat-robot/pkg/captcha"
|
|
"wechat-robot/pkg/response"
|
|
)
|
|
|
|
// GetImgCaptcha
|
|
// @description: 获取图片验证码
|
|
// @param ctx
|
|
func GetImgCaptcha(ctx *gin.Context) {
|
|
store := new(captcha.RedisStore)
|
|
math := base64Captcha.DriverMath{
|
|
Height: 60,
|
|
Width: 240,
|
|
Fonts: []string{"ApothecaryFont.ttf"},
|
|
}
|
|
|
|
driver := math.ConvertFonts()
|
|
|
|
// 验证码生成器
|
|
c := base64Captcha.NewCaptcha(driver, store)
|
|
id, imgStr, _, err := c.Generate()
|
|
if err != nil {
|
|
response.New(ctx).SetMsg("验证码生成失败").Fail()
|
|
return
|
|
}
|
|
// 数据返回
|
|
result := login.CaptchaCode{Id: id, Img: imgStr}
|
|
response.New(ctx).SetData(result).Success()
|
|
}
|