fix(system): 调整小程序配置读取顺序

- 修改 getMpWxSetting 方法,优先读取 sys_setting(mp-weixin)
- 读取失败时回退到 db_websopy.app_config(category=wechat)
- 更新异常日志内容,明确读取失败顺序
- 适配业务需求调整配置优先级
- 影响所有调用 getMpWxSetting 的相关方法调用流程
This commit is contained in:
2026-06-21 10:32:39 +08:00
parent 307c209565
commit f5f9e3a19d
2 changed files with 35 additions and 7 deletions

View File

@@ -0,0 +1,27 @@
# 2026-06-21 工作日志
## WxLoginController 配置读取顺序调整
### 修改内容
修改了 `WxLoginController.java` 中的 `getMpWxSetting` 方法,调整小程序配置读取顺序:
**修改前:**
- 优先:`db_websopy.app_config`category=wechat
- 兜底:`sys_setting.mp-weixin`
**修改后:**
- 优先:`sys_setting.mp-weixin`
- 兜底:`db_websopy.app_config`category=wechat
### 修改原因
业务需求变更需要优先从系统设置sys_setting读取小程序配置数据库配置app_config作为兜底方案。
### 影响范围
影响所有调用 `getMpWxSetting` 方法的地方:
- `getOpenIdByCode` - 获取 openid
- `getAccessToken` - 获取 access_token
- `loginByOpenId` - openid 无感登录
- `getWxOpenId` / `getWxOpenIdOnly` - 获取微信 openId
### 文件位置
`/Users/gxwebsoft/JAVA/com.gxwebsoft.core/src/main/java/com/gxwebsoft/common/system/controller/WxLoginController.java`

View File

@@ -437,7 +437,7 @@ public class WxLoginController extends BaseController {
}
/**
* 优先读取 db_websopy.app_configcategory=wechat,不存在或异常时回退到 sys_setting (mp-weixin)
* 优先读取 sys_setting (mp-weixin),不存在或异常时回退到 db_websopy.app_configcategory=wechat
*
* @param tenantId 租户ID传 null 时使用当前请求租户)
* @return JSONObject 配置内容(含 appId / appSecret 等字段)
@@ -445,15 +445,16 @@ public class WxLoginController extends BaseController {
private JSONObject getMpWxSetting(Integer tenantId) {
Integer tid = tenantId != null ? tenantId : getTenantId();
try {
JSONObject wechat = appConfigService.getByCategory("wechat", tid);
if (wechat != null && !wechat.isEmpty()) {
return wechat;
// 优先sys_setting.mp-weixin
JSONObject setting = settingService.getBySettingKey("mp-weixin");
if (setting != null && !setting.isEmpty()) {
return setting;
}
} catch (Exception e) {
System.err.println("[WxLoginController] 读取 app_config 失败,回退 sys_setting: " + e.getMessage());
System.err.println("[WxLoginController] 读取 sys_setting 失败,回退 app_config: " + e.getMessage());
}
// 兜底:原 sys_setting.mp-weixin
return settingService.getBySettingKey("mp-weixin");
// 兜底:db_websopy.app_configcategory=wechat
return appConfigService.getByCategory("wechat", tid);
}
/**