基于 e签宝开放平台 API 实现,采用 Content-MD5 + HMAC-SHA256 请求签名机制。
包信息
- NuGet 包:
Bitzsoft.Integrations.ElectronicSignature.ESign - 接口:
IElectronicSignatureProvider - 鉴权:Content-MD5 + HMAC-SHA256(AppId / AppSecret)
- Provider ID:
ESign
配置
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
AppId | string | 是 | — | 应用 AppId |
AppSecret | string | 是 | — | 应用 AppSecret(参与 HMAC-SHA256 签名,不传输) |
BaseUrl | string | 否 | https://openapi.esign.cn | API 基地址(沙箱 https://smlopenapi.esign.cn) |
Timeout | TimeSpan | 否 | 00:00:30 | HTTP 请求超时 |
HttpClientName | string | 否 | ESignElectronicSignatureProvider | Typed Client 注册名称(仅供接口兼容) |
{ "ESign": { "AppId": "your-app-id", "AppSecret": "your-app-secret", "BaseUrl": "https://openapi.esign.cn", "Timeout": "00:00:30" }}注册
using Bitzsoft.Integrations.ElectronicSignature.ESign;
// 方式一:IConfiguration(默认读取 "ESign" 配置节)services.AddBitzsoftESignElectronicSignature(configuration);
// 方式二:委托配置services.AddBitzsoftESignElectronicSignature(options =>{ options.AppId = "your-app-id"; options.AppSecret = "your-app-secret"; options.BaseUrl = "https://openapi.esign.cn";});使用示例
var createResult = await provider.CreateContractAsync(new SimpleContractRequest{ Title = "劳动合同", FileName = "contract.pdf", FileData = await File.ReadAllBytesAsync("contract.pdf"), SignerName = "李四", SignerPhone = "13900000000"});
var contractId = createResult.Data!;var status = await provider.GetSigningStatusAsync(contractId);var seals = await provider.ListSealsAsync();鉴权机制
- 请求签名:对请求体计算 MD5,再与 AppSecret、时间戳等参数拼接后做 HMAC-SHA256。
ESignHttpClient以 Typed Client 模式注册,HttpClientName属性仅供接口兼容,不参与实际注册。
已知限制
统一接口覆盖极简签署场景。多签署方、审批流程等高级功能通过 partial class 扩展方法调用。