CSharp-Single-EFCore/Bunny.WebApi/Config/PluginConfig.cs

34 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Lazy.Captcha.Core;
using Lazy.Captcha.Core.Generator;
using SkiaSharp;
namespace Bunny.WebApi.Config;
public static class PluginConfig
{
public static void AddCaptcha(this WebApplicationBuilder builder)
{
var service = builder.Services;
// 使用图形验证码
service.AddDistributedMemoryCache();
// 验证码相关配置内容
service.AddCaptcha(options =>
{
options.CaptchaType = CaptchaType.DEFAULT; // 验证码类型
options.CodeLength = 4; // 验证码长度
options.ExpirySeconds = 60; // 过期时间(单位/秒)
options.IgnoreCase = true; // 比较忽略大小写
options.ImageOption.Animation = true; // 是否启用动画
options.ImageOption.Width = 130; // 验证码宽度
options.ImageOption.Height = 48; // 验证码高度
options.ImageOption.BackgroundColor = SKColors.White;
options.ImageOption.BubbleCount = 6; // 气泡数量
options.ImageOption.BubbleMinRadius = 2; // 气泡最小半径
options.ImageOption.BubbleMaxRadius = 6; // 气泡最大半径
options.ImageOption.BubbleThickness = 2; // 气泡边沿厚度
options.ImageOption.InterferenceLineCount = 2; // 干扰线数量
options.ImageOption.FontSize = 36; // 字体大小
options.ImageOption.FontFamily = DefaultFontFamilys.Instance.Kaiti; // 字体中文使用kaiti其他字符可根据喜好设置
});
}
}