后端【新增】新增商家转账功能后台处理及接口回调获取。

This commit is contained in:
jianweie code
2025-07-29 00:51:57 +08:00
parent 596225acb1
commit c8b4bbd78d
38 changed files with 3385 additions and 436 deletions

View File

@@ -0,0 +1,79 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using Microsoft.Extensions.Options;
using SKIT.FlurlHttpClient.Wechat.TenpayV3;
namespace CoreCms.Net.Services
{
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
/// <summary>
/// 微信支付链接管理器实现
/// </summary>
internal partial class WechatTenpayClientFactory : IWechatTenpayClientFactory
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly IWeChatPayConfigServices _weChatPayConfigServices;
private readonly ICoreCmsWeChatPayPlatformCertificateServices _weChatPayPlatformCertificateServices;
public WechatTenpayClientFactory(IHttpClientFactory httpClientFactory, IWeChatPayConfigServices weChatPayConfigServices, ICoreCmsWeChatPayPlatformCertificateServices weChatPayPlatformCertificateServices)
{
_httpClientFactory = httpClientFactory;
_weChatPayConfigServices = weChatPayConfigServices;
_weChatPayPlatformCertificateServices = weChatPayPlatformCertificateServices;
}
public async Task<WechatTenpayClient> Create(string merchantId)
{
var tenpayMerchantOptions = await _weChatPayConfigServices.QueryByClauseAsync(p => p.mchId == merchantId && p.isDefault == true && p.isEnable == true);
if (tenpayMerchantOptions == null)
{
throw new Exception("未在配置项中找到该 MerchantId 对应的微信商户号。");
}
var wechatTenpayClientOptions = new WechatTenpayClientOptions()
{
MerchantId = tenpayMerchantOptions.mchId,
MerchantV3Secret = tenpayMerchantOptions.apiV3Key,
MerchantCertificateSerialNumber = tenpayMerchantOptions.certificateSerialNumber,
MerchantCertificatePrivateKey = tenpayMerchantOptions.certificatePrivateKey,
AutoEncryptRequestSensitiveProperty = true,
AutoDecryptResponseSensitiveProperty = false,
};
// 基于平台证书的认证方式还需设置以下参数:
if (tenpayMerchantOptions.payType == (int)GlobalEnumVars.WeChatPayIdentityVerificationMethods.PlatformCertificate)
{
wechatTenpayClientOptions.PlatformAuthScheme = PlatformAuthScheme.Certificate;
var certificate = await _weChatPayPlatformCertificateServices.QueryByClauseAsync(p => p.merchantId == tenpayMerchantOptions.mchId);
if (certificate != null)
{
var entity = new CertificateEntry(certificate.algorithmType, certificate.serialNumber, certificate.certificate, certificate.effectiveTime, certificate.expireTime);
wechatTenpayClientOptions.PlatformCertificateManager.AddEntry(entity);
}
}
// 基于平台公钥的认证方式还需设置以下参数:
if (tenpayMerchantOptions.payType == (int)GlobalEnumVars.WeChatPayIdentityVerificationMethods.PlatformPublicKey)
{
wechatTenpayClientOptions.PlatformAuthScheme = PlatformAuthScheme.PublicKey;
wechatTenpayClientOptions.PlatformPublicKeyManager.AddEntry(
new PublicKeyEntry(
PublicKeyEntry.ALGORITHM_TYPE_RSA,
tenpayMerchantOptions.platformPublicKeyId!,
tenpayMerchantOptions.platformPublicKey!)
);
}
var wechatTenpayClient = WechatTenpayClientBuilder.Create(wechatTenpayClientOptions).Build();
return wechatTenpayClient;
}
}
}