Bitzsoft.Integrations.Payment.WeChatPay
1.0.1
dotnet add package Bitzsoft.Integrations.Payment.WeChatPay --version 1.0.1
NuGet\Install-Package Bitzsoft.Integrations.Payment.WeChatPay -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.WeChatPay" 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.WeChatPay" Version="1.0.1" />
<PackageReference Include="Bitzsoft.Integrations.Payment.WeChatPay" />
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.WeChatPay --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bitzsoft.Integrations.Payment.WeChatPay, 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.WeChatPay@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.WeChatPay&version=1.0.1
#tool nuget:?package=Bitzsoft.Integrations.Payment.WeChatPay&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bitzsoft.Integrations.Payment.WeChatPay
微信支付服务实现,实现 IPaymentProvider 统一接口。
功能特性
- 多场景下单:APP 支付、Native 扫码、H5 支付、付款码(当面付)
- 交易管理:订单状态查询、关闭订单、申请退款
- APIv3 安全:请求使用商户私钥 RSA-SHA256 签名 + 证书序列号头
- 回调验签解密:使用微信支付平台公钥 RSA-SHA256 验签,再用 APIv3Key 进行 AES-256-GCM 解密
- 统一接口:实现
IPaymentProvider,Code返回PaymentProviderCode.WeChatPay - 请求审计:内置 RequestLogging 管道,记录出站请求
安装
dotnet add package Bitzsoft.Integrations.Payment.WeChatPay
<PackageReference Include="Bitzsoft.Integrations.Payment.WeChatPay" Version="1.0.0" />
配置
appsettings.json
{
"WeChatPay": {
"AppId": "wx your-app-id",
"MchId": "your-mch-id",
"MchSerialNo": "your-merchant-cert-serial-no",
"APIv3Key": "your-32-byte-apiv3-key",
"PrivateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
"WeChatPayPublicKey": "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----",
"NotifyUrl": "https://your-domain.com/callback/wechatpay",
"ApiBase": "https://api.mch.weixin.qq.com"
}
}
| 配置项 | 说明 | 必填 | 默认值 |
|---|---|---|---|
AppId |
微信应用 AppId(公众号 / 小程序 / APP) | 是 | - |
MchId |
商户号 | 是 | - |
MchSerialNo |
商户证书序列号(请求签名头) | 是 | - |
APIv3Key |
APIv3 密钥(32 字节,回调解密用,须脱敏) | 是 | - |
PrivateKey |
商户 API 私钥(PEM 格式,请求签名用,须脱敏) | 是 | - |
WeChatPayPublicKey |
微信支付平台公钥(PEM 格式,回调验签用) | 是 | - |
NotifyUrl |
异步通知回调地址 | 否 | - |
ApiBase |
API 基地址 | 否 | https://api.mch.weixin.qq.com |
Timeout |
HTTP 请求超时 | 否 | 30s |
HttpClientName |
命名 HttpClient 标识 | 否 | WeChatPayPaymentProvider |
注册服务
从 IConfiguration 绑定(推荐)
using Microsoft.Extensions.DependencyInjection;
builder.Services.AddBitzsoftWeChatPayPayment(
builder.Configuration.GetSection("WeChatPay"));
委托配置
builder.Services.AddBitzsoftWeChatPayPayment(options =>
{
options.AppId = "wx your-app-id";
options.MchId = "your-mch-id";
options.MchSerialNo = "your-merchant-cert-serial-no";
options.APIv3Key = "your-32-byte-apiv3-key";
options.PrivateKey = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----";
options.WeChatPayPublicKey = "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----";
options.NotifyUrl = "https://your-domain.com/callback/wechatpay";
});
注册后
IPaymentProvider(Code = wechatpay)可用,可通过IIntegrationProviderResolver<IPaymentProvider>按供应商 ID 解析。
使用示例
using Bitzsoft.Integrations.Core;
using Bitzsoft.Integrations.Payment;
public class CheckoutService(IIntegrationProviderResolver<IPaymentProvider> resolver)
{
public async Task<string> CreateNativeOrderAsync(string outTradeNo, long amountCents, string description, CancellationToken ct)
{
var provider = resolver.GetRequired(PaymentProviderCode.WeChatPay);
// Native 扫码下单,返回 code_url
var order = await provider.CreateOrderAsync(new PaymentOrderRequest
{
OutTradeNo = outTradeNo,
TotalAmount = amountCents, // 单位:分
Subject = description,
Scene = PaymentScene.Web // Native 扫码
}, 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.WeChatPay);
var status = await provider.QueryStatusAsync(outTradeNo, ct);
return status.IsSuccess ? status.Data!.Status : PaymentStatus.Pending;
}
}
IPaymentProvider 方法 |
微信支付端点 |
|---|---|
CreateOrderAsync |
POST /v3/pay/transactions/app / native / h5 / codepayment |
QueryStatusAsync |
GET /v3/pay/transactions/out-trade-no/{out_trade_no} |
CloseOrderAsync |
POST /v3/pay/transactions/out-trade-no/{out_trade_no}/close |
RefundAsync |
POST /v3/refund/domestic/refunds |
VerifyCallbackAsync |
平台公钥验签 + APIv3Key AES-256-GCM 解密 |
金额单位:统一接口与微信支付均以「分」为单位,无需换算。
回调验签:含 5 分钟时间戳容差校验防重放。
依赖
| 包 | 说明 |
|---|---|
Bitzsoft.Integrations.Payment |
抽象层(IPaymentProvider / 模型) |
Bitzsoft.Integrations.Compatibility |
基础工具库 |
Bitzsoft.Integrations.RequestLogging |
出站请求审计 |
Microsoft.Extensions.Http |
IHttpClientFactory |
Microsoft.Extensions.Options.ConfigurationExtensions |
Options 配置绑定 |
Microsoft.Extensions.Logging.Abstractions |
日志抽象 |
相关包
- Bitzsoft.Integrations.Payment -- 抽象层
- Bitzsoft.Integrations.Payment.Alipay -- 支付宝实现
- Bitzsoft.Integrations.Payment.PayPal -- PayPal 实现
- Bitzsoft.Integrations.Payment.Stripe -- Stripe 实现
- Bitzsoft.Integrations.Payment.UnionPay -- 银联实现
- Bitzsoft.Integrations.Payment.All -- 聚合包
| Product | Versions 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.
-
net10.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.1)
- Bitzsoft.Integrations.Payment (>= 1.0.1)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
-
net5.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.1)
- Bitzsoft.Integrations.Payment (>= 1.0.1)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Http (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
-
net8.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.1)
- Bitzsoft.Integrations.Payment (>= 1.0.1)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.Payment.WeChatPay:
| 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 | 35 | 8/3/2026 |
| 1.0.0 | 38 | 8/2/2026 |
| 1.0.0-alpha.10 | 50 | 7/26/2026 |
| 1.0.0-alpha.9 | 404 | 7/12/2026 |