From f65ce9c19568745003b22e82060fb38c2885c701 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期五, 13 十月 2023 15:36:30 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/crm --- api/v1/captcha.go | 104 +++++++++++++++++++++++----------------------------- 1 files changed, 46 insertions(+), 58 deletions(-) diff --git a/api/v1/captcha.go b/api/v1/captcha.go index 4be71ca..124ed57 100644 --- a/api/v1/captcha.go +++ b/api/v1/captcha.go @@ -1,62 +1,50 @@ package v1 -import ( - "aps_crm/conf" - "aps_crm/constvar" - "aps_crm/model/response" - "aps_crm/pkg/contextx" - "aps_crm/pkg/convertx" - "aps_crm/pkg/ecode" - "aps_crm/pkg/logx" - "github.com/gin-gonic/gin" - "github.com/mojocn/base64Captcha" - "time" -) - type BaseApi struct{} -// Captcha -// @Tags Base -// @Summary 鑾峰彇楠岃瘉鐮� -// @Produce application/json -// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛" -// @Router /api/base/captcha [post] -func (slf *BaseApi) Captcha(c *gin.Context) { - ctx, ok := contextx.NewContext(c, nil) - if !ok { - return - } - - // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚� - openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鐖嗘鏁� - openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿 - key := c.ClientIP() - v, ok := constvar.BlackCache.Get(key) - if !ok { - constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut)) - } - - var oc bool - if openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha { // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃茬垎娆℃暟 - oc = true - } - // 瀛楃,鍏紡,楠岃瘉鐮侀厤缃� - // 鐢熸垚榛樿鏁板瓧鐨刣river - driver := base64Captcha.NewDriverDigit(conf.Conf.Captcha.ImgHeight, conf.Conf.Captcha.ImgWidth, conf.Conf.Captcha.KeyLong, 0.7, 80) - cp := base64Captcha.NewCaptcha(driver, store) - id, b64s, err := cp.Generate() - captcha := store.Get(id, false) - logx.Infof("Captcha Generate captchaId:%v captcha:%v", id, captcha) - if err != nil { - logx.Errorf("Captcha Generate err:%v", err) - ctx.Fail(ecode.CaptchaGenerateFailed) - return - } - - ctx.OkWithDetailed(response.CaptchaResponse{ - CaptchaId: id, - PicPath: b64s, - CaptchaLength: conf.Conf.Captcha.KeyLong, - OpenCaptcha: oc, - }) -} +// +//// Captcha +//// @Tags Base +//// @Summary 鑾峰彇楠岃瘉鐮� +//// @Produce application/json +//// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛" +//// @Router /api/base/captcha [post] +//func (slf *BaseApi) Captcha(c *gin.Context) { +// ctx, ok := contextx.NewContext(c, nil) +// if !ok { +// return +// } +// +// // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚� +// openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鐖嗘鏁� +// openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿 +// key := c.ClientIP() +// v, ok := constvar.BlackCache.Get(key) +// if !ok { +// constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut)) +// } +// +// var oc bool +// if openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha { // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃茬垎娆℃暟 +// oc = true +// } +// // 瀛楃,鍏紡,楠岃瘉鐮侀厤缃� +// // 鐢熸垚榛樿鏁板瓧鐨刣river +// driver := base64Captcha.NewDriverDigit(conf.Conf.Captcha.ImgHeight, conf.Conf.Captcha.ImgWidth, conf.Conf.Captcha.KeyLong, 0.7, 80) +// cp := base64Captcha.NewCaptcha(driver, store) +// id, b64s, err := cp.Generate() +// captcha := store.Get(id, false) +// logx.Infof("Captcha Generate captchaId:%v captcha:%v", id, captcha) +// if err != nil { +// logx.Errorf("Captcha Generate err:%v", err) +// ctx.Fail(ecode.CaptchaGenerateFailed) +// return +// } +// +// ctx.OkWithDetailed(response.CaptchaResponse{ +// CaptchaId: id, +// PicPath: b64s, +// CaptchaLength: conf.Conf.Captcha.KeyLong, +// OpenCaptcha: oc, +// }) +//} -- Gitblit v1.8.0