|
|
|
@ -6,7 +6,6 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/mojocn/base64Captcha"
|
|
|
|
|
"image/color"
|
|
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -31,10 +30,7 @@ type CaptchaResult struct {
|
|
|
|
|
|
|
|
|
|
// GetOne 生成图形化验证码
|
|
|
|
|
func getCaptcha(c *gin.Context) {
|
|
|
|
|
id, b64s, err := CaptMake()
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "发生错误!"})
|
|
|
|
|
}
|
|
|
|
|
id, b64s := CaptMake()
|
|
|
|
|
captchaResult := CaptchaResult{
|
|
|
|
|
Id: id,
|
|
|
|
|
Base64Blob: b64s,
|
|
|
|
@ -59,31 +55,18 @@ func verifyCaptcha(c *gin.Context) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CaptMake 生成验证码
|
|
|
|
|
func CaptMake() (id, b64s string, err error) {
|
|
|
|
|
var driver base64Captcha.Driver
|
|
|
|
|
var driverString base64Captcha.DriverString
|
|
|
|
|
|
|
|
|
|
// 配置验证码信息
|
|
|
|
|
captchaConfig := base64Captcha.DriverString{
|
|
|
|
|
Height: 60,
|
|
|
|
|
Width: 200,
|
|
|
|
|
NoiseCount: 0,
|
|
|
|
|
ShowLineOptions: 2 | 4,
|
|
|
|
|
Length: 4,
|
|
|
|
|
Source: "1234567890qwertyuioplkjhgfdsazxcvbnm",
|
|
|
|
|
BgColor: &color.RGBA{
|
|
|
|
|
R: 3,
|
|
|
|
|
G: 102,
|
|
|
|
|
B: 214,
|
|
|
|
|
A: 125,
|
|
|
|
|
},
|
|
|
|
|
Fonts: []string{"wqy-microhei.ttc"},
|
|
|
|
|
func CaptMake() (string, string) {
|
|
|
|
|
// 生成默认数字
|
|
|
|
|
driver := base64Captcha.DefaultDriverDigit
|
|
|
|
|
// 生成base64图片
|
|
|
|
|
c := base64Captcha.NewCaptcha(driver, store)
|
|
|
|
|
// 获取
|
|
|
|
|
id, b64s, err := c.Generate()
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("Register GetCaptchaPhoto get base64Captcha has err:", err)
|
|
|
|
|
return "", ""
|
|
|
|
|
}
|
|
|
|
|
driverString = captchaConfig
|
|
|
|
|
driver = driverString.ConvertFonts()
|
|
|
|
|
captcha := base64Captcha.NewCaptcha(driver, store)
|
|
|
|
|
lid, lb64s, lerr := captcha.Generate()
|
|
|
|
|
return lid, lb64s, lerr
|
|
|
|
|
return id, b64s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CaptVerify 验证captcha是否正确
|
|
|
|
|