From 469279cdbbfcebb15d9b1c2c9c2b7bc6210041ba Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期一, 09 六月 2025 17:10:02 +0800 Subject: [PATCH] feat:每隔10分钟定时查询15分钟内的未支付订单向微信API获取最新信息若为支付成功则更改订单状态 --- LifePayment/LifePayment.Worker/LifePaymentServicesWorkModule.cs | 1 LifePayment/LifePayment.Worker/LifePayment.Worker.csproj | 15 +++++++ LifePayment/LifePayment.Worker/Worker/CheckUnPayOrderWork.cs | 87 +++++++++++++++++++++++++++++++++++++++++++ LifePayment/LifePayment.Worker/appsettings.json | 5 +- LifePayment/LifePayment.Application/LifePay/LifePayService.cs | 1 5 files changed, 105 insertions(+), 4 deletions(-) diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs index 7d0e1f1..69f1df1 100644 --- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs +++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs @@ -99,7 +99,6 @@ #region 鏌ヨ - /// <summary> /// 鑾峰彇鐢佃垂闈㈠�� /// </summary> diff --git a/LifePayment/LifePayment.Worker/LifePayment.Worker.csproj b/LifePayment/LifePayment.Worker/LifePayment.Worker.csproj index dee56af..e6e6a62 100644 --- a/LifePayment/LifePayment.Worker/LifePayment.Worker.csproj +++ b/LifePayment/LifePayment.Worker/LifePayment.Worker.csproj @@ -38,4 +38,19 @@ <ProjectReference Include="..\LifePayment.EntityFrameworkCore\LifePayment.EntityFrameworkCore.csproj" /> </ItemGroup> + <ItemGroup> + <None Update="Cert\alipayCertPublicKey_RSA2.crt"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Update="Cert\alipayRootCert.crt"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Update="Cert\appCertPublicKey_2021004171602214.crt"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Update="Cert\CSR鏂囦欢.csr"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + </ItemGroup> + </Project> diff --git a/LifePayment/LifePayment.Worker/LifePaymentServicesWorkModule.cs b/LifePayment/LifePayment.Worker/LifePaymentServicesWorkModule.cs index efeef28..94062ab 100644 --- a/LifePayment/LifePayment.Worker/LifePaymentServicesWorkModule.cs +++ b/LifePayment/LifePayment.Worker/LifePaymentServicesWorkModule.cs @@ -52,6 +52,7 @@ public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) { await context.AddBackgroundWorkerAsync<GetStaticsWorker>(); + await context.AddBackgroundWorkerAsync<CheckUnPayOrderWork>(); } private void ConfigurePays(ServiceConfigurationContext context, IConfiguration configuration) diff --git a/LifePayment/LifePayment.Worker/Worker/CheckUnPayOrderWork.cs b/LifePayment/LifePayment.Worker/Worker/CheckUnPayOrderWork.cs new file mode 100644 index 0000000..085423f --- /dev/null +++ b/LifePayment/LifePayment.Worker/Worker/CheckUnPayOrderWork.cs @@ -0,0 +1,87 @@ +锘縰sing LifePayment.Application; +using LifePayment.Application.Contracts; +using LifePayment.Application.LifePay; +using LifePayment.Domain.Models; +using LifePayment.Domain.Shared; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Nest; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.BackgroundWorkers; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Threading; +using Volo.Abp.Uow; +using ZeroD.Util; + +namespace LifePayment.Worker.Worker +{ + public class CheckUnPayOrderWork : AsyncPeriodicBackgroundWorkerBase + { + private readonly int _doWorkHour = 0; + private readonly int _doWorkMinute = 1; + private readonly ILifePayOrderService lifePayOrderService; + private readonly ILifePayService lifePayService; + private readonly IRepository<LifePayOrder, Guid> lifePayOrderRepository; + + public CheckUnPayOrderWork( + AbpAsyncTimer timer, + IServiceScopeFactory serviceScopeFactory, + ILifePayOrderService lifePayOrderService, + ILifePayService lifePayService, + IRepository<LifePayOrder, Guid> lifePayOrderRepository) : base(timer, serviceScopeFactory) + { + timer.Period = (int)TimeSpan.FromMinutes(10).TotalMilliseconds; + this.lifePayOrderService = lifePayOrderService; + this.lifePayService = lifePayService; + this.lifePayOrderRepository = lifePayOrderRepository; + } + + [UnitOfWork] + protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) + { + try + { + Logger.LogInformation($"妫�鏌ユ湭鏀粯璁㈠崟鐘舵�佸紑濮�: {DateTime.Now}"); + var end = DateTime.Now; + var start = end.AddMinutes(-15); + var orderNos = lifePayOrderRepository.Where(it => it.PayStatus == LifePayStatusEnum.鏈敮浠� && it.CreationTime >= start && it.CreationTime <= end).Select(it => it.OrderNo).ToList(); + foreach (var orderNo in orderNos) + { + var wxPayNotice = await lifePayService.WxPayTradeQuery(orderNo); + var json = wxPayNotice.ToJson(); + Logger.LogInformation($"璁㈠崟锛坽wxPayNotice.OutTradeNo}锛変俊鎭�: {json}"); + if (wxPayNotice.OutTradeNo.Contains("JF") && wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.鏀粯鎴愬姛) + { + await lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId); + + // 鎻掑叆鏀舵敮娴佹按 + await lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() + { + OrderNo = wxPayNotice.OutTradeNo, + OutOrderNo = wxPayNotice.TransactionId, + LifePayType = LifePayTypeEnum.WxPay, + ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, + Amount = wxPayNotice.Amount.Total + }); + + Logger.LogInformation("宸叉敼涓烘敮浠樻垚鍔�"); + } + else + { + Logger.LogInformation("鏈洿鏂�"); + } + } + } + catch (Exception ex) + { + Logger.LogError($"妫�鏌ユ湭鏀粯璁㈠崟鐘舵�佸彂鐢熷紓甯�: {DateTime.Now}" + ex.Message); + } + + + } + } +} diff --git a/LifePayment/LifePayment.Worker/appsettings.json b/LifePayment/LifePayment.Worker/appsettings.json index 93c551b..4beb47b 100644 --- a/LifePayment/LifePayment.Worker/appsettings.json +++ b/LifePayment/LifePayment.Worker/appsettings.json @@ -13,9 +13,8 @@ "OssUrl": "https://waterdroptest2.oss-cn-hangzhou.aliyuncs.com/" }, "ConnectionStrings": { - //"LifePayment": "Server=120.26.58.240; Database=Dev_12333; User=bole;Password=Blym123!@#$" - "AbpIdentity": "Server=120.26.58.240; Database=Dev_LifePaymentIdentity; User=bole;Password=Bole147258", - "LifePaymentServices": "Server=120.26.58.240; Database=Dev_LifePayment; User=bole;Password=Bole147258" + "LifePaymentServices": "Server=rm-bp1mt744021h1s6dg4o.sqlserver.rds.aliyuncs.com,2333;Database=Dev_LifePayment;Uid=bole;Pwd=Blcs20@%27;", + "AbpIdentity": "Server=rm-bp1mt744021h1s6dg4o.sqlserver.rds.aliyuncs.com,2333;Database=Dev_LifePaymentIdentity;Uid=bole;Pwd=Blcs20@%27;" }, "App": { "CorsOrigins": "http://localhost:31804" -- Gitblit v1.9.1