NexusContract.Providers.Alipay
1.0.0-preview.19
This is a prerelease version of NexusContract.Providers.Alipay.
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package NexusContract.Providers.Alipay --version 1.0.0-preview.19
NuGet\Install-Package NexusContract.Providers.Alipay -Version 1.0.0-preview.19
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="NexusContract.Providers.Alipay" Version="1.0.0-preview.19" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NexusContract.Providers.Alipay" Version="1.0.0-preview.19" />
<PackageReference Include="NexusContract.Providers.Alipay" />
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 NexusContract.Providers.Alipay --version 1.0.0-preview.19
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NexusContract.Providers.Alipay, 1.0.0-preview.19"
#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 NexusContract.Providers.Alipay@1.0.0-preview.19
#: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=NexusContract.Providers.Alipay&version=1.0.0-preview.19&prerelease
#tool nuget:?package=NexusContract.Providers.Alipay&version=1.0.0-preview.19&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
支付宝提供商 - 开箱即用的支付宝 OpenAPI v3 集成
📦 这个包包含什么?
完整的支付宝 Provider 实现:
- AlipayProvider: 支付宝网关集成(RSA2 签名、OpenAPI v3)
- AlipayProviderConfig: 配置模型(AppId, 私钥, 公钥等)
- DI 扩展:
AddAlipayProvider()- 一行代码完成注册
🎯 适用场景
- ✅ 支付宝当面付 (扫码、刷卡、声波)
- ✅ 支付宝线上支付 (APP、Web、H5)
- ✅ 支付宝交易管理 (查询、退款、关闭)
🚀 快速开始
安装
dotnet add package NexusContract.Providers.Alipay
HttpApi 集成(推荐)
using NexusContract.Abstractions.Configuration;
using NexusContract.Core;
using NexusContract.Core.Engine;
using NexusContract.Providers.Alipay;
using NexusContract.Providers.Alipay.ServiceConfiguration;
using NexusContract.Hosting.Yarp;
var builder = WebApplication.CreateBuilder(args);
// 配置传输层(HTTP/2 + 重试 + 熔断)
builder.Services.AddNexusYarpTransport();
// 配置 Provider
builder.Services.AddAlipayProvider(new AlipayProviderConfig
{
AppId = "2021xxx",
MerchantId = "2088xxx",
PrivateKey = "MIIEvQIBA...",
AlipayPublicKey = "MIIBIjANBgkqh...",
ApiGateway = new Uri("https://openapi.alipay.com/"),
UseSandbox = false
});
// 注册配置解析器(示例:内存实现)
builder.Services.AddSingleton<IConfigurationResolver>(sp =>
new NexusContract.Core.Configuration.InMemoryConfigResolver());
// 注册引擎并挂载 Provider 适配器
builder.Services.AddSingleton<INexusEngine>(sp =>
{
var transport = sp.GetRequiredService<INexusTransport>();
var gateway = new NexusGateway(new SnakeCaseNamingPolicy());
var engine = new NexusEngine(sp.GetRequiredService<IConfigurationResolver>());
engine.RegisterProvider("Alipay", new AlipayProviderAdapter(transport, gateway));
return engine;
});
var app = builder.Build();
app.MapNexusEndpoints("/v3");
app.Run();
定义契约(放在独立的 Contract 项目中)
using NexusContract.Abstractions.Attributes;
using NexusContract.Abstractions.Contracts;
[ApiOperation("alipay.trade.pay", HttpVerb.POST)]
public class TradePayRequest : IApiRequest<TradePayResponse>
{
[ApiField("out_trade_no", IsRequired = true)]
public string MerchantOrderNo { get; set; }
[ApiField("total_amount", IsRequired = true)]
public decimal TotalAmount { get; set; }
[ApiField("subject", IsRequired = true)]
public string Subject { get; set; }
[ApiField("scene", IsRequired = true)]
public string Scene { get; set; } // bar_code, qr_code
}
直接调用 Provider(非 Hosting)
var gateway = new NexusGateway(new SnakeCaseNamingPolicy());
var provider = new AlipayProvider(alipayConfig, gateway, transport);
var resp = await provider.ExecuteAsync(new TradePayRequest
{
MerchantOrderNo = "202501...",
TotalAmount = 100.00m,
Subject = "测试订单",
Scene = "bar_code"
});
🔐 安全特性
- RSA2 签名: 所有请求自动签名,所有响应自动验签
- 密钥隔离: 私钥仅用于签名,公钥仅用于验签
- HTTPS 强制: 生产环境强制 HTTPS
📚 支持的接口
- ✅
alipay.trade.pay- 统一收单交易支付 - ✅
alipay.trade.create- 统一收单交易创建 - ✅
alipay.trade.query- 统一收单交易查询 - ✅
alipay.trade.refund- 统一收单交易退款 - ✅
alipay.trade.close- 统一收单交易关闭 - ✅
alipay.trade.precreate- 统一收单线下交易预创建
🔗 相关包
- NexusContract.Core - 核心引擎(必需依赖)
- NexusContract.Abstractions - 基础抽象(传递依赖)
📖 完整示例
- Contract 定义: examples/Demo.Alipay.Contract
- Endpoint 实现: examples/Demo.Alipay.HttpApi
📄 许可
MIT License - 查看 LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Http (>= 10.0.0)
- NexusContract.Abstractions (>= 1.0.0-preview.19)
- NexusContract.Core (>= 1.0.0-preview.19)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|
Initial preview with full Alipay OpenAPI v3 support and RSA2 signing.