fix RedisHelper wxTokenKeyPrefix

This commit is contained in:
glz
2026-06-29 17:49:28 +08:00
parent 6b09006071
commit 2fcff63ee2
2 changed files with 10 additions and 5 deletions

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using QYZH.InteractiveMagazine.Infrastructure.Auth;
using QYZH.InteractiveMagazine.Models.Settings;
using System.IdentityModel.Tokens.Jwt;
@ -60,7 +61,11 @@ public class JwtAutoRefreshMiddleware
{
return;
}
var wxUserId = jwtToken.Claims.FirstOrDefault(c => c.Type == JwtHelper.WxUserIdClaimType)?.Value;
if (string.IsNullOrEmpty(wxUserId))
{
return;
}
var jwtSettings = _configuration.GetSection("JwtSettings").Get<JwtSettings>();
if (jwtSettings == null || jwtSettings.ExpiryMinutes <= 0)
{
@ -68,7 +73,7 @@ public class JwtAutoRefreshMiddleware
}
// 每次请求都刷新 Redis 中 Token 的过期时间
await RefreshRedisTokenExpiryAsync(userId, token, jwtSettings.ExpiryMinutes);
await RefreshRedisTokenExpiryAsync(wxUserId,userId, token, jwtSettings.ExpiryMinutes);
}
catch
{
@ -79,7 +84,7 @@ public class JwtAutoRefreshMiddleware
/// <summary>
/// 刷新 Redis 中已存在 Token 的过期时间(保持会话活跃)
/// </summary>
private async Task RefreshRedisTokenExpiryAsync(string userId, string currentToken, int expiryMinutes)
private async Task RefreshRedisTokenExpiryAsync(string wxUserId,string userId, string currentToken, int expiryMinutes)
{
// 检查 Admin Token
var adminTokenKey = $"{AdminTokenKeyPrefix}:{userId}";
@ -91,7 +96,7 @@ public class JwtAutoRefreshMiddleware
}
// 检查 WeChat Token
var wechatTokenKey = $"{WeChatTokenKeyPrefix}:{userId}";
var wechatTokenKey = $"{WeChatTokenKeyPrefix}:{wxUserId}{userId}";
var wechatToken = await RedisHelper.GetAsync(wechatTokenKey);
if (!string.IsNullOrEmpty(wechatToken))
{