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/Fuwuhao/FuwuhaoService.cs similarity index 99% rename from Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FuwuhaoService.cs rename to Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/Fuwuhao/FuwuhaoService.cs index 160f3fab..874688a1 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/Fuwuhao/FuwuhaoService.cs @@ -1,5 +1,4 @@ using System.Text; -using System.Text.Json; using System.Xml.Serialization; using Medallion.Threading; using Microsoft.AspNetCore.Http; @@ -18,7 +17,7 @@ using Yi.Framework.Rbac.Application.Contracts.Dtos.Account; using Yi.Framework.Rbac.Application.Contracts.IServices; using Yi.Framework.SqlSugarCore.Abstractions; -namespace Yi.Framework.AiHub.Application.Services; +namespace Yi.Framework.AiHub.Application.Services.Fuwuhao; /// /// 服务号服务 diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs index 1d4f8d5b..e1e80a86 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs @@ -224,18 +224,25 @@ public class PayService : ApplicationService, IPayService // 如果是尊享包商品,计算折扣 if (goodsType.IsPremiumPackage()) { - discountDescription = "累计充值每10元可减2.5元,最多减50元"; - if ( CurrentUser.IsAuthenticated) + + + if (CurrentUser.IsAuthenticated) { discountAmount = goodsType.CalculateDiscount(totalRechargeAmount); actualPrice = goodsType.GetDiscountedPrice(totalRechargeAmount); - if (discountAmount > 0) { discountDescription = $"根据累积充值已优惠 ¥{discountAmount:F2}"; } + else + { + discountDescription = $"累积充值过低,暂无优惠"; + } + } + else + { + discountDescription = $"登录后查看优惠"; } - } var goodsItem = new GoodsListOutput @@ -255,7 +262,7 @@ public class PayService : ApplicationService, IPayService return goodsList; } - + /// /// 获取交易状态描述 @@ -280,6 +287,7 @@ public class PayService : ApplicationService, IPayService { return result; } + return TradeStatusEnum.WAIT_TRADE; } -} +} \ No newline at end of file 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 e733a6ba..60fef2a9 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 @@ -19,6 +19,7 @@ public class FuwuhaoManager : DomainService private IDistributedCache _accessTokenCache; private ISqlSugarRepository _userRepository; private readonly ILogger _logger; + public FuwuhaoManager(IOptions options, IHttpClientFactory httpClientFactory, ISqlSugarRepository userRepository, IDistributedCache accessTokenCache, ILogger logger) @@ -49,6 +50,11 @@ public class FuwuhaoManager : DomainService { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower }); + if (result is null || string.IsNullOrEmpty(result.AccessToken)) + { + throw new UserFriendlyException("微信服务号AccessToken为空"); + } + return result; }, () => new DistributedCacheEntryOptions() { @@ -107,7 +113,7 @@ public class FuwuhaoManager : DomainService response.EnsureSuccessStatusCode(); var jsonContent = await response.Content.ReadAsStringAsync(); - + _logger.LogInformation($"服务号code获取用户基础信息:{jsonContent}"); var result = JsonSerializer.Deserialize(jsonContent); @@ -175,7 +181,8 @@ public class FuwuhaoManager : DomainService /// 图文消息标题 /// 图文消息描述 /// XML格式的图文消息体 - public string BuildRegisterMessage(string toUser, string title="意社区点击一键注册账号", string description="来自意社区SSO统一注册安全中心") + public string BuildRegisterMessage(string toUser, string title = "意社区点击一键注册账号", + string description = "来自意社区SSO统一注册安全中心") { var createTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); var fromUser = _options.FromUser; @@ -207,7 +214,8 @@ public class FuwuhaoManager : DomainService /// /// /// - public async Task<(SceneResultEnum SceneResult,Guid? UserId)> 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 +224,12 @@ public class FuwuhaoManager : DomainService //有openid,说明登录成功 if (aiUserInfo is not null) { - return (SceneResultEnum.Login,aiUserInfo.UserId); + return (SceneResultEnum.Login, aiUserInfo.UserId); } //无openid,说明需要进行注册 else { - return (SceneResultEnum.Register,null); + return (SceneResultEnum.Register, null); } break; @@ -240,7 +248,7 @@ public class FuwuhaoManager : DomainService //说明没有绑定过,直接绑定 await _userRepository.InsertAsync(new AiUserExtraInfoEntity(bindUserId.Value, openId)); - return (SceneResultEnum.Bind,bindUserId); + return (SceneResultEnum.Bind, bindUserId); break; default: throw new ArgumentOutOfRangeException(nameof(sceneType), sceneType, null);