Bitzsoft.Integrations.Captcha.All
1.0.0-alpha.10
This is a prerelease version of Bitzsoft.Integrations.Captcha.All.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Bitzsoft.Integrations.Captcha.All --version 1.0.0-alpha.10
NuGet\Install-Package Bitzsoft.Integrations.Captcha.All -Version 1.0.0-alpha.10
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bitzsoft.Integrations.Captcha.All" Version="1.0.0-alpha.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.Captcha.All" Version="1.0.0-alpha.10" />
<PackageReference Include="Bitzsoft.Integrations.Captcha.All" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bitzsoft.Integrations.Captcha.All --version 1.0.0-alpha.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bitzsoft.Integrations.Captcha.All, 1.0.0-alpha.10"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bitzsoft.Integrations.Captcha.All@1.0.0-alpha.10
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitzsoft.Integrations.Captcha.All&version=1.0.0-alpha.10&prerelease
#tool nuget:?package=Bitzsoft.Integrations.Captcha.All&version=1.0.0-alpha.10&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bitzsoft.Integrations.Captcha.All
验证码聚合包 -- 一次引用即包含阿里云验证码 2.0 / 腾讯天御 / 极验 GeeTest v4 全部实现。
本包是元包(meta-package),本身不含代码,仅聚合传递引用三个厂商实现包 + 抽象层。
安装
dotnet add package Bitzsoft.Integrations.Captcha.All
<PackageReference Include="Bitzsoft.Integrations.Captcha.All" Version="1.0.0" />
安装后自动引入:
Bitzsoft.Integrations.Captcha-- 抽象层Bitzsoft.Integrations.Captcha.Aliyun-- 阿里云验证码 2.0Bitzsoft.Integrations.Captcha.Tencent-- 腾讯天御Bitzsoft.Integrations.Captcha.Geetest-- 极验 GeeTest v4
配置
appsettings.json -- 按需配置启用的厂商,未配置的厂商不会注册。
{
"Captcha": {
"Aliyun": {
"AccessKeyId": "your-access-key-id",
"AccessKeySecret": "your-access-key-secret",
"SceneId": "your-scene-id",
"AppKey": "your-app-key"
},
"Tencent": {
"SecretId": "your-tencent-secret-id",
"SecretKey": "your-tencent-secret-key",
"CaptchaAppId": 1234567,
"AppSecretKey": "your-captcha-app-secret-key"
},
"Geetest": {
"CaptchaId": "your-captcha-id",
"CaptchaKey": "your-captcha-key"
}
}
}
仅配置中存在的厂商节会被注册(
section.Exists()判定),无需删除不想用的厂商节以外的配置。
注册服务
using Microsoft.Extensions.DependencyInjection;
// 一行注册配置中存在的全部厂商 + 工厂
builder.Services.AddBitzsoftCaptchaAll(builder.Configuration.GetSection("Captcha"));
注册后以下服务均可用:
ICaptchaProvider(每个厂商各注册一个实例)ICaptchaProviderFactory(按编码解析)IIntegrationProviderResolver<ICaptchaProvider>(跨领域统一解析入口;Factory 委托给它)
使用示例
通过工厂按编码解析(推荐)
风控引擎等消费方通常按配置动态选择厂商:
public class CaptchaService(ICaptchaProviderFactory factory)
{
public async Task<bool> VerifyAsync(string providerCode, string token, string? userIp = null)
{
var provider = factory.GetProvider(providerCode); // "aliyun" / "tencent" / "geetest"
var result = await provider.VerifyAsync(new CaptchaVerifyRequest
{
Token = token,
RemoteIp = userIp
});
return result.IsSuccess && result.Data!.Passed;
}
public IEnumerable<string> ListProviders() => factory.GetRegisteredCodes();
}
生成前端 SDK 凭证
var provider = factory.GetProvider(CaptchaProviderCode.Aliyun);
var challenge = await provider.GenerateAsync(new CaptchaGenerateRequest
{
Type = CaptchaType.Intelligent,
Scene = "login"
});
// challenge.Data.ScriptUrl / AppId / SceneId 返回给前端初始化
降级到自有验证码
第三方不可用时 GenerateAsync / VerifyAsync 返回 Fail,宿主可回退自有实现(如 SVG 图形码):
var result = await provider.VerifyAsync(request);
if (!result.IsSuccess)
{
// 第三方不可用 → 回退自有验证码
return await FallbackToSvgCaptchaAsync(request);
}
请求审计
services.AddRequestLogging<MyRequestLogStore>(opts =>
{
opts.SensitiveFields.Add("AccessKeySecret");
opts.SensitiveFields.Add("SecretKey");
opts.SensitiveFields.Add("AppSecretKey"); // 腾讯随请求体传输,务必脱敏
opts.SensitiveFields.Add("CaptchaKey");
});
services.AddBitzsoftCaptchaAll(builder.Configuration.GetSection("Captcha"));
安全说明
- 密钥脱敏:所有厂商密钥字段均须加入 RequestLogging 脱敏配置,不落入审计日志
- 腾讯 AppSecretKey:随每个校验请求体明文传输(腾讯既定设计),务必脱敏
- fail-closed:阿里云响应异常时一律判失败
- token 一次性:三家厂商验证 token 校验后即失效
供应商编码对照表
| 编码 | 实现类 | 平台 |
|---|---|---|
aliyun |
AliyunCaptchaProvider |
阿里云验证码 2.0 |
tencent |
TencentCaptchaProvider |
腾讯天御验证码 |
geetest |
GeetestCaptchaProvider |
极验 GeeTest v4 |
相关包
- Bitzsoft.Integrations.Captcha -- 抽象层
- Bitzsoft.Integrations.Captcha.Aliyun -- 阿里云验证码 2.0 实现
- Bitzsoft.Integrations.Captcha.Tencent -- 腾讯天御实现
- Bitzsoft.Integrations.Captcha.Geetest -- 极验 GeeTest v4 实现
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Bitzsoft.Integrations.Captcha (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Captcha.Aliyun (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Captcha.Geetest (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Captcha.Tencent (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Compatibility (>= 1.0.0-alpha.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
-
net5.0
- Bitzsoft.Integrations.Captcha (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Captcha.Aliyun (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Captcha.Geetest (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Captcha.Tencent (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Compatibility (>= 1.0.0-alpha.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
-
net8.0
- Bitzsoft.Integrations.Captcha (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Captcha.Aliyun (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Captcha.Geetest (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Captcha.Tencent (>= 1.0.0-alpha.10)
- Bitzsoft.Integrations.Compatibility (>= 1.0.0-alpha.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.