From 83a08a9f1649342cce4281a5f85b2eaae60aebac Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期一, 24 三月 2025 19:14:49 +0800 Subject: [PATCH] 修改 code缓存时间 --- LifePayment/LifePayment.Application/User/AccountService.cs | 48 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 37 insertions(+), 11 deletions(-) diff --git a/LifePayment/LifePayment.Application/User/AccountService.cs b/LifePayment/LifePayment.Application/User/AccountService.cs index 0837679..f0af87b 100644 --- a/LifePayment/LifePayment.Application/User/AccountService.cs +++ b/LifePayment/LifePayment.Application/User/AccountService.cs @@ -11,11 +11,13 @@ using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Services; +using Volo.Abp.Caching; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity; using Volo.Abp.Identity.Application.Contracts.Account; using Volo.Abp.IdentityModel; using ZeroD.Util; +using ZeroD.Util.Fadd; using static LifePayment.Domain.Shared.LifePaymentConstant; @@ -30,6 +32,8 @@ private readonly IRepository<User, Guid> _userRepository; private readonly IRepository<UserChannle, Guid> _userChannleRep; private readonly IIdentityUserAppService _identityUserService; + private readonly IDistributedCache<string> _distributedCache; + public AccountService( IWxManager wxManager, @@ -38,7 +42,8 @@ IRepository<User, Guid> userRepository, IIdentityUserAppService identityUserService, IRepository<LifePayUser, Guid> lifePayUserRepository, - IRepository<UserChannle, Guid> userChannleRep) + IRepository<UserChannle, Guid> userChannleRep, + IDistributedCache<string> distributedCache) { _configuration = configuration; _wxManager = wxManager; @@ -47,19 +52,38 @@ _authenticator = authenticator; _userRepository = userRepository; _userChannleRep = userChannleRep; + _distributedCache = distributedCache; } #region 鏌ヨ public async Task<WxMiniAppIndentityInfo> GetLifePayWxIndentity(string code) { - var res = await _wxManager.GetWxOauth2AccessToken(code); - var result = new WxMiniAppIndentityInfo + var cacheData = await _distributedCache.GetAsync(code); + var result = new WxMiniAppIndentityInfo(); + if (cacheData != null) { - SessionKey = res.SessionKey, - OpenId = res.OpenId, - UnionId = res.UnionId - }; + result.OpenId = cacheData; + } + else + { + var res = await _wxManager.GetWxOauth2AccessToken(code); + result = new WxMiniAppIndentityInfo + { + SessionKey = res.SessionKey, + OpenId = res.OpenId, + UnionId = res.UnionId + }; + if (!string.IsNullOrEmpty(res.OpenId)) + { + await _distributedCache.SetAsync(code, res.OpenId, options: new Microsoft.Extensions.Caching.Distributed.DistributedCacheEntryOptions() + { + AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(24) + }); + } + + } + return result; } @@ -129,12 +153,12 @@ var user = await _userRepository.Where(r => r.UserName == accessRequestDto.UserName && !r.IsDeleted).FirstOrDefaultAsync(); // 璁板綍鏃ュ織 - // await PublishUserOperateHistoryEvent(LogsSpecies.Login, LogsSpecies.Login, user.Id, user.Id, creatorName: user.Name); + // await PublishUserOperateHistoryEvent(LogsSpecies.Login, LogsSpecies.Login, user.Id, user.Id, creatorName: user.Name); return result; } - public async Task<Guid> CreateAccount(CreateAccountInput input, bool isSend, bool isAdminCreate = false, string password = null) + public async Task<Guid> CreateAccount(CreateAccountInput input, bool isSend, bool isAdminCreate = false) { if (input.ClientId == LifePaymentConstant.ClientId.Back) { @@ -146,8 +170,10 @@ CheckExtensions.IfTrueThrowUserFriendlyException(any, CustomeErrorMessage.PhoneNumberRepeatSaveFail); - password ??= GlobalRandom.GetRandomPassword(); + /// input.Password ??= GlobalRandom.GetRandomPassword(); + CheckExtensions.IfTrueThrowUserFriendlyException(string.IsNullOrEmpty(input.Password), + "璇疯緭鍏ュ瘑鐮�"); var res = await _identityUserService.CreateAsync(new IdentityUserCreateDto { Name = input.Name, @@ -155,7 +181,7 @@ UserName = input.UserName, RoleNames = input.RoleNames, ClientId = input.ClientId, - Password = password, + Password = input.Password, }); var user = await _userRepository.InsertAsync(new User { -- Gitblit v1.9.1