From 522dcb347b81641d7cfa7a1d591f531041c4409c Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Mon, 8 May 2023 21:54:18 +0800 Subject: [PATCH 01/18] Update config.go --- config/config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/config.go b/config/config.go index 2ab0f1c..865b50a 100644 --- a/config/config.go +++ b/config/config.go @@ -17,6 +17,8 @@ type WatermarkConfig struct { type BlockPuzzleConfig struct { // 校验时 容错偏移量 Offset int `yaml:"offset"` + // 是否插入干扰图 + IsInterference bool `yaml:"isInterference"` } type ClickWordConfig struct { From 94f0e4a9097431cff1866a95a6c096acd5f6fca1 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Mon, 8 May 2023 21:55:50 +0800 Subject: [PATCH 02/18] Update block_puzzle_captcha_service.go --- service/block_puzzle_captcha_service.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/service/block_puzzle_captcha_service.go b/service/block_puzzle_captcha_service.go index df8ea77..14fcb3f 100644 --- a/service/block_puzzle_captcha_service.go +++ b/service/block_puzzle_captcha_service.go @@ -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 + } } } } From ab66a3ce6b85ed63fb24791849dc0e3cfda251b8 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:04:30 +0800 Subject: [PATCH 03/18] Update go.mod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改配置 --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 91684ed5e7eb85c21e8a9642449c7b44c435fa23 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:16:17 +0800 Subject: [PATCH 04/18] Update example.go --- example.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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" From 29edfd21828e5e950fea8ceaf5f006c9fe9b9a6e Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:16:48 +0800 Subject: [PATCH 05/18] Update config.go --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 865b50a..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" ) From 3490b9b58c2b8343e2968cdaab9fa353539d63f0 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:17:24 +0800 Subject: [PATCH 06/18] Update block_puzzle_captcha_service.go --- service/block_puzzle_captcha_service.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service/block_puzzle_captcha_service.go b/service/block_puzzle_captcha_service.go index 14fcb3f..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" From 4f85c8a145b52987d243e69baea81c0e956859e3 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:17:41 +0800 Subject: [PATCH 07/18] Update captcha_service_factory.go --- service/captcha_service_factory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" ) From b36f7276f297b6627c14c4bc0606a130c47fd4e0 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:17:58 +0800 Subject: [PATCH 08/18] Update click_word_captcha_service.go --- service/click_word_captcha_service.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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" ) From 636ae721347520ccf343151247c0ad9ad60d5924 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:18:16 +0800 Subject: [PATCH 09/18] Update mem_cache_service.go --- service/mem_cache_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" ) From 0117f3e85804206875b0d79397d6024aab8fbd39 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:18:27 +0800 Subject: [PATCH 10/18] Update redis_cache_service.go --- service/redis_cache_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" ) From 570cbe1d9d002f51b40f97aa26d1996fba7041d3 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:18:50 +0800 Subject: [PATCH 11/18] Update block_puzzle_captcha_service_test.go --- test/block_puzzle_captcha_service_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" ) From 51a711cceb9d698d8ae76d3e26c00741fb87fe6e Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:19:01 +0800 Subject: [PATCH 12/18] Update cache_util_test.go --- test/cache_util_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" ) From bc3feadeb4441efe9db764ca2a483d2ba8b17284 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:19:17 +0800 Subject: [PATCH 13/18] Update image_test.go --- test/image_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" ) From a22f74c96712569c83db57756f4c143761b034e7 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:19:30 +0800 Subject: [PATCH 14/18] Update local_cache_service_test.go --- test/local_cache_service_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" ) From 01c9b9626ffda138fc3713707667572b835a1252 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:19:41 +0800 Subject: [PATCH 15/18] Update random_util_test.go --- test/random_util_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" ) From c0f814b500646323648698257cf0e0819e8e5b85 Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Tue, 9 May 2023 08:19:53 +0800 Subject: [PATCH 16/18] Update redis_util_test.go --- test/redis_util_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" ) From b978e971d98810067a49baad8e61261ad0d02cbf Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Fri, 26 May 2023 21:41:14 +0800 Subject: [PATCH 17/18] Update image.go --- util/image/image.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" From 5efb5c8b454ec0d769521b4a4ed5b3c7278e521d Mon Sep 17 00:00:00 2001 From: xierui921326 <30567005+xierui921326@users.noreply.github.com> Date: Fri, 26 May 2023 21:41:36 +0800 Subject: [PATCH 18/18] Update image_util.go --- util/image_util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"