feat: 完成多模块功能迭代与优化

1.  新增宠物皮肤初始枚举值、下拉列表接口及相关DTO
2.  完善商品实体与DTO,新增虚拟商品标记和类型ID字段
3.  重构用户认证体系,支持多用户切换并重新生成JWT令牌
4.  新增签到配置管理全套功能,包括增删改查和状态管理
5.  优化模型验证过滤器和基础响应类的命名规范
6.  新增补签功能,完善签到服务逻辑
7.  拆分用户详情DTO,新增各子数据分页查询接口
8.  重构微信控制器的用户ID获取逻辑,统一使用激活用户ID
9.  修复背包服务中补签卡的扣减逻辑
10. 新增家长姓名修改接口和相关服务实现
This commit is contained in:
glz
2026-06-10 17:53:38 +08:00
parent 028e3dfb34
commit ae4cd627df
35 changed files with 1334 additions and 316 deletions

View File

@ -12,7 +12,7 @@ namespace QYZH.InteractiveMagazine.Infrastructure.Auth;
public static class JwtHelper
{
/// <summary>
/// 生成JWT令牌
/// 生成JWT令牌(管理端 / 单用户场景)
/// </summary>
/// <param name="userId">用户ID</param>
/// <param name="userName">用户名</param>
@ -29,6 +29,39 @@ public static class JwtHelper
new Claim(ClaimTypes.Name, userName)
};
return BuildToken(claims, settings);
}
/// <summary>
/// 生成JWT令牌小程序场景同时携带 WxUserId 和 UserId
/// </summary>
/// <param name="wxUserId">微信用户IDWxUser.Id</param>
/// <param name="userId">当前激活用户IDUsers.Id无用户时为 0</param>
/// <param name="userName">用户名</param>
/// <param name="settings">JWT配置</param>
/// <returns>JWT令牌字符串</returns>
public static string GenerateToken(long wxUserId, long userId, string userName, JwtSettings settings)
{
var claims = new[]
{
new Claim(JwtRegisteredClaimNames.Sub, userId.ToString()),
new Claim(JwtRegisteredClaimNames.Name, userName),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(ClaimTypes.NameIdentifier, userId.ToString()),
new Claim(ClaimTypes.Name, userName),
new Claim(WxUserIdClaimType, wxUserId.ToString())
};
return BuildToken(claims, settings);
}
/// <summary>
/// 自定义 Claim 类型WxUserId
/// </summary>
public const string WxUserIdClaimType = "WxUserId";
private static string BuildToken(Claim[] claims, JwtSettings settings)
{
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settings.SecretKey!));
var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
@ -77,6 +110,25 @@ public static class JwtHelper
return null;
}
/// <summary>
/// 从Token中获取微信用户IDWxUserId
/// </summary>
/// <param name="token">JWT令牌</param>
/// <returns>WxUserId</returns>
public static long? GetWxUserIdFromToken(string token)
{
var tokenHandler = new JwtSecurityTokenHandler();
if (tokenHandler.ReadToken(token) is JwtSecurityToken jwtToken)
{
var wxUserIdClaim = jwtToken.Claims.FirstOrDefault(c => c.Type == WxUserIdClaimType);
if (long.TryParse(wxUserIdClaim?.Value, out long wxUserId))
{
return wxUserId;
}
}
return null;
}
/// <summary>
/// 从Token中获取用户名
/// </summary>

View File

@ -24,10 +24,10 @@ public class ModelValidActionFilterAttribute : ActionFilterAttribute
errorDic.Add(key, errorStr);
}
}
var result = new BaseResponse<Dictionary<string, string>>() { Code = ResultCode.FAIL };
var result = new BaseResponse<Dictionary<string, string>>() { code = ResultCode.FAIL };
result.Message = string.Join("|", errorDic.Select(e => e.Value).Distinct());
result.Result = errorDic;
result.message = string.Join("|", errorDic.Select(e => e.Value).Distinct());
result.result = errorDic;
context.Result = new JsonResult(result);
}
}