fix: 优化服务号与支付逻辑,增加AccessToken为空校验及优惠描述完善
This commit is contained in:
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 服务号服务
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取交易状态描述
|
||||
@@ -280,6 +287,7 @@ public class PayService : ApplicationService, IPayService
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return TradeStatusEnum.WAIT_TRADE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public class FuwuhaoManager : DomainService
|
||||
private IDistributedCache<AccessTokenResponse> _accessTokenCache;
|
||||
private ISqlSugarRepository<AiUserExtraInfoEntity> _userRepository;
|
||||
private readonly ILogger<FuwuhaoManager> _logger;
|
||||
|
||||
public FuwuhaoManager(IOptions<FuwuhaoOptions> options, IHttpClientFactory httpClientFactory,
|
||||
ISqlSugarRepository<AiUserExtraInfoEntity> userRepository,
|
||||
IDistributedCache<AccessTokenResponse> accessTokenCache, ILogger<FuwuhaoManager> 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<UserBaseInfoResponse>(jsonContent);
|
||||
|
||||
@@ -175,7 +181,8 @@ public class FuwuhaoManager : DomainService
|
||||
/// <param name="title">图文消息标题</param>
|
||||
/// <param name="description">图文消息描述</param>
|
||||
/// <returns>XML格式的图文消息体</returns>
|
||||
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
|
||||
/// <param name="openId"></param>
|
||||
/// <param name="bindUserId"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user