Bläddra i källkod

wip:提示信息

wangshan 5 månader sedan
förälder
incheckning
279e03d4ee
3 ändrade filer med 32 tillägg och 19 borttagningar
  1. 11 2
      captcha/captcha.go
  2. 20 16
      captcha/entity.go
  3. 1 1
      captcha/slide.go

+ 11 - 2
captcha/captcha.go

@@ -1,5 +1,14 @@
 package captcha
 
+/**
+	1、滑动式
+	2、区域内拖拽滑动式
+	3、中文文本、字母/数字混合 点选
+	4、浅色 中文文本、字母/数字混合 点选
+	5、图形点选
+	6、旋转式
+**/
+
 import (
 	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
 	"fmt"
@@ -69,9 +78,9 @@ func (c *GetCaptcha) GetCaptchaData() (cd CaptRes, err error) {
 	//}(times, timesPhoneKey, timesSessIdKey)
 	//captLock.Unlock()
 	switch {
-	case times < 3:
+	case times < MiniTimes:
 		return c.GetSlideCaptchaData()
-	case times < 7:
+	case times < MaxTimes:
 		return c.GetClickCaptchaData()
 	default:
 		return c.GetRotateCaptchaData()

+ 20 - 16
captcha/entity.go

@@ -7,24 +7,28 @@ import (
 	"sync"
 )
 
+const (
+	MiniTimes       = 3
+	MaxTimes        = 7
+	Padding   int64 = 4
+)
+
 var (
-	num                = 6
 	slideFuncS         []slide.Captcha
 	clickFuncS         []click.Captcha
 	rotateFuncS        []rotate.Captcha
-	rd                       = RandomNumberGenerator()
-	redisTtl                 = 10 * 60
-	padding            int64 = 4
-	RedisCode                = "other"
-	SendCodeKey              = "send_phone_check_%s_%s"
-	MobileCacheKey           = "mobile_captcha_%s"
-	SendCodeTtl              = 30 * 60
-	SendCodeCacheValue       = "send_phone_check_%s_%sValue"
-	SendCodeCacheKey         = "send_phone_check_%s_%sKey"
-	SendCodeCacheTime        = "send_phone_check_%s_%sTime"
-	MoldCacheKey             = "captcha_mold_%s_%s"
-	ResCacheKey              = "captcha_res_%s_%s"
-	TimesCacheKey            = "captcha_times_new_%s"
-	CaptLockMap              = map[string]*sync.Mutex{}
-	CaptLock                 = &sync.Mutex{}
+	rd                 = RandomNumberGenerator()
+	redisTtl           = 10 * 60
+	SendCodeTtl        = 30 * 60
+	RedisCode          = "other"
+	MoldCacheKey       = "captcha_mold_%s_%s"
+	ResCacheKey        = "captcha_res_%s_%s"
+	SendCodeKey        = "send_phone_check_%s_%s"
+	MobileCacheKey     = "mobile_captcha_%s"
+	SendCodeCacheValue = "send_phone_check_%s_%sValue"
+	SendCodeCacheKey   = "send_phone_check_%s_%sKey"
+	SendCodeCacheTime  = "send_phone_check_%s_%sTime"
+	TimesCacheKey      = "captcha_times_new_%s"
+	CaptLockMap        = map[string]*sync.Mutex{}
+	CaptLock           = &sync.Mutex{}
 )

+ 1 - 1
captcha/slide.go

@@ -117,7 +117,7 @@ func (c *CheckCaptcha) CheckSlideCaptchaData(cacheDataByte []byte) (err error) {
 	if 2 == len(src) {
 		sx, _ := strconv.ParseFloat(fmt.Sprintf("%v", src[0]), 64)
 		sy, _ := strconv.ParseFloat(fmt.Sprintf("%v", src[1]), 64)
-		chkRet = slide.CheckPoint(int64(sx), int64(sy), int64(dct.X), int64(dct.Y), padding)
+		chkRet = slide.CheckPoint(int64(sx), int64(sy), int64(dct.X), int64(dct.Y), Padding)
 	}
 	if !chkRet {
 		err = fmt.Errorf("check result false")