From 089d7fe32312aea4d89c8f5339e9b361923a4731 Mon Sep 17 00:00:00 2001 From: zpc Date: Thu, 11 Sep 2025 18:08:57 +0800 Subject: [PATCH] 3213 --- CoreCms.Net.Auth/AuthorizationSetup.cs | 29 ++++++++++++++++++ .../AppSettingsConstVars.cs | 5 +++- .../Controllers/UserController.cs | 6 ++-- CoreCms.Net.Web.WebApi/Doc.xml | 30 +++++++++++++++++-- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/CoreCms.Net.Auth/AuthorizationSetup.cs b/CoreCms.Net.Auth/AuthorizationSetup.cs index 5e1f43a..f9a8d14 100644 --- a/CoreCms.Net.Auth/AuthorizationSetup.cs +++ b/CoreCms.Net.Auth/AuthorizationSetup.cs @@ -155,6 +155,35 @@ namespace CoreCms.Net.Auth var signingKey = new SymmetricSecurityKey(keyByteArray); var issuer = AppSettingsConstVars.JwtConfigIssuer; var audience = AppSettingsConstVars.JwtConfigAudience; + // 👇 下面是你应该添加的打印代码,用于调试 + Console.WriteLine("[JWT Debug] JwtConfigSecretKey 配置读取开始 ====================="); + + // 1. 打印密钥的长度(帮助判断是否为空或过短) + Console.WriteLine($"[JWT Debug] JwtConfigSecretKey 长度: {symmetricKeyAsBase64.Length}"); + + // 2. 打印密钥的前 5 个字符(避免泄露全部密钥,但可以用于对比) + if (!string.IsNullOrEmpty(symmetricKeyAsBase64) && symmetricKeyAsBase64.Length >= 5) + { + Console.WriteLine($"[JWT Debug] JwtConfigSecretKey 前5位: '{symmetricKeyAsBase64.Substring(0, 5)}...'"); + } + else + { + Console.WriteLine($"[JWT Debug] JwtConfigSecretKey 前5位: (太短或为空)"); + } + + // 3. 打印密钥的 SHA256 哈希值(可用于绝对安全地对比密钥是否一致,不会泄露原文) + try + { + var sha256Hash = System.Security.Cryptography.SHA256.HashData(keyByteArray); + var hashString = BitConverter.ToString(sha256Hash).Replace("-", "").ToLower(); + Console.WriteLine($"[JWT Debug] JwtConfigSecretKey SHA256 哈希值: {hashString},明文:{symmetricKeyAsBase64}"); + } + catch (Exception ex) + { + Console.WriteLine($"[JWT Debug] 计算密钥哈希时出错: {ex.Message}"); + } + + Console.WriteLine("[JWT Debug] JwtConfigSecretKey 配置读取结束 ====================="); var signingCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256); diff --git a/CoreCms.Net.Configuration/AppSettingsConstVars.cs b/CoreCms.Net.Configuration/AppSettingsConstVars.cs index 75ad825..e120aa5 100644 --- a/CoreCms.Net.Configuration/AppSettingsConstVars.cs +++ b/CoreCms.Net.Configuration/AppSettingsConstVars.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; + using SqlSugar.Extensions; namespace CoreCms.Net.Configuration @@ -63,8 +64,10 @@ namespace CoreCms.Net.Configuration #region Jwt授权配置================================================================================ - public static readonly string JwtConfigSecretKey = AppSettingsHelper.GetContent("JwtConfig", "SecretKey") + AppSettingsHelper.GetMachineRandomKey(DbSqlConnection + AppSettingsHelper.GetMACIp(true)); + public static readonly string JwtConfigSecretKey = !string.IsNullOrEmpty(AppSettingsHelper.GetContent("JwtConfig", "SecretKey")) ? AppSettingsHelper.GetContent("JwtConfig", "SecretKey") : AppSettingsHelper.GetMachineRandomKey(DbSqlConnection + AppSettingsHelper.GetMACIp(true)); + public static readonly string JwtConfigIssuer = !string.IsNullOrEmpty(AppSettingsHelper.GetContent("JwtConfig", "Issuer")) ? AppSettingsHelper.GetContent("JwtConfig", "Issuer") : AppSettingsHelper.GetHostName(); + public static readonly string JwtConfigAudience = AppSettingsHelper.GetContent("JwtConfig", "Audience"); #endregion diff --git a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs index 11ca8f9..a5caa17 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs @@ -49,6 +49,8 @@ using DotLiquid.Util; using System.IO; using System.Text.RegularExpressions; using CoreCms.Net.Model.ViewModels.User; +using CoreCms.Net.Repository.UnitOfWork; +using CoreCms.Net.IRepository.UnitOfWork; namespace CoreCms.Net.Web.WebApi.Controllers { @@ -125,7 +127,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers , ICoreCmsSettingServices settingServices , ICoreCmsServicesServices servicesServices , IOptions weChatOptions - , ICoreCmsUserServicesOrderServices userServicesOrderServices, ICoreCmsUserServicesTicketServices userServicesTicketServices, ICoreCmsStoreServices storeServices, ICoreCmsCouponServices couponServices, ICoreCmsOrderServices orderServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IToolsServices toolsServices, ICoreCmsUserBlacklistServices coreCmsUserBlacklistServices, SqlSugarScope dbBase) + , ICoreCmsUserServicesOrderServices userServicesOrderServices, ICoreCmsUserServicesTicketServices userServicesTicketServices, ICoreCmsStoreServices storeServices, ICoreCmsCouponServices couponServices, ICoreCmsOrderServices orderServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IToolsServices toolsServices, ICoreCmsUserBlacklistServices coreCmsUserBlacklistServices, IUnitOfWork unitOfWork) { _user = user; _userWeChatInfoServices = userWeChatInfoServices; @@ -160,7 +162,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers _weChatOptions = weChatOptions.Value; _toolsServices = toolsServices; _coreCmsUserBlacklistServices = coreCmsUserBlacklistServices; - _dbBase = dbBase; + _dbBase = unitOfWork.GetDbClient(); } /// /// wx.login登陆成功之后发送的请求 diff --git a/CoreCms.Net.Web.WebApi/Doc.xml b/CoreCms.Net.Web.WebApi/Doc.xml index 7439348..8d869c3 100644 --- a/CoreCms.Net.Web.WebApi/Doc.xml +++ b/CoreCms.Net.Web.WebApi/Doc.xml @@ -776,9 +776,15 @@ 页大小 + + + 获取正在进行的预约 + + + - + 首页预约列表 @@ -884,7 +890,7 @@ 用户操作事件 - + 构造函数 @@ -1281,6 +1287,26 @@ + + + 获取黑名单列表 + + + + + + 添加黑名单 + + + + + + + 取消拉黑名单 + + + + 微信小程序消息订阅接口