mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package apis
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
"github.com/mojocn/base64Captcha"
|
|
"net/http"
|
|
)
|
|
|
|
//configJsonBody json request body.
|
|
type configJsonBody struct {
|
|
Id string
|
|
CaptchaType string
|
|
VerifyValue string
|
|
DriverAudio *base64Captcha.DriverAudio
|
|
DriverString *base64Captcha.DriverString
|
|
DriverChinese *base64Captcha.DriverChinese
|
|
DriverMath *base64Captcha.DriverMath
|
|
DriverDigit *base64Captcha.DriverDigit
|
|
}
|
|
|
|
var store = base64Captcha.DefaultMemStore
|
|
|
|
func GenerateCaptchaHandler(c *gin.Context) {
|
|
|
|
var param configJsonBody
|
|
param.Id = uuid.New().String()
|
|
//param.CaptchaType = "string"
|
|
param.DriverDigit = base64Captcha.DefaultDriverDigit
|
|
driver := param.DriverDigit
|
|
//param.DriverString = base64Captcha.NewDriverString(46, 140, 2, 2, 4, "234567890abcdefghjkmnpqrstuvwxyz", &color.RGBA{240, 240, 246, 246}, []string{"wqy-microhei.ttc"})
|
|
//driver := param.DriverString.ConvertFonts()
|
|
|
|
cap := base64Captcha.NewCaptcha(driver, store)
|
|
id, b64s, err := cap.Generate()
|
|
body := map[string]interface{}{"code": 200, "data": b64s, "id": id, "msg": "success"}
|
|
if err != nil {
|
|
body = map[string]interface{}{"code": 0, "msg": err.Error()}
|
|
}
|
|
c.JSON(http.StatusOK, body)
|
|
}
|