基于银联在线支付网关(95516)实现,采用 RSA SHA256 证书签名机制。
包信息
- NuGet 包:
Bitzsoft.Integrations.Payment.UnionPay - 接口:
IPaymentProvider - 鉴权:RSA SHA256 证书签名
- Provider ID:
unionpay
配置
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
MerId | string | 是 | — | 商户号 |
CertPath | string | 是 | — | 商户签名证书路径(.pfx) |
CertPassword | string | 是 | — | 商户签名证书密码 |
SignMethod | string | 否 | 01 | 签名算法(01 = SHA256withRSA) |
BaseUrl | string | 否 | https://gateway.95516.com | 支付网关基地址(沙箱自动切换 https://gateway.test.95516.com) |
UseSandbox | bool | 否 | false | 是否使用 sandbox 沙箱环境 |
HttpClientName | string | 否 | UnionPayPaymentProvider | 业务 HttpClient 命名 |
Timeout | TimeSpan | 否 | 00:00:30 | HTTP 请求超时 |
{ "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 扩展。