diff --git a/config/config.go b/config/config.go index 2ab0f1c..66d38c6 100644 --- a/config/config.go +++ b/config/config.go @@ -2,7 +2,7 @@ package config import ( "errors" - "github.com/TestsLing/aj-captcha-go/const" + "github.com/xierui921326/aj-captcha-go/const" "image/color" "strings" ) @@ -17,6 +17,8 @@ type WatermarkConfig struct { type BlockPuzzleConfig struct { // 校验时 容错偏移量 Offset int `yaml:"offset"` + // 是否插入干扰图 + IsInterference bool `yaml:"isInterference"` } type ClickWordConfig struct { diff --git a/example.go b/example.go index 21800ab..7d177b2 100644 --- a/example.go +++ b/example.go @@ -3,9 +3,9 @@ package main import ( "encoding/json" "errors" - config2 "github.com/TestsLing/aj-captcha-go/config" - "github.com/TestsLing/aj-captcha-go/const" - "github.com/TestsLing/aj-captcha-go/service" + config2 "github.com/xierui921326/aj-captcha-go/config" + "github.com/xierui921326/aj-captcha-go/const" + "github.com/xierui921326/aj-captcha-go/service" "image/color" "io/ioutil" "log" diff --git a/go.mod b/go.mod index f8b61ab..735cfd3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/TestsLing/aj-captcha-go +module github.com/xierui921326/aj-captcha-go -go 1.12 +go 1.19 require ( github.com/go-redis/redis/v8 v8.11.5 diff --git a/service/block_puzzle_captcha_service.go b/service/block_puzzle_captcha_service.go index df8ea77..4e4cd87 100644 --- a/service/block_puzzle_captcha_service.go +++ b/service/block_puzzle_captcha_service.go @@ -4,10 +4,10 @@ import ( "encoding/json" "errors" "fmt" - constant "github.com/TestsLing/aj-captcha-go/const" - "github.com/TestsLing/aj-captcha-go/model/vo" - "github.com/TestsLing/aj-captcha-go/util" - img "github.com/TestsLing/aj-captcha-go/util/image" + constant "github.com/xierui921326/aj-captcha-go/const" + "github.com/xierui921326/aj-captcha-go/model/vo" + "github.com/xierui921326/aj-captcha-go/util" + img "github.com/xierui921326/aj-captcha-go/util/image" "golang.org/x/image/colornames" "log" "math" @@ -40,7 +40,7 @@ func (b *BlockPuzzleCaptchaService) Get() (map[string]interface{}, error) { templateImage := img.GetTemplateImage() // 构造前端所需图片 - b.pictureTemplatesCut(backgroundImage, templateImage) + b.pictureTemplatesCut(backgroundImage, templateImage, b.factory.config.BlockPuzzle.IsInterference) originalImageBase64, err := backgroundImage.Base64() jigsawImageBase64, err := templateImage.Base64() @@ -67,20 +67,22 @@ func (b *BlockPuzzleCaptchaService) Get() (map[string]interface{}, error) { return data, nil } -func (b *BlockPuzzleCaptchaService) pictureTemplatesCut(backgroundImage *util.ImageUtil, templateImage *util.ImageUtil) { +func (b *BlockPuzzleCaptchaService) pictureTemplatesCut(backgroundImage *util.ImageUtil, templateImage *util.ImageUtil, isInterference bool) { // 生成拼图坐标点 b.generateJigsawPoint(backgroundImage, templateImage) // 裁剪模板图 b.cutByTemplate(backgroundImage, templateImage, b.point.X, 0) - // 插入干扰图 - for { - newTemplateImage := img.GetTemplateImage() - if newTemplateImage.Src != templateImage.Src { - offsetX := util.RandomInt(0, backgroundImage.Width-newTemplateImage.Width-5) - if math.Abs(float64(newTemplateImage.Width-offsetX)) > float64(newTemplateImage.Width/2) { - b.interferenceByTemplate(backgroundImage, newTemplateImage, offsetX, b.point.Y) - break + if isInterference { + // 插入干扰图 + for { + newTemplateImage := img.GetTemplateImage() + if newTemplateImage.Src != templateImage.Src { + offsetX := util.RandomInt(0, backgroundImage.Width-newTemplateImage.Width-5) + if math.Abs(float64(newTemplateImage.Width-offsetX)) > float64(newTemplateImage.Width/2) { + b.interferenceByTemplate(backgroundImage, newTemplateImage, offsetX, b.point.Y) + break + } } } } diff --git a/service/captcha_service_factory.go b/service/captcha_service_factory.go index 3d18bd2..47ccda6 100644 --- a/service/captcha_service_factory.go +++ b/service/captcha_service_factory.go @@ -1,7 +1,7 @@ package service import ( - configIns "github.com/TestsLing/aj-captcha-go/config" + configIns "github.com/xierui921326/aj-captcha-go/config" "log" "sync" ) diff --git a/service/click_word_captcha_service.go b/service/click_word_captcha_service.go index ac1a2b4..0b0e513 100644 --- a/service/click_word_captcha_service.go +++ b/service/click_word_captcha_service.go @@ -4,10 +4,10 @@ import ( "encoding/json" "errors" "fmt" - constant "github.com/TestsLing/aj-captcha-go/const" - "github.com/TestsLing/aj-captcha-go/model/vo" - "github.com/TestsLing/aj-captcha-go/util" - img "github.com/TestsLing/aj-captcha-go/util/image" + constant "github.com/xierui921326/aj-captcha-go/const" + "github.com/xierui921326/aj-captcha-go/model/vo" + "github.com/xierui921326/aj-captcha-go/util" + img "github.com/xierui921326/aj-captcha-go/util/image" "log" ) diff --git a/service/mem_cache_service.go b/service/mem_cache_service.go index 3111fcb..d690b91 100644 --- a/service/mem_cache_service.go +++ b/service/mem_cache_service.go @@ -1,7 +1,7 @@ package service import ( - "github.com/TestsLing/aj-captcha-go/util" + "github.com/xierui921326/aj-captcha-go/util" "strconv" ) diff --git a/service/redis_cache_service.go b/service/redis_cache_service.go index 0b40e2a..80106c7 100644 --- a/service/redis_cache_service.go +++ b/service/redis_cache_service.go @@ -1,7 +1,7 @@ package service import ( - "github.com/TestsLing/aj-captcha-go/util" + "github.com/xierui921326/aj-captcha-go/util" "strconv" ) diff --git a/test/block_puzzle_captcha_service_test.go b/test/block_puzzle_captcha_service_test.go index 02be192..4165509 100644 --- a/test/block_puzzle_captcha_service_test.go +++ b/test/block_puzzle_captcha_service_test.go @@ -2,8 +2,8 @@ package test import ( "fmt" - "github.com/TestsLing/aj-captcha-go/service" - "github.com/TestsLing/aj-captcha-go/util" + "github.com/xierui921326/aj-captcha-go/service" + "github.com/xierui921326/aj-captcha-go/util" "image/color" "testing" ) diff --git a/test/cache_util_test.go b/test/cache_util_test.go index 31657b9..d52a2ba 100644 --- a/test/cache_util_test.go +++ b/test/cache_util_test.go @@ -1,7 +1,7 @@ package test import ( - "github.com/TestsLing/aj-captcha-go/util" + "github.com/xierui921326/aj-captcha-go/util" "testing" "time" ) diff --git a/test/image_test.go b/test/image_test.go index 69eabee..997cc04 100644 --- a/test/image_test.go +++ b/test/image_test.go @@ -1,7 +1,7 @@ package test import ( - i "github.com/TestsLing/aj-captcha-go/util/image" + i "github.com/xierui921326/aj-captcha-go/util/image" "testing" ) diff --git a/test/local_cache_service_test.go b/test/local_cache_service_test.go index a49f818..64fb791 100644 --- a/test/local_cache_service_test.go +++ b/test/local_cache_service_test.go @@ -1,7 +1,7 @@ package test import ( - "github.com/TestsLing/aj-captcha-go/service" + "github.com/xierui921326/aj-captcha-go/service" "testing" ) diff --git a/test/random_util_test.go b/test/random_util_test.go index 9a3b9e4..188ffd8 100644 --- a/test/random_util_test.go +++ b/test/random_util_test.go @@ -2,7 +2,7 @@ package test import ( "fmt" - "github.com/TestsLing/aj-captcha-go/util" + "github.com/xierui921326/aj-captcha-go/util" "testing" ) diff --git a/test/redis_util_test.go b/test/redis_util_test.go index 9d02358..9da4398 100644 --- a/test/redis_util_test.go +++ b/test/redis_util_test.go @@ -1,7 +1,7 @@ package test import ( - "github.com/TestsLing/aj-captcha-go/util" + "github.com/xierui921326/aj-captcha-go/util" "testing" "time" ) diff --git a/util/image/image.go b/util/image/image.go index 548d860..561adb9 100644 --- a/util/image/image.go +++ b/util/image/image.go @@ -1,8 +1,8 @@ package image import ( - "github.com/TestsLing/aj-captcha-go/const" - "github.com/TestsLing/aj-captcha-go/util" + "github.com/xierui921326/aj-captcha-go/const" + "github.com/xierui921326/aj-captcha-go/util" "log" "os" "path/filepath" diff --git a/util/image_util.go b/util/image_util.go index 460a718..ef39d3c 100644 --- a/util/image_util.go +++ b/util/image_util.go @@ -3,7 +3,7 @@ package util import ( "bytes" "encoding/base64" - "github.com/TestsLing/aj-captcha-go/model/vo" + "github.com/xierui921326/aj-captcha-go/model/vo" "github.com/golang/freetype" "image" "image/color"