Bitzsoft.Integrations.Payment.Alipay 1.0.1

dotnet add package Bitzsoft.Integrations.Payment.Alipay --version 1.0.1
                    
NuGet\Install-Package Bitzsoft.Integrations.Payment.Alipay -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.Alipay" 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.Alipay" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Payment.Alipay" />
                    
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.Alipay --version 1.0.1
                    
#r "nuget: Bitzsoft.Integrations.Payment.Alipay, 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.Alipay@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.Alipay&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Payment.Alipay&version=1.0.1
                    
Install as a Cake Tool

Bitzsoft.Integrations.Payment.Alipay

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

功能特性

  • 多场景下单:APP 支付、电脑网站支付(Page)、手机网站支付(H5/WAP)、扫码当面付(Precreate)
  • 交易管理:订单状态查询、关闭订单、申请退款
  • 回调验签:异步通知使用支付宝公钥 RSA2 验签,解析交易状态与金额
  • RSA2 签名:请求使用应用私钥 SHA256WithRSA 签名(PEM 格式,PKCS#1 / PKCS#8 均可)
  • 统一接口:实现 IPaymentProviderCode 返回 PaymentProviderCode.Alipay
  • 请求审计:内置 RequestLogging 管道,记录出站请求

安装

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

配置

appsettings.json

{
  "Alipay": {
    "AppId": "your-app-id",
    "AppPrivateKey": "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----",
    "AlipayPublicKey": "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----",
    "Gateway": "https://openapi.alipay.com/gateway.do",
    "NotifyUrl": "https://your-domain.com/callback/alipay",
    "SignType": "RSA2"
  }
}
配置项 说明 必填 默认值
AppId 支付宝应用 AppId -
AppPrivateKey 应用私钥(PEM 格式,请求签名用,须脱敏) -
AlipayPublicKey 支付宝公钥(PEM 格式,回调验签用) -
Gateway 网关地址(正式 / 沙箱) https://openapi.alipay.com/gateway.do
NotifyUrl 异步通知回调地址 -
SignType 签名算法(RSA2RSA RSA2
Timeout HTTP 请求超时 30s
HttpClientName 命名 HttpClient 标识 AlipayPaymentProvider

注册服务

从 IConfiguration 绑定(推荐)

using Microsoft.Extensions.DependencyInjection;

builder.Services.AddBitzsoftAlipayPayment(
    builder.Configuration.GetSection("Alipay"));

委托配置

builder.Services.AddBitzsoftAlipayPayment(options =>
{
    options.AppId = "your-app-id";
    options.AppPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----";
    options.AlipayPublicKey = "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----";
    options.NotifyUrl = "https://your-domain.com/callback/alipay";
});

注册后 IPaymentProviderCode = alipay)可用,可通过 IIntegrationProviderResolver<IPaymentProvider> 按供应商 ID 解析。

使用示例

using Bitzsoft.Integrations.Core;
using Bitzsoft.Integrations.Payment;

public class CheckoutService(IIntegrationProviderResolver<IPaymentProvider> resolver)
{
    public async Task<string> CreateQrOrderAsync(string outTradeNo, long amountCents, string subject, CancellationToken ct)
    {
        var provider = resolver.GetRequired(PaymentProviderCode.Alipay);

        // 扫码当面付下单
        var order = await provider.CreateOrderAsync(new PaymentOrderRequest
        {
            OutTradeNo = outTradeNo,
            TotalAmount = amountCents,   // 单位:分
            Subject = subject,
            Scene = PaymentScene.Code     // 扫码预下单
        }, ct);

        return order.IsSuccess ? order.Data!.QrCode! : throw new Exception(order.ErrorMessage);
    }

    public async Task<PaymentStatus> QueryAsync(string outTradeNo, CancellationToken ct)
    {
        var provider = resolver.GetRequired(PaymentProviderCode.Alipay);
        var status = await provider.QueryStatusAsync(outTradeNo, ct);
        return status.IsSuccess ? status.Data!.Status : PaymentStatus.Pending;
    }
}
IPaymentProvider 方法 支付宝接口
CreateOrderAsync alipay.trade.app.pay / page.pay / wap.pay / precreate
QueryStatusAsync alipay.trade.query
CloseOrderAsync alipay.trade.close
RefundAsync alipay.trade.refund
VerifyCallbackAsync 解析回调表单参数,用支付宝公钥验签

金额单位:统一接口与支付宝均以「分」为单位,内部按需换算为元字符串。

依赖

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

相关包

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.Alipay:

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 0 8/3/2026
1.0.0 33 8/2/2026
1.0.0-alpha.10 49 7/26/2026
1.0.0-alpha.9 388 7/12/2026