CSharp-Single-EFCore/Bunny.WebApi/ReadMe.md

65 lines
2.1 KiB
Markdown
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.

## 后台服务设置
### Quartz写法
- 持久化存储生成数据SQL语句参考
- https://github.com/quartznet/quartznet/tree/main/database/tables
### 原生写法
- 设置每秒执行多少,设置后台服务,原生写法
```csharp
using Microsoft.Extensions.Hosting;
namespace Bunny.Service.BackgroundModule;
/// <summary>
/// 定时任务
/// </summary>
public class TemplateBackgroundModule : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
Console.WriteLine("TemplateService started");
await Task.Delay(1000, stoppingToken);
await Task.Run(() => { Console.WriteLine("执行了。。。"); }, stoppingToken);
await Task.Delay(1000, stoppingToken);
Console.WriteLine("--------------------------------");
}
}
}
```
## 验证码生成
- 验证码生成相关配置
```csharp
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其他字符可根据喜好设置
});
}
```