diff --git a/README.md b/README.md index 9468886..8ae867e 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ func main() { - click.WithThumbImageSize(option.Size) - click.WithRangeVerifyLen(option.RangeVal) +- click.WithDisabledRangeVerifyLen(bool) - click.WithRangeThumbSize(option.RangeVal) - click.WithRangeThumbColors([]string) - click.WithRangeThumbBgColors([]string) diff --git a/README_zh.md b/README_zh.md index 61bf272..2ef0fec 100644 --- a/README_zh.md +++ b/README_zh.md @@ -193,6 +193,7 @@ func main() { - click.WithThumbImageSize(option.Size) 设置缩略尺寸,默认 150x40 - click.WithRangeVerifyLen(option.RangeVal) 设置校验内容的随机长度范围 +- click.WithDisabledRangeVerifyLen(bool) 禁用校验内容的随机长度,与主图内容的长度保持一致 - click.WithRangeThumbSize(option.RangeVal) 设置随机缩略内容随机大小范围 - click.WithRangeThumbColors([]string) 设置缩略随机颜色范围 - click.WithRangeThumbBgColors([]string) 设置缩略随机背景颜色范围 diff --git a/v2/click/click.go b/v2/click/click.go index f03a53f..a1165e9 100644 --- a/v2/click/click.go +++ b/v2/click/click.go @@ -297,9 +297,10 @@ func (c *captcha) rangeCheckDots(dots map[int]*Dot) (map[int]*Dot, []string) { count := random.RandInt(c.opts.rangeVerifyLen.Min, c.opts.rangeVerifyLen.Max) var values []string for i, value := range rs { - if i >= count { - continue + if !c.opts.disabledRangeVerifyLen && i >= count { + break } + dot := dots[value] dot.Index = i chkDots[i] = dot diff --git a/v2/click/default.go b/v2/click/default.go index 844ec8e..d540262 100644 --- a/v2/click/default.go +++ b/v2/click/default.go @@ -79,6 +79,7 @@ func defaultOptions() Option { opts.imageAlpha = 1 opts.rangeVerifyLen = &option.RangeVal{Min: 2, Max: 4} + opts.disabledRangeVerifyLen = false opts.thumbImageSize = &option.Size{Width: 150, Height: 40} opts.rangeThumbSize = &option.RangeVal{Min: 22, Max: 28} opts.rangeThumbColors = getDefaultThumbColors() diff --git a/v2/click/option.go b/v2/click/option.go index ddada4c..0a7fc19 100644 --- a/v2/click/option.go +++ b/v2/click/option.go @@ -29,6 +29,7 @@ type Options struct { thumbImageSize *option.Size rangeVerifyLen *option.RangeVal + disabledRangeVerifyLen bool rangeThumbSize *option.RangeVal rangeThumbColors []string rangeThumbBgColors []string @@ -123,6 +124,11 @@ func (o *Options) GetRangeVerifyLen() *option.RangeVal { } } +// GetDisabledRangeVerifyLen . +func (o *Options) GetDisabledRangeVerifyLen() bool { + return o.disabledRangeVerifyLen +} + // GetRangeThumbSize . func (o *Options) GetRangeThumbSize() *option.RangeVal { return &option.RangeVal{ @@ -292,6 +298,13 @@ func WithRangeVerifyLen(val option.RangeVal) Option { } } +// WithDisabledRangeVerifyLen . +func WithDisabledRangeVerifyLen(disabled bool) Option { + return func(opts *Options) { + opts.disabledRangeVerifyLen = disabled + } +} + // WithRangeThumbSize . func WithRangeThumbSize(val option.RangeVal) Option { return func(opts *Options) { diff --git a/v2/tests/click_text_test.go b/v2/tests/click_text_test.go index 06d19e8..37b351e 100644 --- a/v2/tests/click_text_test.go +++ b/v2/tests/click_text_test.go @@ -18,6 +18,7 @@ func init() { builder := click.NewBuilder( click.WithRangeLen(option.RangeVal{Min: 4, Max: 6}), click.WithRangeVerifyLen(option.RangeVal{Min: 2, Max: 4}), + click.WithDisabledRangeVerifyLen(true), ) fontN, err := loadFont("../.cache/fzshengsksjw_cu.ttf") @@ -31,7 +32,8 @@ func init() { } builder.SetResources( - click.WithChars([]string{"这", "是", "随", "机", "的", "文", "本", "种", "子", "呀"}), + //click.WithChars([]string{"这", "是", "随", "机", "的", "文", "本", "种", "子", "呀"}), + click.WithChars([]string{"A1", "B2", "C3", "D4", "E5", "F6", "G7", "H8", "I9", "J0"}), click.WithFonts([]*truetype.Font{ fontN, }),