Bitzsoft.Integrations.Payment.UnionPay 1.0.1

dotnet add package Bitzsoft.Integrations.Payment.UnionPay --version 1.0.1
                    
NuGet\Install-Package Bitzsoft.Integrations.Payment.UnionPay -Version 1.0.1
                    
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.Payment.UnionPay" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.Payment.UnionPay" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Payment.UnionPay" />
                    
Project file
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.Payment.UnionPay --version 1.0.1
                    
#r "nuget: Bitzsoft.Integrations.Payment.UnionPay, 1.0.1"
                    
#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.Payment.UnionPay@1.0.1
                    
#: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.Payment.UnionPay&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Payment.UnionPay&version=1.0.1
                    
Install as a Cake Tool

Bitzsoft.Integrations.Payment.UnionPay

银联支付服务实现,实现 IPaymentProvider 统一接口。

功能特性

  • 银联网关对接:基于银联在线支付网关(表单 POST + RSA SHA256 证书签名),覆盖下单、查单、关单、退款全流程
  • RSA SHA256 证书签名:商户签名证书(.pfx)由银联开发者中心签发,按字典序拼接字段以 SHA256withRSA 计算签名
  • 前台跳转支付:下单返回前台跳转支付链接,适合 Web / H5 场景
  • 回调验签:解析回调表单参数,用商户证书公钥验签
  • 沙箱自动切换UseSandboxtrue 时基地址自动切换为 sandbox
  • 请求审计:内置 RequestLogging 管道,记录出站请求

安装

dotnet add package Bitzsoft.Integrations.Payment.UnionPay
<PackageReference Include="Bitzsoft.Integrations.Payment.UnionPay" Version="1.0.0" />

配置

appsettings.json

{
  "UnionPay": {
    "MerId": "your-mer-id",
    "CertPath": "/path/to/your.pfx",
    "CertPassword": "your-cert-password",
    "UseSandbox": true
  }
}
配置项 说明 必填 默认值
MerId 商户号 -
CertPath 商户签名证书路径(.pfx) -
CertPassword 证书保护口令 -
PlatformCertPath 银联平台验签证书路径,回调验签必需 -
SignMethod 签名算法(银联约定 01 表示 SHA256withRSA) 01
BaseUrl 网关基地址(UseSandboxtrue 时自动切换为 sandbox 地址) https://gateway.95516.com
UseSandbox 是否使用沙箱环境 false
HttpClientName 业务 HttpClient 命名 UnionPayPaymentProvider
Timeout HTTP 请求超时时间 30s

注册服务

从 IConfiguration 绑定(推荐)

using Microsoft.Extensions.DependencyInjection;

builder.Services.AddUnionPayPayment(
    builder.Configuration.GetSection("UnionPay"));

委托配置

builder.Services.AddUnionPayPayment(options =>
{
    options.MerId = "your-mer-id";
    options.CertPath = "/path/to/your.pfx";
    options.CertPassword = "your-cert-password";
    options.UseSandbox = true;
});

使用示例

注入 IPaymentProvider 调用

using Bitzsoft.Integrations.Payment;

public class OrderService(IPaymentProvider payment)
{
    public async Task<string> CreatePaymentAsync(string outTradeNo, long amountCents, string subject)
    {
        var result = await payment.CreateOrderAsync(new PaymentOrderRequest
        {
            OutTradeNo = outTradeNo,
            Subject = subject,
            TotalAmount = amountCents,
            Currency = "CNY",
            Scene = PaymentScene.Web
        });

        if (!result.IsSuccess)
            throw new PaymentException(payment.Code, result.ErrorCode, result.ErrorMessage);

        return result.Data!.PayUrl!;
    }

    public async Task<bool> IsPaidAsync(string outTradeNo)
    {
        var result = await payment.QueryStatusAsync(outTradeNo);
        return result.IsSuccess && result.Data!.Status == PaymentStatus.Success;
    }
}

接口映射

IPaymentProvider 方法 银联端点
CreateOrderAsync POST /gateway/api/frontTransReq(前台跳转支付)
QueryStatusAsync POST /gateway/api/querySingle
CloseOrderAsync POST /gateway/api/closeOrder(先查询 queryId 再撤销)
RefundAsync POST /gateway/api/refund(先查询 queryId 再退款)
VerifyCallbackAsync 解析回调表单参数,用银联平台证书公钥验签(必须配置 PlatformCertPath 指向银联平台证书,否则回调验签一律拒绝)

金额单位:统一接口与银联均以「分」为单位,无需换算。

依赖

说明
Bitzsoft.Integrations.Payment 抽象层(IPaymentProvider 接口 / 模型)
Bitzsoft.Integrations.RequestLogging 出站请求审计
Bitzsoft.Integrations.Compatibility 基础工具库
Microsoft.Extensions.Http IHttpClientFactory
Microsoft.Extensions.Options.ConfigurationExtensions Options 配置绑定
Microsoft.Extensions.Logging.Abstractions 日志抽象

相关包

供应商 包名
统一抽象 Bitzsoft.Integrations.Payment
支付宝 Bitzsoft.Integrations.Payment.Alipay
微信支付 Bitzsoft.Integrations.Payment.WeChatPay
Stripe Bitzsoft.Integrations.Payment.Stripe
PayPal Bitzsoft.Integrations.Payment.PayPal
银联 Bitzsoft.Integrations.Payment.UnionPay
聚合包 Bitzsoft.Integrations.Payment.All
Product 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.Payment.UnionPay:

Package Downloads
Bitzsoft.Integrations.Payment.All

支付聚合包 — 包含支付宝 / 微信支付 / Stripe / PayPal / 银联 全部实现

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 37 8/3/2026
1.0.0 40 8/2/2026