package loginVerify import ( "fmt" "key_performance_indicators/middleware/grocerystore" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" "github.com/gin-gonic/gin" "github.com/mojocn/base64Captcha" ) var store = base64Captcha.DefaultMemStore func (a *ApiMethod) Captcha(c *gin.Context) { // 字符,公式,验证码配置 // 生成默认数字的driver driver := base64Captcha.NewDriverDigit(overall.CONSTANT_CONFIG.Captcha.ImgHeight, overall.CONSTANT_CONFIG.Captcha.ImgWidth, overall.CONSTANT_CONFIG.Captcha.KeyLong, 0.7, 80) //coder := base64Captcha.NewCaptcha(driver, store.UseWithCtx(c)) // v8下使用redis coder := base64Captcha.NewCaptcha(driver, store) if id, b64s, err := coder.Generate(); err != nil { publicmethod.Result(1, err, c, "验证码获取失败") } else { publicmethod.Result(0, SysCaptchaResponse{ CaptchaId: id, PicPath: b64s, }, c) } } // 验证授权是否还有效 func (a *ApiMethod) VerifyEmpower(c *gin.Context) { userKey := c.Request.Header.Get("user-key") if userKey == "" { publicmethod.Result(9001, userKey, c, "未获得授权信息!") return } redisFileKey := fmt.Sprintf("ScanCode:Authentication:LoginApi_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userKey) redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5) userRedisToken, isTrue := redisClient.HashGetAll(redisFileKey) if isTrue == false { publicmethod.Result(9002, userKey, c, "授权超时!") return } publicmethod.Result(0, userRedisToken, c) }