From ee371446146f9286e056c36f782f61ea26693462 Mon Sep 17 00:00:00 2001 From: "Mr.Null" Date: Sun, 27 Jul 2025 17:11:36 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lazy.Captcha.xUnit/Demo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lazy.Captcha.xUnit/Demo.cs b/Lazy.Captcha.xUnit/Demo.cs index d65e5a6..2c6116c 100644 --- a/Lazy.Captcha.xUnit/Demo.cs +++ b/Lazy.Captcha.xUnit/Demo.cs @@ -33,7 +33,7 @@ namespace Lazy.Captcha.xUnit [InlineData("#FF000088")] [InlineData("#00FF0088")] [InlineData("#0000FF88")] - [Trait("SixLabors工具", "SixLabors")] + [Trait("SixLabors宸ュ叿", "SixLabors")] public void GenerateCaptcha_Test(string color) { //var outputFileName = System.IO.Path.Combine(OutputPath, $"cc2_{color}.png"); @@ -48,7 +48,7 @@ namespace Lazy.Captcha.xUnit //} //var fileExists = File.Exists(outputFileName); - //_outputHelper.WriteLine(fileExists ? "文件存在" : "文件不存在"); + //_outputHelper.WriteLine(fileExists ? "鏂囦欢瀛樺湪" : "鏂囦欢涓嶅瓨鍦"); //Assert.True(fileExists); } } -- Gitee From 625dba7f5935b3a7be9c1e38e46c88aac32829a4 Mon Sep 17 00:00:00 2001 From: "Mr.Null" Date: Sun, 27 Jul 2025 17:40:39 +0800 Subject: [PATCH 2/4] =?UTF-8?q?typo.=20=E4=BF=AE=E6=AD=A3=20`Lazy.Captcha.?= =?UTF-8?q?Core`=20=E4=B8=AD=E7=9A=84=E6=8B=BC=E5=86=99=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=B0=86=E9=94=99=E8=AF=AF=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E6=A0=87=E8=AE=B0=E4=B8=BA=E5=BA=9F=E5=BC=83=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lazy.Captcha.Core/CaptchaOptions.cs | 15 +++++++++-- Lazy.Captcha.Core/CaptchaServiceBuilder.cs | 26 ++++++++++++++----- .../CaptchaServiceCollectionExtensions.cs | 1 - Lazy.Captcha.Core/Storage/DefaultStorage.cs | 21 +++++---------- .../{MemeoryStorage.cs => MemoryStorage.cs} | 20 +++++++------- README.md | 5 ++-- 6 files changed, 51 insertions(+), 37 deletions(-) rename Lazy.Captcha.Core/Storage/{MemeoryStorage.cs => MemoryStorage.cs} (44%) diff --git a/Lazy.Captcha.Core/CaptchaOptions.cs b/Lazy.Captcha.Core/CaptchaOptions.cs index 453987f..48c3e7e 100644 --- a/Lazy.Captcha.Core/CaptchaOptions.cs +++ b/Lazy.Captcha.Core/CaptchaOptions.cs @@ -1,4 +1,5 @@ -锘縰sing Lazy.Captcha.Core.Generator; +锘縰sing System; +using Lazy.Captcha.Core.Generator; using Lazy.Captcha.Core.Generator.Image.Option; namespace Lazy.Captcha.Core @@ -52,8 +53,18 @@ namespace Lazy.Captcha.Core /// /// 瀛樺偍閿墠缂 /// - public virtual string StoreageKeyPrefix { get; set; } + public virtual string StorageKeyPrefix { get; set; } + /// + /// 瀛樺偍閿墠缂 + /// + [Obsolete("鐢变簬鎷煎啓閿欒锛屽簲琚簾寮冦傝浣跨敤 `StorageKeyPrefix`銆", false)] + public virtual string StoreageKeyPrefix + { + get => StorageKeyPrefix; + set => StorageKeyPrefix = value; + } + /// /// 鍥剧墖閫夐」 /// diff --git a/Lazy.Captcha.Core/CaptchaServiceBuilder.cs b/Lazy.Captcha.Core/CaptchaServiceBuilder.cs index 82b610a..8d807b4 100644 --- a/Lazy.Captcha.Core/CaptchaServiceBuilder.cs +++ b/Lazy.Captcha.Core/CaptchaServiceBuilder.cs @@ -12,13 +12,13 @@ namespace Lazy.Captcha.Core /// public class CaptchaServiceBuilder { - private CaptchaOptions CaptchaOptions; - private IStorage InnerStorage; + private CaptchaOptions CaptchaOptions; + private IStorage InnerStorage; - public CaptchaServiceBuilder() + public CaptchaServiceBuilder() { CaptchaOptions = GenerateDefaultOptions(); - InnerStorage = new MemeoryStorage(); + InnerStorage = new MemoryStorage(); } public static CaptchaServiceBuilder New() @@ -97,11 +97,23 @@ namespace Lazy.Captcha.Core /// /// 瀛樺偍閿墠缂 /// - /// + /// /// - public CaptchaServiceBuilder StoreageKeyPrefix(string storeageKeyPrefix) + public CaptchaServiceBuilder StorageKeyPrefix(string storageKeyPrefix) { - CaptchaOptions.StoreageKeyPrefix = storeageKeyPrefix; + CaptchaOptions.StorageKeyPrefix = storageKeyPrefix; + return this; + } + + /// + /// 瀛樺偍閿墠缂 + /// + /// + /// + [Obsolete("鐢变簬鎷煎啓閿欒锛岃鏂规硶搴旇搴熷純銆備娇鐢 `StorageKeyPrefix`銆", false)] + public CaptchaServiceBuilder StoreageKeyPrefix(string storageKeyPrefix) + { + CaptchaOptions.StorageKeyPrefix = storageKeyPrefix; return this; } diff --git a/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs b/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs index dd6c342..7d89a66 100644 --- a/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs +++ b/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs @@ -6,7 +6,6 @@ using System.Linq; using Lazy.Captcha.Core; using Lazy.Captcha.Core.RateLimit; using Lazy.Captcha.Core.Storage; -using Lazy.Captcha.Core.Storeage; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection.Extensions; using SkiaSharp; diff --git a/Lazy.Captcha.Core/Storage/DefaultStorage.cs b/Lazy.Captcha.Core/Storage/DefaultStorage.cs index f93d0f7..0a974f2 100644 --- a/Lazy.Captcha.Core/Storage/DefaultStorage.cs +++ b/Lazy.Captcha.Core/Storage/DefaultStorage.cs @@ -3,37 +3,28 @@ using Lazy.Captcha.Core.Storage; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Options; -namespace Lazy.Captcha.Core.Storeage +namespace Lazy.Captcha.Core.Storage { - public class DefaultStorage : IStorage + public class DefaultStorage(IOptionsMonitor options, IDistributedCache cache) : IStorage { - private readonly IDistributedCache _cache; - private readonly IOptionsMonitor _options; - - public DefaultStorage(IOptionsMonitor options, IDistributedCache cache) - { - _options = options; - _cache = cache; - } - private string WrapKey(string key) { - return $"{this._options.CurrentValue.StoreageKeyPrefix}{key}"; + return $"{options.CurrentValue.StorageKeyPrefix}{key}"; } public string Get(string key) { - return _cache.GetString(WrapKey(key)); + return cache.GetString(WrapKey(key)); } public void Remove(string key) { - _cache.Remove(WrapKey(key)); + cache.Remove(WrapKey(key)); } public void Set(string key, string value, DateTimeOffset absoluteExpiration) { - _cache.SetString(WrapKey(key), value, new DistributedCacheEntryOptions + cache.SetString(WrapKey(key), value, new DistributedCacheEntryOptions { AbsoluteExpiration = absoluteExpiration }); diff --git a/Lazy.Captcha.Core/Storage/MemeoryStorage.cs b/Lazy.Captcha.Core/Storage/MemoryStorage.cs similarity index 44% rename from Lazy.Captcha.Core/Storage/MemeoryStorage.cs rename to Lazy.Captcha.Core/Storage/MemoryStorage.cs index 6c84cb7..28652a4 100644 --- a/Lazy.Captcha.Core/Storage/MemeoryStorage.cs +++ b/Lazy.Captcha.Core/Storage/MemoryStorage.cs @@ -5,34 +5,36 @@ using System.Text; namespace Lazy.Captcha.Core.Storage { - public class MemeoryStorage : IStorage + public class MemoryStorage : IStorage { - private MemoryCache Cache; - public string StoreageKeyPrefix { get; set; } = string.Empty; + private readonly MemoryCache _cache = MemoryCache.Default; + public string StorageKeyPrefix { get; set; } = string.Empty; - public MemeoryStorage() + [Obsolete("鐢变簬鎷煎啓閿欒锛屽凡琚簾寮冦傝浣跨敤 `StorageKeyPrefix`銆", false)] + public string StoreageKeyPrefix { - Cache = MemoryCache.Default; + get => StorageKeyPrefix; + set => StorageKeyPrefix = value; } private string WrapKey(string key) { - return $"{StoreageKeyPrefix}{key}"; + return $"{StorageKeyPrefix}{key}"; } public string Get(string key) { - return Cache.Get(WrapKey(key)); + return _cache.Get(WrapKey(key)); } public void Remove(string key) { - Cache.Remove(WrapKey(key)); + _cache.Remove(WrapKey(key)); } public void Set(string key, string value, DateTimeOffset absoluteExpiration) { - Cache.Set(WrapKey(key), value, absoluteExpiration); + _cache.Set(WrapKey(key), value, absoluteExpiration); } } } diff --git a/README.md b/README.md index f9e2b43..ba63cc1 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ builder.Services.AddCaptcha(builder.Configuration); "CodeLength": 4, // 楠岃瘉鐮侀暱搴, 瑕佹斁鍦–aptchaType璁剧疆鍚 褰撶被鍨嬩负绠楁湳琛ㄨ揪寮忔椂锛岄暱搴︿唬琛ㄦ搷浣滅殑涓暟, 渚嬪2 "ExpirySeconds": 60, // 楠岃瘉鐮佽繃鏈熺鏁 "IgnoreCase": true, // 姣旇緝鏃舵槸鍚﹀拷鐣ュぇ灏忓啓 - "StoreageKeyPrefix": "", // 瀛樺偍閿墠缂 + "StorageKeyPrefix": "", // 瀛樺偍閿墠缂 "RateLimit": { "Enabled": false, // 鏄惁鍚敤棰戠巼闄愬埗 "WindowSeconds": 60, // 鏃堕棿绐楀彛锛堢锛 @@ -136,12 +136,11 @@ builder.Services.AddCaptcha(builder.Configuration); ``` c# // 鍏ㄩ儴閰嶇疆 builder.Services.AddCaptcha(builder.Configuration, option => -{ option.CaptchaType = CaptchaType.WORD; // 楠岃瘉鐮佺被鍨 option.CodeLength = 6; // 楠岃瘉鐮侀暱搴, 瑕佹斁鍦–aptchaType璁剧疆鍚. 褰撶被鍨嬩负绠楁湳琛ㄨ揪寮忔椂锛岄暱搴︿唬琛ㄦ搷浣滅殑涓暟 option.ExpirySeconds = 30; // 楠岃瘉鐮佽繃鏈熸椂闂 option.IgnoreCase = true; // 姣旇緝鏃舵槸鍚﹀拷鐣ュぇ灏忓啓 - option.StoreageKeyPrefix = ""; // 瀛樺偍閿墠缂 + option.StorageKeyPrefix = ""; // 瀛樺偍閿墠缂 option.ImageOption.Animation = true; // 鏄惁鍚敤鍔ㄧ敾 option.ImageOption.FrameDelay = 30; // 姣忓抚寤惰繜,Animation=true鏃舵湁鏁, 榛樿30 -- Gitee From 039870f16bee558e8dd76dfd765900c9062d2fe0 Mon Sep 17 00:00:00 2001 From: "Mr.Null" Date: Sun, 27 Jul 2025 17:59:01 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20`Family`=20=E7=9A=84?= =?UTF-8?q?=E5=A4=8D=E6=95=B0=E5=BD=A2=E5=BC=8F=E6=8B=BC=E5=86=99=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lazy.Captcha.Core/CaptchaOptions.cs | 2 +- .../CaptchaServiceCollectionExtensions.cs | 2 +- ...tFontFamilys.cs => DefaultFontFamilies.cs} | 135 +++++------------- .../Option/CaptchaImageGeneratorOption.cs | 2 +- Sample.MvcFramework/Global.asax.cs | 2 +- .../Controllers/CaptchaController.cs | 2 +- Sample.NetCore/RandomCaptcha.cs | 4 +- .../FontFamilyOptionProvider.cs | 22 +-- 8 files changed, 55 insertions(+), 116 deletions(-) rename Lazy.Captcha.Core/{DefaultFontFamilys.cs => DefaultFontFamilies.cs} (45%) diff --git a/Lazy.Captcha.Core/CaptchaOptions.cs b/Lazy.Captcha.Core/CaptchaOptions.cs index 48c3e7e..12ad5ed 100644 --- a/Lazy.Captcha.Core/CaptchaOptions.cs +++ b/Lazy.Captcha.Core/CaptchaOptions.cs @@ -28,7 +28,7 @@ namespace Lazy.Captcha.Core if (value.ContainsChinese()) { - this.ImageOption.FontFamily = DefaultFontFamilys.Instance.Kaiti; + this.ImageOption.FontFamily = DefaultFontFamilies.Instance.Kaiti; } _captchaType = value; diff --git a/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs b/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs index 7d89a66..51437ae 100644 --- a/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs +++ b/Lazy.Captcha.Core/CaptchaServiceCollectionExtensions.cs @@ -34,7 +34,7 @@ namespace Microsoft.Extensions.DependencyInjection var fontFamily = configuration?.GetSection("CaptchaOptions:ImageOption:FontFamily")?.Value; if (!string.IsNullOrWhiteSpace(fontFamily)) { - options.ImageOption.FontFamily = DefaultFontFamilys.Instance.GetFontFamily(fontFamily); + options.ImageOption.FontFamily = DefaultFontFamilies.Instance.GetFontFamily(fontFamily); } var backgroundColor = configuration?.GetSection("CaptchaOptions:ImageOption:BackgroundColor")?.Value; diff --git a/Lazy.Captcha.Core/DefaultFontFamilys.cs b/Lazy.Captcha.Core/DefaultFontFamilies.cs similarity index 45% rename from Lazy.Captcha.Core/DefaultFontFamilys.cs rename to Lazy.Captcha.Core/DefaultFontFamilies.cs index 6e34e70..e6bb12d 100644 --- a/Lazy.Captcha.Core/DefaultFontFamilys.cs +++ b/Lazy.Captcha.Core/DefaultFontFamilies.cs @@ -6,11 +6,12 @@ using SkiaSharp; namespace Lazy.Captcha.Core { - public class DefaultFontFamilys + public class DefaultFontFamilies { - public static DefaultFontFamilys Instance = new DefaultFontFamilys(); - private static List _fontFamilies = null; - private static Dictionary FamilyNameMapper = new Dictionary + public static readonly DefaultFontFamilies Instance = new DefaultFontFamilies(); + private static readonly List _fontFamilies = []; + + private static readonly Dictionary FamilyNameMapper = new Dictionary { { "actionj", "Action Jackson" }, { "epilog", "Epilog" }, @@ -25,25 +26,22 @@ namespace Lazy.Captcha.Core { "kaiti", "FZKai-Z03" } }; - static DefaultFontFamilys() + static DefaultFontFamilies() { - if (_fontFamilies == null) + if (_fontFamilies.Count != 0) + return; + + var assembly = Assembly.GetExecutingAssembly(); + var names = assembly.GetManifestResourceNames(); + + if (names.Length == 0) { - var assembly = Assembly.GetExecutingAssembly(); - var names = assembly.GetManifestResourceNames(); - _fontFamilies = new List(); - - if (names?.Length > 0 == true) - { - foreach (var name in names) - { - _fontFamilies.Add(SKTypeface.FromStream(assembly.GetManifestResourceStream(name))); - } - } - else - { - throw new Exception($"缁樺埗楠岃瘉鐮佸瓧浣撴枃浠跺姞杞藉け璐"); - } + throw new Exception("缁樺埗楠岃瘉鐮佸瓧浣撴枃浠跺姞杞藉け璐"); + } + + foreach (var name in names) + { + _fontFamilies.Add(SKTypeface.FromStream(assembly.GetManifestResourceStream(name))); } } @@ -59,6 +57,7 @@ namespace Lazy.Captcha.Core // 榛樿瀛椾綋 realName = FamilyNameMapper[normalizeName]; } + // 鏀圭敤StartsWith, 鏌愪簺鐜涓嬶細 Prefix鍙栧埌鐨勫间负Prefix Endangered, Ransom鍙栧埌鐨勫间负Ransom CutUpLetters return _fontFamilies.First(f => f.FamilyName.StartsWith(realName)); } @@ -66,122 +65,62 @@ namespace Lazy.Captcha.Core /// /// ACTIONJ /// - public SKTypeface Actionj - { - get - { - return GetFontFamily("Actionj"); - } - } + public SKTypeface Actionj => GetFontFamily("Actionj"); /// /// Epilog /// - public SKTypeface Epilog - { - get - { - return GetFontFamily("Epilog"); - } - } + public SKTypeface Epilog => GetFontFamily("Epilog"); /// /// Fresnel /// - public SKTypeface Fresnel - { - get - { - return GetFontFamily("Fresnel"); - } - } + public SKTypeface Fresnel => GetFontFamily("Fresnel"); /// /// headache /// - public SKTypeface Headache - { - get - { - return GetFontFamily("Headache"); - } - } + public SKTypeface Headache => GetFontFamily("Headache"); /// /// Lexo /// - public SKTypeface Lexo - { - get - { - return GetFontFamily("Lexo"); - } - } + public SKTypeface Lexo => GetFontFamily("Lexo"); /// /// Prefix /// - public SKTypeface Prefix - { - get - { - return GetFontFamily("Prefix"); - } - } + public SKTypeface Prefix => GetFontFamily("Prefix"); /// /// Progbot /// - public SKTypeface Progbot - { - get - { - return GetFontFamily("Progbot"); - } - } + public SKTypeface Progbot => GetFontFamily("Progbot"); /// /// Ransom /// - public SKTypeface Ransom - { - get - { - return GetFontFamily("Ransom"); - } - } + public SKTypeface Ransom => GetFontFamily("Ransom"); /// /// Robot /// - public SKTypeface Robot - { - get - { - return GetFontFamily("Robot"); - } - } + public SKTypeface Robot => GetFontFamily("Robot"); /// /// Scandal /// - public SKTypeface Scandal - { - get - { - return GetFontFamily("Scandal"); - } - } + public SKTypeface Scandal => GetFontFamily("Scandal"); /// /// 妤蜂綋 /// - public SKTypeface Kaiti - { - get - { - return GetFontFamily("Kaiti"); - } - } + public SKTypeface Kaiti => GetFontFamily("Kaiti"); + } + + [Obsolete("鎷煎啓閿欒銆傝浣跨敤 `DefaultFontFamilies` 浠f浛銆")] + public class DefaultFontFamilys + { + public static readonly DefaultFontFamilies Instance = DefaultFontFamilies.Instance; } } \ No newline at end of file diff --git a/Lazy.Captcha.Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs b/Lazy.Captcha.Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs index 2b5c4ea..99bfd72 100644 --- a/Lazy.Captcha.Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs +++ b/Lazy.Captcha.Core/Generator/Image/Option/CaptchaImageGeneratorOption.cs @@ -24,7 +24,7 @@ namespace Lazy.Captcha.Core.Generator.Image.Option /// /// FontFamily /// - public SKTypeface FontFamily { get; set;}= DefaultFontFamilys.Instance.Kaiti; + public SKTypeface FontFamily { get; set;}= DefaultFontFamilies.Instance.Kaiti; /// /// 瀛椾綋澶у皬 /// diff --git a/Sample.MvcFramework/Global.asax.cs b/Sample.MvcFramework/Global.asax.cs index 9ac5e73..7034b72 100644 --- a/Sample.MvcFramework/Global.asax.cs +++ b/Sample.MvcFramework/Global.asax.cs @@ -31,7 +31,7 @@ namespace Sample.MvcFramework .Height(35) .FontSize(20) .CaptchaType(CaptchaType.ARITHMETIC) - .FontFamily(DefaultFontFamilys.Instance.Ransom) + .FontFamily(DefaultFontFamilies.Instance.Ransom) .InterferenceLineCount(3) .Animation(false) .Build(); diff --git a/Sample.NetCore/Controllers/CaptchaController.cs b/Sample.NetCore/Controllers/CaptchaController.cs index 29cd61f..decd688 100644 --- a/Sample.NetCore/Controllers/CaptchaController.cs +++ b/Sample.NetCore/Controllers/CaptchaController.cs @@ -131,7 +131,7 @@ namespace Sample.NetCore.Controllers .Height(35) .FontSize(26) .CaptchaType(Enum.Parse(type)) - .FontFamily(DefaultFontFamilys.Instance.GetFontFamily(font)) + .FontFamily(DefaultFontFamilies.Instance.GetFontFamily(font)) .InterferenceLineCount(2) .Animation(false) .TextBold(textBold) diff --git a/Sample.NetCore/RandomCaptcha.cs b/Sample.NetCore/RandomCaptcha.cs index c6800d9..91ff304 100644 --- a/Sample.NetCore/RandomCaptcha.cs +++ b/Sample.NetCore/RandomCaptcha.cs @@ -39,12 +39,12 @@ namespace Sample.NetCore // 濡傛灉鍖呭惈涓枃鏃讹紝浣跨敤kaiti瀛椾綋锛屽惁鍒欐枃瀛椾贡鐮 if (options.CaptchaType.ContainsChinese()) { - options.ImageOption.FontFamily = DefaultFontFamilys.Instance.Kaiti; + options.ImageOption.FontFamily = DefaultFontFamilies.Instance.Kaiti; options.ImageOption.FontSize = 24; } else { - options.ImageOption.FontFamily = DefaultFontFamilys.Instance.Actionj; + options.ImageOption.FontFamily = DefaultFontFamilies.Instance.Actionj; } // 鍔ㄩ潤闅忔満 diff --git a/Sample.Winfrom/OptionProviders/FontFamilyOptionProvider.cs b/Sample.Winfrom/OptionProviders/FontFamilyOptionProvider.cs index 5ef5c48..c883fd1 100644 --- a/Sample.Winfrom/OptionProviders/FontFamilyOptionProvider.cs +++ b/Sample.Winfrom/OptionProviders/FontFamilyOptionProvider.cs @@ -14,17 +14,17 @@ namespace Sample.Winfrom.OptionProviders { return new List { - new FontFamilyOption("Actionj", DefaultFontFamilys.Instance.Actionj), - new FontFamilyOption("Kaiti", DefaultFontFamilys.Instance.Kaiti), - new FontFamilyOption("Fresnel", DefaultFontFamilys.Instance.Fresnel), - new FontFamilyOption("Prefix", DefaultFontFamilys.Instance.Prefix), - new FontFamilyOption("Ransom", DefaultFontFamilys.Instance.Ransom), - new FontFamilyOption("Scandal", DefaultFontFamilys.Instance.Scandal), - new FontFamilyOption("Epilog", DefaultFontFamilys.Instance.Epilog), - new FontFamilyOption("Headache", DefaultFontFamilys.Instance.Headache), - new FontFamilyOption("Lexo", DefaultFontFamilys.Instance.Lexo), - new FontFamilyOption("Progbot", DefaultFontFamilys.Instance.Progbot), - new FontFamilyOption("Robot", DefaultFontFamilys.Instance.Robot), + new FontFamilyOption("Actionj", DefaultFontFamilies.Instance.Actionj), + new FontFamilyOption("Kaiti", DefaultFontFamilies.Instance.Kaiti), + new FontFamilyOption("Fresnel", DefaultFontFamilies.Instance.Fresnel), + new FontFamilyOption("Prefix", DefaultFontFamilies.Instance.Prefix), + new FontFamilyOption("Ransom", DefaultFontFamilies.Instance.Ransom), + new FontFamilyOption("Scandal", DefaultFontFamilies.Instance.Scandal), + new FontFamilyOption("Epilog", DefaultFontFamilies.Instance.Epilog), + new FontFamilyOption("Headache", DefaultFontFamilies.Instance.Headache), + new FontFamilyOption("Lexo", DefaultFontFamilies.Instance.Lexo), + new FontFamilyOption("Progbot", DefaultFontFamilies.Instance.Progbot), + new FontFamilyOption("Robot", DefaultFontFamilies.Instance.Robot), }; } } -- Gitee From e7956526b8d784dd1d98fe61dc95bd3d4984b12c Mon Sep 17 00:00:00 2001 From: "Mr.Null" Date: Sun, 27 Jul 2025 18:03:42 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E4=B9=B1=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lazy.Captcha.Core/DefaultCaptcha.cs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Lazy.Captcha.Core/DefaultCaptcha.cs b/Lazy.Captcha.Core/DefaultCaptcha.cs index 4c9e28b..75cd77b 100644 --- a/Lazy.Captcha.Core/DefaultCaptcha.cs +++ b/Lazy.Captcha.Core/DefaultCaptcha.cs @@ -31,35 +31,37 @@ namespace Lazy.Captcha.Core _captchaImageGenerator = new DefaultCaptchaImageGenerator(); } - // 选锟斤拷锟斤拷锟 + /// + /// 鏇存柊楠岃瘉鐮侀夐」 + /// + /// 楠岃瘉鐮佺敓鎴愰夐」 protected virtual void ChangeOptions(CaptchaOptions options) { - } /// - /// 锟斤拷锟斤拷锟斤拷证锟斤拷 + /// 鐢熸垚楠岃瘉鐮 /// - /// 锟斤拷证锟斤拷id - /// 锟斤拷锟斤拷时锟戒,未锟借定锟斤拷使锟斤拷锟斤拷锟斤拷时锟斤拷 + /// 楠岃瘉鐮乮d + /// 缂撳瓨鏃堕棿锛屾湭璁惧畾鍒欎娇鐢ㄩ厤缃椂闂 /// public virtual CaptchaData Generate(string captchaId, int? expirySeconds = null) { var (renderText, code) = _captchaCodeGenerator.Generate(_options.CodeLength); var image = _captchaImageGenerator.Generate(renderText, _options.ImageOption); - expirySeconds = expirySeconds.HasValue ? expirySeconds.Value : _options.ExpirySeconds; + expirySeconds ??= _options.ExpirySeconds; _storage.Set(captchaId, code, DateTime.Now.AddSeconds(expirySeconds.Value).ToUniversalTime()); return new CaptchaData(captchaId, code, image); } /// - /// 校锟斤拷 + /// 鏍¢獙 /// - /// 锟斤拷证锟斤拷id - /// 锟矫伙拷锟斤拷锟斤拷锟斤拷锟街わ拷锟 - /// 校锟斤拷晒锟绞憋拷欠锟斤拷瞥锟斤拷锟斤拷锟(锟斤拷锟节讹拷锟斤拷锟街) - /// 校锟斤拷失锟斤拷时锟角凤拷锟狡筹拷锟斤拷锟斤拷 + /// 楠岃瘉鐮乮d + /// 鐢ㄦ埛杈撳叆鐨勯獙璇佺爜 + /// 鏍¢獙鎴愬姛鏃舵槸鍚︾Щ闄ょ紦瀛(鐢ㄤ簬澶氭楠岃瘉) + /// 鏍¢獙澶辫触鏃舵槸鍚︾Щ闄 /// public virtual bool Validate(string captchaId, string code, bool removeIfSuccess = true, bool removeIfFail = true) { -- Gitee