Bitzsoft.Integrations.Captcha.Geetest
1.0.4
dotnet add package Bitzsoft.Integrations.Captcha.Geetest --version 1.0.4
NuGet\Install-Package Bitzsoft.Integrations.Captcha.Geetest -Version 1.0.4
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.Geetest" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.Captcha.Geetest" Version="1.0.4" />
<PackageReference Include="Bitzsoft.Integrations.Captcha.Geetest" />
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.Geetest --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bitzsoft.Integrations.Captcha.Geetest, 1.0.4"
#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.Geetest@1.0.4
#: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.Geetest&version=1.0.4
#tool nuget:?package=Bitzsoft.Integrations.Captcha.Geetest&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bitzsoft.Integrations.Captcha.Geetest
极验 GeeTest v4 验证码实现包 -- 前端 gt.js 自渲染 + 服务端 /validate 二次校验。
功能特性
- 无感验证:前端 gt.js SDK 自渲染,验证通过后回传
lot_number+captcha_output+pass_token+gen_time - 服务端二次校验:后端用
CaptchaKey计算sign_token(HMAC-SHA256),调极验/validate接口校验 - v4 签名:内置 GeeTest v4
sign_token生成(HMAC-SHA256),无需引入极验 SDK - 零厂商 SDK 依赖:裸 HttpClient 直调 REST API
- 请求审计:内置 RequestLogging 管道
- 构造校验:
CaptchaId/CaptchaKey缺失时构造即失败(fail-fast)
安装
dotnet add package Bitzsoft.Integrations.Captcha.Geetest
<PackageReference Include="Bitzsoft.Integrations.Captcha.Geetest" Version="1.0.0" />
配置
appsettings.json
{
"Captcha": {
"Geetest": {
"CaptchaId": "your-captcha-id",
"CaptchaKey": "your-captcha-key",
"ApiServer": "gcaptcha4.geetest.com"
}
}
}
| 配置项 | 说明 | 必填 | 默认值 |
|---|---|---|---|
CaptchaId |
验证码 CaptchaId(前端 + 后端均用) | 是 | - |
CaptchaKey |
验证码 CaptchaKey(服务端签名密钥,须脱敏) | 是 | - |
ApiServer |
API 服务端点 | 否 | gcaptcha4.geetest.com |
ScriptUrl |
前端 SDK 脚本地址 | 否 | 极验 CDN |
Timeout |
HTTP 超时 | 否 | 30s |
HttpClientName |
命名 HttpClient 标识 | 否 | GeetestCaptchaProvider |
注册服务
从 IConfiguration 绑定(推荐)
using Microsoft.Extensions.DependencyInjection;
builder.Services.AddBitzsoftGeetestCaptcha(
builder.Configuration.GetSection("Captcha:Geetest"));
委托配置
builder.Services.AddBitzsoftGeetestCaptcha(options =>
{
options.CaptchaId = "your-captcha-id";
options.CaptchaKey = "your-captcha-key";
});
使用示例
生成前端 SDK 凭证
var provider = factory.GetProvider(CaptchaProviderCode.Geetest);
var result = await provider.GenerateAsync(new CaptchaGenerateRequest { Type = CaptchaType.Intelligent });
// result.Data.AppId → CaptchaId,前端 gt.js 初始化用
前端加载 gt4.js,用 CaptchaId 初始化,验证通过后拿到 lot_number + captcha_output + pass_token + gen_time。
服务端校验
[HttpPost("captcha/verify")]
public async Task<IActionResult> Verify([FromBody] VerifyDto dto)
{
var provider = factory.GetProvider(CaptchaProviderCode.Geetest);
var result = await provider.VerifyAsync(new CaptchaVerifyRequest
{
LotNumber = dto.LotNumber, // 前端回传
CaptchaOutput = dto.CaptchaOutput, // 前端回传
PassToken = dto.PassToken, // 前端回传
GenTime = dto.GenTime // 前端回传
});
if (result.IsSuccess && result.Data!.Passed)
return Ok();
return BadRequest(result.ErrorMessage);
}
Token字段作为LotNumber的兼容入口:若LotNumber为空则回退取Token。
响应解析
result 字段:success 校验通过,其余失败。score(0~100)部分场景返回。失败时 ErrorCode 形如 VERIFY_fail。
请求审计
services.AddRequestLogging<MyRequestLogStore>(opts =>
{
opts.SensitiveFields.Add("CaptchaKey");
});
services.AddBitzsoftGeetestCaptcha(builder.Configuration.GetSection("Captcha:Geetest"));
安全说明
- CaptchaKey:服务端签名密钥,通过环境变量注入,禁止硬编码;务必加入 RequestLogging 脱敏字段
- 验证数据一次性:
lot_number+captcha_output等校验后即失效
依赖
| 包 | 说明 |
|---|---|
Bitzsoft.Integrations.Captcha |
抽象层(接口 / 模型) |
Bitzsoft.Integrations.Compatibility |
基础工具库 |
Bitzsoft.Integrations.RequestLogging |
出站请求审计 |
Microsoft.Extensions.Http |
IHttpClientFactory |
Microsoft.Extensions.Options.ConfigurationExtensions |
Options 配置绑定 |
Microsoft.Extensions.Logging.Abstractions |
日志抽象 |
相关包
- Bitzsoft.Integrations.Captcha -- 抽象层
- Bitzsoft.Integrations.Captcha.Aliyun -- 阿里云验证码 2.0 实现
- Bitzsoft.Integrations.Captcha.Tencent -- 腾讯天御实现
- Bitzsoft.Integrations.Captcha.All -- 聚合包
| 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.4)
- Bitzsoft.Integrations.Compatibility (>= 1.0.4)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.4)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
-
net5.0
- Bitzsoft.Integrations.Captcha (>= 1.0.4)
- Bitzsoft.Integrations.Compatibility (>= 1.0.4)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.4)
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Http (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
-
net8.0
- Bitzsoft.Integrations.Captcha (>= 1.0.4)
- Bitzsoft.Integrations.Compatibility (>= 1.0.4)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.4)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.Captcha.Geetest:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.Captcha.All
验证码聚合包 — 包含阿里云 / 腾讯天御 / 极验 GeeTest 全部实现 |
GitHub repositories
This package is not used by any popular GitHub repositories.