From d90e24f9ed0a7d517b4ac60ae871dcf6d1f4b304 Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Fri, 29 Aug 2025 21:55:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=8F=B7=E5=9B=9E=E8=B0=83=E5=A4=84=E7=90=86=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=94=A8=E6=88=B7ID=E5=8F=8A=E7=BC=93=E5=AD=98=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/FuwuhaoService.cs | 11 +++++++---- .../Managers/Fuwuhao/FuwuhaoManager.cs | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FuwuhaoService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FuwuhaoService.cs index 9cc4f7c6..fe746cfe 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FuwuhaoService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FuwuhaoService.cs @@ -112,14 +112,13 @@ public class FuwuhaoService : ApplicationService //根据操作类型,进行业务处理,返回处理结果,再写入缓存,10s过去,相当于用户10s扫完app后,轮询要在10秒内完成 var scenResult = await _fuwuhaoManager.CallBackHandlerAsync(cache.SceneType, body.FromUserName, cache.UserId); - cache.SceneResult = scenResult; - + cache.SceneResult = scenResult.SceneResult; + cache.UserId = scenResult.UserId; await _sceneCache.SetAsync($"{FuwuhaoConst.SceneCacheKey}{scene}", cache, new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(50) }); - //如果是注册,将OpenId与Scene进行绑定,代表用户有30分钟进行注册 - if (scenResult == SceneResultEnum.Register) + if (scenResult.SceneResult == SceneResultEnum.Register) { await _openIdToSceneCache.SetAsync($"{FuwuhaoConst.OpenIdToSceneCacheKey}{body.FromUserName}", scene, new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30) }); @@ -176,6 +175,10 @@ public class FuwuhaoService : ApplicationService switch (output.SceneResult) { case SceneResultEnum.Login: + if (cache.UserId is null) + { + throw new ApplicationException("获取用户id异常,请重试"); + } var loginInfo = await _accountService.PostLoginAsync(cache.UserId!.Value); output.Token = loginInfo.Token; output.RefreshToken = loginInfo.RefreshToken; diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/Fuwuhao/FuwuhaoManager.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/Fuwuhao/FuwuhaoManager.cs index d99af62d..b08e2a2b 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/Fuwuhao/FuwuhaoManager.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/Fuwuhao/FuwuhaoManager.cs @@ -207,7 +207,7 @@ public class FuwuhaoManager : DomainService /// /// /// - public async Task CallBackHandlerAsync(SceneTypeEnum sceneType, string openId, Guid? bindUserId) + public async Task<(SceneResultEnum SceneResult,Guid? UserId)> CallBackHandlerAsync(SceneTypeEnum sceneType, string openId, Guid? bindUserId) { var aiUserInfo = await _userRepository._DbQueryable.Where(x => x.FuwuhaoOpenId == openId).FirstAsync(); switch (sceneType) @@ -216,12 +216,12 @@ public class FuwuhaoManager : DomainService //有openid,说明登录成功 if (aiUserInfo is not null) { - return SceneResultEnum.Login; + return (SceneResultEnum.Login,aiUserInfo.UserId); } //无openid,说明需要进行注册 else { - return SceneResultEnum.Register; + return (SceneResultEnum.Register,null); } break; @@ -240,7 +240,7 @@ public class FuwuhaoManager : DomainService //说明没有绑定过,直接绑定 await _userRepository.InsertAsync(new AiUserExtraInfoEntity(bindUserId.Value, openId)); - return SceneResultEnum.Bind; + return (SceneResultEnum.Bind,null); break; default: throw new ArgumentOutOfRangeException(nameof(sceneType), sceneType, null);