Skip to content
Bitzsoft.Integrationsbitzsoft.integrations

Reference

银联 Payment

银联在线支付服务——RSA SHA256 证书签名。

Last updated

基于银联在线支付网关(95516)实现,采用 RSA SHA256 证书签名机制。

包信息

  • NuGet 包:Bitzsoft.Integrations.Payment.UnionPay
  • 接口:IPaymentProvider
  • 鉴权:RSA SHA256 证书签名
  • Provider ID:unionpay

配置

字段类型必填默认值说明
MerIdstring商户号
CertPathstring商户签名证书路径(.pfx)
CertPasswordstring商户签名证书密码
SignMethodstring01签名算法(01 = SHA256withRSA)
BaseUrlstringhttps://gateway.95516.com支付网关基地址(沙箱自动切换 https://gateway.test.95516.com
UseSandboxboolfalse是否使用 sandbox 沙箱环境
HttpClientNamestringUnionPayPaymentProvider业务 HttpClient 命名
TimeoutTimeSpan00:00:30HTTP 请求超时
{
"UnionPay": {
"MerId": "your-mer-id",
"CertPath": "/path/to/your-cert.pfx",
"CertPassword": "your-cert-password",
"SignMethod": "01",
"UseSandbox": false
}
}

注册

// 方式一:IConfiguration(默认读取 "UnionPay" 配置节)
services.AddUnionPayPayment(configuration);
// 方式二:委托配置
services.AddUnionPayPayment(options =>
{
options.MerId = "your-mer-id";
options.CertPath = "/path/to/your-cert.pfx";
options.CertPassword = "your-cert-password";
options.UseSandbox = false;
});

使用示例

var orderResult = await provider.CreateOrderAsync(new PaymentOrderRequest
{
OutTradeNo = "ORDER_20260801_005",
Subject = "银联商品订单",
TotalAmount = 599.00m,
Scene = PaymentScene.Web
});
// 查询状态
var status = await provider.QueryStatusAsync("ORDER_20260801_005");
// 退款
var refundResult = await provider.RefundAsync(new RefundRequest
{
OutTradeNo = "ORDER_20260801_005",
RefundAmount = 599.00m,
RefundNo = "REFUND_004"
});

鉴权机制

  • 请求签名:加载 pfx 证书(CertPath + CertPassword),使用证书中的 RSA 私钥对请求参数做 SHA256withRSA 签名。
  • 回调验签:使用银联公钥验证回调签名。

已知限制

UseSandbox 为 true 时,若 BaseUrl 仍为默认值则自动切换到沙箱地址。证书文件必须为 .pfx 格式。统一接口覆盖标准支付场景,复杂业务通过 partial class 扩展。

100%

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