Skip to content
Bitzsoft.Integrationsbitzsoft.integrations

Reference

上上签 电子签章

上上签电子签章服务——OAuth2 + RSA256 请求签名。

Last updated

基于上上签开放平台 API 实现,采用 OAuth2 + RSA256 签名机制。

包信息

  • NuGet 包:Bitzsoft.Integrations.ElectronicSignature.BestSign
  • 接口:IElectronicSignatureProvider
  • 鉴权:OAuth2 + RSA256 签名(ClientId / PrivateKey)
  • Provider ID:BestSign

配置

字段类型必填默认值说明
ClientIdstringOAuth2 客户端标识
ClientSecretstringOAuth2 客户端密钥
DeveloperIdstring开发者标识
PrivateKeystring开发者 RSA 私钥(PKCS#8 PEM 格式,用于请求签名)
PublicKeystring平台 RSA 公钥(PKCS#8 PEM 格式,用于回调验签)
BaseUrlstringhttps://openapi.bestsign.cnAPI 基地址(测试 https://demotest.bestsign.cn
TimeoutTimeSpan00:00:30HTTP 请求超时
HttpClientNamestringBestSignElectronicSignatureProvider命名 HttpClient 标识
{
"BestSign": {
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"DeveloperId": "your-developer-id",
"PrivateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
"PublicKey": "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----",
"BaseUrl": "https://openapi.bestsign.cn"
}
}

注册

using Bitzsoft.Integrations.ElectronicSignature.BestSign;
// 方式一:IConfiguration(默认读取 "BestSign" 配置节)
services.AddBitzsoftBestSignElectronicSignature(configuration);
// 方式二:委托配置
services.AddBitzsoftBestSignElectronicSignature(options =>
{
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
options.DeveloperId = "your-developer-id";
options.PrivateKey = File.ReadAllText("private_key.pem");
options.PublicKey = File.ReadAllText("public_key.pem");
options.BaseUrl = "https://openapi.bestsign.cn";
});

使用示例

var createResult = await provider.CreateContractAsync(new SimpleContractRequest
{
Title = "合作协议",
FileName = "contract.pdf",
FileData = await File.ReadAllBytesAsync("contract.pdf"),
SignerName = "钱七",
SignerPhone = "13500000000"
});
var contractId = createResult.Data!;
var detail = await provider.GetContractDetailAsync(contractId);
var bytes = await provider.DownloadContractAsync(contractId);

鉴权机制

  • 请求签名:使用开发者 RSA 私钥对请求内容做 SHA256WithRSA 签名。
  • 回调验签:使用平台 RSA 公钥验证回调签名。

已知限制

私钥和公钥必须为 PKCS#8 PEM 格式。统一接口覆盖极简场景,复杂业务通过 partial class 扩展。

100%

滚轮或按钮缩放 · 放大后拖动画面 · 双击切换 100% / 200%