Merge pull request 'main' (#7) from Admin.NET/Admin.NET.Pro:main into main

Reviewed-on: http://101.43.53.74:3000/shuerchoi/Admin.NET.Pro/pulls/7
This commit is contained in:
shuerchoi 2024-07-23 11:31:26 +08:00
commit ea07a0216c
5 changed files with 47 additions and 30 deletions

View File

@ -38,7 +38,7 @@
<PackageReference Include="SqlSugarCore" Version="5.1.4.166" />
<PackageReference Include="SSH.NET" Version="2024.1.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.3" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1051" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1052" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
</ItemGroup>

View File

@ -40,7 +40,7 @@ public class DictAttribute : ValidationAttribute, ITransient
// 是否忽略空字符串
if (AllowEmptyStrings && string.IsNullOrEmpty(valueAsString)) return ValidationResult.Success;
var sysDictDataServiceProvider = validationContext.GetRequiredService<SysDictDataService>();
var sysDictDataServiceProvider = App.GetRequiredService<SysDictDataService>();
var dictDataList = sysDictDataServiceProvider.GetDataList(DictTypeCode).Result;
// 使用HashSet来提高查找效率

View File

@ -1,4 +1,4 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
@ -35,10 +35,7 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable
private RedisStream<string> _queueBroadcast;
/// <summary>
/// 路由键
/// </summary>
private readonly string _routeKey;
private ILogger<RedisEventSourceStorer> _logger;
/// <summary>
/// 构造函数
@ -48,6 +45,8 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable
/// <param name="capacity">存储器最多能够处理多少消息,超过该容量进入等待写入</param>
public RedisEventSourceStorer(ICacheProvider cacheProvider, string routeKey, int capacity)
{
_logger = App.GetRequiredService<ILogger<RedisEventSourceStorer>>();
// 配置通道,设置超出默认容量后进入等待
var boundedChannelOptions = new BoundedChannelOptions(capacity)
{
@ -58,7 +57,6 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable
_channel = Channel.CreateBounded<IEventSource>(boundedChannelOptions);
//_redis = redis as FullRedis;
_routeKey = routeKey;
// 创建广播消息订阅者即所有服务器节点都能收到消息用来发布重启、Reload配置等消息
FullRedis redis = (FullRedis)cacheProvider.Cache;
@ -73,23 +71,29 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable
_eventConsumer = new EventConsumer<ChannelEventSource>(_queueSingle);
// 订阅消息写入 Channel
_eventConsumer.Received += (send, cr) =>
_eventConsumer.Received += async (send, cr) =>
{
// var oriColor = Console.ForegroundColor;
try
{
var oriColor = Console.ForegroundColor;
ChannelEventSource ces = (ChannelEventSource)cr;
ConsumeChannelEventSource(ces);
await ConsumeChannelEventSourceAsync(ces, ces.CancellationToken);
}
catch (Exception e)
{
_logger.LogError(e, "处理Received中的消息产生错误");
}
};
_eventConsumer.Start();
}
private Task OnConsumeBroadcast(string source, Message message, CancellationToken token)
private async Task OnConsumeBroadcast(string source, Message message, CancellationToken token)
{
ChannelEventSource ces = JsonConvert.DeserializeObject<ChannelEventSource>(source);
ConsumeChannelEventSource(ces);
return Task.CompletedTask;
await ConsumeChannelEventSourceAsync(ces, token);
}
private void ConsumeChannelEventSource(ChannelEventSource ces)
private async Task ConsumeChannelEventSourceAsync(ChannelEventSource ces, CancellationToken cancel = default)
{
// 打印测试事件
if (ces.EventId != null && ces.EventId.IndexOf(":Test") > 0)
@ -99,7 +103,7 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable
Console.WriteLine($"有消息要处理{ces.EventId},{ces.Payload}");
Console.ForegroundColor = oriColor;
}
_channel.Writer.WriteAsync(ces);
await _channel.Writer.WriteAsync(ces, cancel);
}
/// <summary>

View File

@ -91,6 +91,8 @@ public class SysCommonService : IDynamicApiController, ITransient
// 接口分组/控制器信息
var controllerActionDescriptor = action.ActionDescriptor as ControllerActionDescriptor;
if (controllerActionDescriptor == null)
continue;
var apiDescription = controllerActionDescriptor.ControllerTypeInfo.GetCustomAttribute<ApiDescriptionSettingsAttribute>(true);
var controllerName = controllerActionDescriptor.ControllerName;
if (!apiOuput.Children.Exists(u => u.Name == controllerName))

View File

@ -19,10 +19,10 @@ public class SysWechatPayService : IDynamicApiController, ITransient
private readonly WechatTenpayClient _wechatTenpayClient;
public SysWechatPayService(SqlSugarRepository<SysWechatPay> sysWechatPayRep
, SqlSugarRepository<SysWechatRefund> sysWechatRefundRep
, IOptions<WechatPayOptions> wechatPayOptions
, IOptions<PayCallBackOptions> payCallBackOptions)
public SysWechatPayService(SqlSugarRepository<SysWechatPay> sysWechatPayRep,
SqlSugarRepository<SysWechatRefund> sysWechatRefundRep,
IOptions<WechatPayOptions> wechatPayOptions,
IOptions<PayCallBackOptions> payCallBackOptions)
{
_sysWechatPayRep = sysWechatPayRep;
this._sysWechatRefundRep = sysWechatRefundRep;
@ -40,6 +40,9 @@ public class SysWechatPayService : IDynamicApiController, ITransient
{
var cerFilePath = App.WebHostEnvironment.ContentRootPath + _wechatPayOptions.MerchantCertificatePrivateKey;
if (!File.Exists(cerFilePath))
Log.Warning("商户证书文件不存在:" + cerFilePath);
var tenpayClientOptions = new WechatTenpayClientOptions()
{
MerchantId = _wechatPayOptions.MerchantId,
@ -353,6 +356,12 @@ public class SysWechatPayService : IDynamicApiController, ITransient
[DisplayName("微信支付订单号查询(校正)")]
public async Task<WechatPayOutput> GetPayTransactionByIdAsync(string transactionId)
{
if (string.IsNullOrEmpty(transactionId))
throw Oops.Oh("TransactionId 不能为空");
if (string.IsNullOrEmpty(_wechatPayOptions.MerchantId) || string.IsNullOrEmpty(_wechatPayOptions.MerchantCertificateSerialNumber))
throw Oops.Oh("商户号或证书序列号不能为空,请检查支付配置");
var request = new GetPayTransactionByIdRequest()
{
MerchantId = _wechatPayOptions.MerchantId,
@ -360,21 +369,18 @@ public class SysWechatPayService : IDynamicApiController, ITransient
WechatpayCertificateSerialNumber = _wechatPayOptions.MerchantCertificateSerialNumber
};
var response = await _wechatTenpayClient.ExecuteGetPayTransactionByIdAsync(request);
if (response.TradeState == "SUCCESS")
if (response.TradeState == "SUCCESS" || response.TradeState == "CLOSED")
{
// 修正订单支付状态
var wechatPay = await _sysWechatPayRep.GetFirstAsync(u => u.TransactionId == transactionId && u.MerchantId == request.MerchantId);
var wechatPay = await _sysWechatPayRep.GetFirstAsync(u => u.TransactionId == request.TransactionId && u.MerchantId == request.MerchantId);
if (wechatPay != null && string.IsNullOrEmpty(wechatPay.TradeState))
{
wechatPay.TransactionId = response.TransactionId; // 支付订单号
wechatPay.TradeType = response.TradeType; // 交易类型
wechatPay.TradeState = response.TradeState; // 交易状态
wechatPay.TradeStateDescription = response.TradeStateDescription; // 交易状态描述
wechatPay.BankType = response.BankType; // 付款银行类型
wechatPay.Total = response.Amount.Total; // 订单总金额
wechatPay.PayerTotal = response.Amount.PayerTotal; // 用户支付金额
wechatPay.PayerTotal = response.Amount?.PayerTotal; // 用户支付金额
wechatPay.SuccessTime = response.SuccessTime; // 支付完成时间
await _sysWechatPayRep.AsUpdateable(wechatPay).IgnoreColumns(true).ExecuteCommandAsync();
return wechatPay.Adapt<WechatPayOutput>();
}
@ -391,6 +397,12 @@ public class SysWechatPayService : IDynamicApiController, ITransient
[DisplayName("微信商户订单号查询(校正)")]
public async Task<WechatPayOutput> GetPayTransactionByOutTradeNumberAsync(string outTradeNumber)
{
if (string.IsNullOrEmpty(outTradeNumber))
throw Oops.Oh("商户订单号(OutTradeNumber)不能为空");
if (string.IsNullOrEmpty(_wechatPayOptions.MerchantId) || string.IsNullOrEmpty(_wechatPayOptions.MerchantCertificateSerialNumber))
throw Oops.Oh("商户号或证书序列号不能为空,请检查支付配置");
var request = new GetPayTransactionByOutTradeNumberRequest()
{
MerchantId = _wechatPayOptions.MerchantId,
@ -398,7 +410,7 @@ public class SysWechatPayService : IDynamicApiController, ITransient
WechatpayCertificateSerialNumber = _wechatPayOptions.MerchantCertificateSerialNumber
};
var response = await _wechatTenpayClient.ExecuteGetPayTransactionByOutTradeNumberAsync(request);
if (response.TradeState == "SUCCESS")
if (response.TradeState == "SUCCESS" || response.TradeState == "CLOSED")
{
// 修正订单支付状态
var wechatPay = await _sysWechatPayRep.GetFirstAsync(u => u.OutTradeNumber == outTradeNumber && u.MerchantId == request.MerchantId);
@ -409,8 +421,7 @@ public class SysWechatPayService : IDynamicApiController, ITransient
wechatPay.TradeState = response.TradeState; // 交易状态
wechatPay.TradeStateDescription = response.TradeStateDescription; // 交易状态描述
wechatPay.BankType = response.BankType; // 付款银行类型
wechatPay.Total = response.Amount.Total; // 订单总金额
wechatPay.PayerTotal = response.Amount.PayerTotal; // 用户支付金额
wechatPay.PayerTotal = response.Amount?.PayerTotal; // 用户支付金额
wechatPay.SuccessTime = response.SuccessTime; // 支付完成时间
await _sysWechatPayRep.AsUpdateable(wechatPay).IgnoreColumns(true).ExecuteCommandAsync();
return wechatPay.Adapt<WechatPayOutput>();