功能:补齐 消息中心 手工初始化 SQL
This commit is contained in:
@@ -54,14 +54,32 @@
|
||||
- 当缺少来源系统相关表时,会明确提示执行:
|
||||
- `2026-03-23_message_source_system_patch.sql`
|
||||
|
||||
### 7. 新增完整手工初始化 SQL
|
||||
|
||||
- 新增 `2026-03-23_messagehub_complete_manual_init.sql`
|
||||
- 用于一次性补齐:
|
||||
- `push_template`
|
||||
- `push_log`
|
||||
- 通道配置表
|
||||
- 来源系统白名单表
|
||||
- 来源系统默认通道映射表
|
||||
- 旧 YAML 通道种子数据
|
||||
- `yuminail` 来源系统
|
||||
- `SPUG0001` 验证码模板
|
||||
|
||||
## 数据库 SQL
|
||||
|
||||
本轮新增 SQL 文件:
|
||||
|
||||
- [2026-03-23_messagehub_complete_manual_init.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_messagehub_complete_manual_init.sql)
|
||||
- [2026-03-23_message_source_system_patch.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_message_source_system_patch.sql)
|
||||
|
||||
推荐执行顺序:
|
||||
|
||||
1. [2026-03-23_messagehub_complete_manual_init.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_messagehub_complete_manual_init.sql)
|
||||
|
||||
如需拆开执行,再按以下顺序补齐:
|
||||
|
||||
1. [2026-03-23_message_channel_management_patch.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_message_channel_management_patch.sql)
|
||||
2. [2026-03-23_message_source_system_patch.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_message_source_system_patch.sql)
|
||||
|
||||
|
||||
@@ -24,16 +24,18 @@
|
||||
|
||||
## 3. 推荐数据库执行顺序
|
||||
|
||||
当前推荐的 MessageHub 数据库执行顺序如下:
|
||||
当前推荐的 MessageHub 数据库执行方式如下:
|
||||
|
||||
1. 执行 [2026-03-23_message_channel_management_patch.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_message_channel_management_patch.sql)
|
||||
2. 执行 [2026-03-23_message_source_system_patch.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_message_source_system_patch.sql)
|
||||
1. [2026-03-23_messagehub_complete_manual_init.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_messagehub_complete_manual_init.sql)
|
||||
|
||||
说明:
|
||||
|
||||
- 第一份 SQL 创建通道配置表
|
||||
- 第二份 SQL 创建来源系统白名单表和“来源系统默认通道”映射表
|
||||
- 这份完整 SQL 已包含当前发送链路依赖的关键表、旧配置迁移通道、`yuminail` 来源系统以及 `SPUG0001` 模板
|
||||
- 本轮仍然不做自动迁移,SQL 需要手工执行
|
||||
- 仓库里旧 YAML 通道秘钥仍然是占位值,执行前请先替换为真实值
|
||||
- 如果你只想拆开执行补丁,也可以继续使用:
|
||||
- [2026-03-23_message_channel_management_patch.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_message_channel_management_patch.sql)
|
||||
- [2026-03-23_message_source_system_patch.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_message_source_system_patch.sql)
|
||||
|
||||
## 4. 资源目录说明
|
||||
|
||||
@@ -49,6 +51,8 @@
|
||||
- 通道管理表补丁
|
||||
- `sql/2026-03-23_message_source_system_patch.sql`
|
||||
- 来源系统白名单与系统默认通道补丁
|
||||
- `sql/2026-03-23_messagehub_complete_manual_init.sql`
|
||||
- 当前推荐的完整手工执行 SQL
|
||||
- `static/messagehub-admin/`
|
||||
- 后台管理页面
|
||||
- 访问地址:`http://<host>:8080/messagehub-admin/`
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
-- MessageHub 当前推荐的手工补齐 SQL
|
||||
-- 适用日期:2026-03-23
|
||||
-- 用途:
|
||||
-- 1. 一次性补齐 MessageHub 当前发送链路依赖的关键表
|
||||
-- 2. 写入旧 MessageHub.yaml 中能明确提取出的短信/邮件通道
|
||||
-- 3. 写入 YumiNail 当前依赖的来源系统白名单与验证码模板
|
||||
--
|
||||
-- 说明:
|
||||
-- 1. 本文件采用“可重复执行”的思路,尽量避免重复插入
|
||||
-- 2. 仓库中的旧 YAML 凭据是占位值,不是生产真实秘钥,请执行前按需修改
|
||||
-- 3. secret_json 这里先写明文 JSON,MessageHub 兼容读取;后续在后台保存一次即可自动转为加密存储
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS `messagehub` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
USE `messagehub`;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `push_template` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`template_code` VARCHAR(100) NOT NULL COMMENT '模板编码',
|
||||
`template_name` VARCHAR(255) NOT NULL COMMENT '模板名称',
|
||||
`channel_type` VARCHAR(20) NOT NULL COMMENT '通道类型',
|
||||
`msg_type` INT NULL COMMENT '消息类型',
|
||||
`external_id` VARCHAR(100) NULL COMMENT '外部模板 ID',
|
||||
`content_pattern` TEXT NULL COMMENT '模板内容',
|
||||
`msg_category` INT NULL COMMENT '消息分类',
|
||||
`is_enable` TINYINT NOT NULL DEFAULT 1 COMMENT '1 启用,0 停用',
|
||||
`description` VARCHAR(255) NULL COMMENT '描述',
|
||||
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_push_template_code` (`template_code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='消息模板表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `push_log` (
|
||||
`id` VARCHAR(100) NOT NULL COMMENT '消息 ID',
|
||||
`source_system` VARCHAR(64) NULL COMMENT '来源系统',
|
||||
`unique_id` VARCHAR(100) NULL COMMENT '业务唯一标识',
|
||||
`receiver` VARCHAR(128) NULL COMMENT '接收者',
|
||||
`channel_type` VARCHAR(20) NULL COMMENT '通道类型',
|
||||
`msg_type` VARCHAR(50) NULL COMMENT '消息类型',
|
||||
`template_code` VARCHAR(100) NULL COMMENT '模板编码',
|
||||
`template_params` TEXT NULL COMMENT '模板参数',
|
||||
`final_content` TEXT NULL COMMENT '最终内容',
|
||||
`status` TINYINT NOT NULL DEFAULT 0 COMMENT '0 待发送,1 成功,2 失败',
|
||||
`retry_count` INT NOT NULL DEFAULT 0 COMMENT '重试次数',
|
||||
`fail_reason` VARCHAR(255) NULL COMMENT '失败原因',
|
||||
`send_time` DATETIME NULL COMMENT '发送时间',
|
||||
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_push_log_source_system` (`source_system`),
|
||||
KEY `idx_push_log_receiver` (`receiver`),
|
||||
KEY `idx_push_log_channel_type` (`channel_type`),
|
||||
KEY `idx_push_log_status` (`status`),
|
||||
KEY `idx_push_log_create_time` (`create_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='消息推送日志表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `message_channel_config` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
|
||||
`channel_type` VARCHAR(20) NOT NULL COMMENT 'SMS / EMAIL',
|
||||
`provider_code` VARCHAR(50) NOT NULL COMMENT 'SPUG / GMAIL / QQMAIL / MOCK_SMS / MOCK_EMAIL',
|
||||
`channel_name` VARCHAR(100) NOT NULL COMMENT 'Display name',
|
||||
`config_json` TEXT NULL COMMENT 'Public config JSON',
|
||||
`secret_json` TEXT NULL COMMENT 'Encrypted or plain secret JSON',
|
||||
`enabled` TINYINT NOT NULL DEFAULT 1 COMMENT '1 enabled, 0 disabled',
|
||||
`is_default` TINYINT NOT NULL DEFAULT 0 COMMENT '1 default, 0 non-default',
|
||||
`health_status` VARCHAR(20) NOT NULL DEFAULT 'UNKNOWN' COMMENT 'UNKNOWN / HEALTHY / UNHEALTHY',
|
||||
`health_message` VARCHAR(255) NULL COMMENT 'Last health message',
|
||||
`last_health_check_time` DATETIME NULL COMMENT 'Last health check time',
|
||||
`remark` VARCHAR(255) NULL COMMENT 'Remark',
|
||||
`deleted` TINYINT NOT NULL DEFAULT 0 COMMENT 'Logical delete flag',
|
||||
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Create time',
|
||||
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Update time',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_message_channel_type_provider` (`channel_type`, `provider_code`),
|
||||
KEY `idx_message_channel_enabled_default` (`channel_type`, `enabled`, `is_default`),
|
||||
KEY `idx_message_channel_deleted` (`deleted`),
|
||||
KEY `idx_message_channel_name` (`channel_name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Message channel management';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `message_source_system` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
|
||||
`system_code` VARCHAR(64) NOT NULL COMMENT 'External source system code',
|
||||
`system_name` VARCHAR(100) NOT NULL COMMENT 'External source system name',
|
||||
`enabled` TINYINT NOT NULL DEFAULT 1 COMMENT '1 enabled, 0 disabled',
|
||||
`remark` VARCHAR(255) NULL COMMENT 'Remark',
|
||||
`deleted` TINYINT NOT NULL DEFAULT 0 COMMENT 'Logical delete flag',
|
||||
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Create time',
|
||||
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Update time',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_message_source_system_code` (`system_code`),
|
||||
KEY `idx_message_source_system_enabled` (`enabled`),
|
||||
KEY `idx_message_source_system_deleted` (`deleted`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Allowed source systems';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `message_source_system_channel` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
|
||||
`system_id` BIGINT NOT NULL COMMENT 'Source system id',
|
||||
`channel_type` VARCHAR(20) NOT NULL COMMENT 'SMS / EMAIL',
|
||||
`channel_id` BIGINT NOT NULL COMMENT 'Default channel id for this source system and type',
|
||||
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Create time',
|
||||
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Update time',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_message_source_system_channel` (`system_id`, `channel_type`),
|
||||
KEY `idx_message_source_system_channel_id` (`channel_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Per source system default channels';
|
||||
|
||||
-- 旧配置文件里的 Spug 短信通道(sms.platform = spug)
|
||||
UPDATE `message_channel_config`
|
||||
SET `config_json` = '{"baseUrl":"https://push.spug.cc"}',
|
||||
`secret_json` = '{"apiKey":"your-api-key"}',
|
||||
`enabled` = 1,
|
||||
`is_default` = 1,
|
||||
`health_status` = 'UNKNOWN',
|
||||
`health_message` = '待检测',
|
||||
`remark` = '从旧 MessageHub.yaml 迁移的 Spug 短信通道'
|
||||
WHERE `channel_type` = 'SMS'
|
||||
AND `provider_code` = 'SPUG'
|
||||
AND `channel_name` = '旧配置-Spug短信主通道';
|
||||
|
||||
INSERT INTO `message_channel_config` (
|
||||
`channel_type`, `provider_code`, `channel_name`, `config_json`, `secret_json`,
|
||||
`enabled`, `is_default`, `health_status`, `health_message`, `remark`, `deleted`
|
||||
)
|
||||
SELECT
|
||||
'SMS', 'SPUG', '旧配置-Spug短信主通道',
|
||||
'{"baseUrl":"https://push.spug.cc"}',
|
||||
'{"apiKey":"your-api-key"}',
|
||||
1, 1, 'UNKNOWN', '待检测', '从旧 MessageHub.yaml 迁移的 Spug 短信通道', 0
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM `message_channel_config`
|
||||
WHERE `channel_type` = 'SMS'
|
||||
AND `provider_code` = 'SPUG'
|
||||
AND `channel_name` = '旧配置-Spug短信主通道'
|
||||
);
|
||||
|
||||
-- 旧配置文件里的 Gmail 邮件通道(email.platform = gmail)
|
||||
UPDATE `message_channel_config`
|
||||
SET `config_json` = '{"host":"smtp.gmail.com","port":"587","username":"your-gmail-username@gmail.com","fromAddress":"your-gmail-username@gmail.com","auth":true,"starttls":true,"ssl":false}',
|
||||
`secret_json` = '{"password":"your-gmail-app-password"}',
|
||||
`enabled` = 1,
|
||||
`is_default` = 1,
|
||||
`health_status` = 'UNKNOWN',
|
||||
`health_message` = '待检测',
|
||||
`remark` = '从旧 MessageHub.yaml 迁移的 Gmail 邮件通道'
|
||||
WHERE `channel_type` = 'EMAIL'
|
||||
AND `provider_code` = 'GMAIL'
|
||||
AND `channel_name` = '旧配置-Gmail邮件主通道';
|
||||
|
||||
INSERT INTO `message_channel_config` (
|
||||
`channel_type`, `provider_code`, `channel_name`, `config_json`, `secret_json`,
|
||||
`enabled`, `is_default`, `health_status`, `health_message`, `remark`, `deleted`
|
||||
)
|
||||
SELECT
|
||||
'EMAIL', 'GMAIL', '旧配置-Gmail邮件主通道',
|
||||
'{"host":"smtp.gmail.com","port":"587","username":"your-gmail-username@gmail.com","fromAddress":"your-gmail-username@gmail.com","auth":true,"starttls":true,"ssl":false}',
|
||||
'{"password":"your-gmail-app-password"}',
|
||||
1, 1, 'UNKNOWN', '待检测', '从旧 MessageHub.yaml 迁移的 Gmail 邮件通道', 0
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM `message_channel_config`
|
||||
WHERE `channel_type` = 'EMAIL'
|
||||
AND `provider_code` = 'GMAIL'
|
||||
AND `channel_name` = '旧配置-Gmail邮件主通道'
|
||||
);
|
||||
|
||||
-- 旧配置文件里的 QQ 邮箱通道(配置文件中存在,但未被 platform 设为默认)
|
||||
UPDATE `message_channel_config`
|
||||
SET `config_json` = '{"host":"smtp.qq.com","port":"587","username":"your-qq-email@qq.com","fromAddress":"your-qq-email@qq.com","auth":true,"starttls":true,"ssl":false}',
|
||||
`secret_json` = '{"password":"your-qq-authorization-code"}',
|
||||
`enabled` = 0,
|
||||
`is_default` = 0,
|
||||
`health_status` = 'UNKNOWN',
|
||||
`health_message` = '待检测',
|
||||
`remark` = '从旧 MessageHub.yaml 迁移的 QQ 邮箱备用通道'
|
||||
WHERE `channel_type` = 'EMAIL'
|
||||
AND `provider_code` = 'QQMAIL'
|
||||
AND `channel_name` = '旧配置-QQ邮箱备用通道';
|
||||
|
||||
INSERT INTO `message_channel_config` (
|
||||
`channel_type`, `provider_code`, `channel_name`, `config_json`, `secret_json`,
|
||||
`enabled`, `is_default`, `health_status`, `health_message`, `remark`, `deleted`
|
||||
)
|
||||
SELECT
|
||||
'EMAIL', 'QQMAIL', '旧配置-QQ邮箱备用通道',
|
||||
'{"host":"smtp.qq.com","port":"587","username":"your-qq-email@qq.com","fromAddress":"your-qq-email@qq.com","auth":true,"starttls":true,"ssl":false}',
|
||||
'{"password":"your-qq-authorization-code"}',
|
||||
0, 0, 'UNKNOWN', '待检测', '从旧 MessageHub.yaml 迁移的 QQ 邮箱备用通道', 0
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM `message_channel_config`
|
||||
WHERE `channel_type` = 'EMAIL'
|
||||
AND `provider_code` = 'QQMAIL'
|
||||
AND `channel_name` = '旧配置-QQ邮箱备用通道'
|
||||
);
|
||||
|
||||
-- 来源系统白名单:YumiNail
|
||||
INSERT INTO `message_source_system` (`system_code`, `system_name`, `enabled`, `remark`, `deleted`)
|
||||
VALUES ('yuminail', 'YumiNail', 1, 'YumiNail-Core 验证码发送来源系统', 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`system_name` = VALUES(`system_name`),
|
||||
`enabled` = VALUES(`enabled`),
|
||||
`remark` = VALUES(`remark`),
|
||||
`deleted` = 0,
|
||||
`update_time` = CURRENT_TIMESTAMP;
|
||||
|
||||
-- YumiNail 当前验证码模板
|
||||
INSERT INTO `push_template` (
|
||||
`template_code`, `template_name`, `channel_type`, `msg_type`, `external_id`,
|
||||
`content_pattern`, `msg_category`, `is_enable`, `description`
|
||||
)
|
||||
VALUES (
|
||||
'SPUG0001',
|
||||
'YumiNail 验证码短信模板',
|
||||
'SMS',
|
||||
2,
|
||||
'your-template-id',
|
||||
'【YumiNail】您的验证码是${code},${number}分钟内有效,如非本人操作请忽略。',
|
||||
1,
|
||||
1,
|
||||
'由旧 MessageHub.yaml 中的 sms.spug.template-id 和 YumiNail-Core 调用口径整理而来'
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`template_name` = VALUES(`template_name`),
|
||||
`channel_type` = VALUES(`channel_type`),
|
||||
`msg_type` = VALUES(`msg_type`),
|
||||
`external_id` = VALUES(`external_id`),
|
||||
`content_pattern` = VALUES(`content_pattern`),
|
||||
`msg_category` = VALUES(`msg_category`),
|
||||
`is_enable` = VALUES(`is_enable`),
|
||||
`description` = VALUES(`description`),
|
||||
`update_time` = CURRENT_TIMESTAMP;
|
||||
|
||||
-- 来源系统默认短信通道:YumiNail -> 旧配置-Spug短信主通道
|
||||
INSERT INTO `message_source_system_channel` (`system_id`, `channel_type`, `channel_id`)
|
||||
SELECT ss.`id`, 'SMS', mc.`id`
|
||||
FROM `message_source_system` ss
|
||||
JOIN `message_channel_config` mc
|
||||
ON mc.`channel_type` = 'SMS'
|
||||
AND mc.`provider_code` = 'SPUG'
|
||||
AND mc.`channel_name` = '旧配置-Spug短信主通道'
|
||||
WHERE ss.`system_code` = 'yuminail'
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`channel_id` = VALUES(`channel_id`),
|
||||
`update_time` = CURRENT_TIMESTAMP;
|
||||
|
||||
-- 来源系统默认邮件通道:YumiNail -> 旧配置-Gmail邮件主通道
|
||||
INSERT INTO `message_source_system_channel` (`system_id`, `channel_type`, `channel_id`)
|
||||
SELECT ss.`id`, 'EMAIL', mc.`id`
|
||||
FROM `message_source_system` ss
|
||||
JOIN `message_channel_config` mc
|
||||
ON mc.`channel_type` = 'EMAIL'
|
||||
AND mc.`provider_code` = 'GMAIL'
|
||||
AND mc.`channel_name` = '旧配置-Gmail邮件主通道'
|
||||
WHERE ss.`system_code` = 'yuminail'
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`channel_id` = VALUES(`channel_id`),
|
||||
`update_time` = CURRENT_TIMESTAMP;
|
||||
+19
-18
@@ -9,27 +9,27 @@ import org.springframework.amqp.core.MessageBuilder;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* MessageHub客户端服务实现
|
||||
* 通过RabbitMQ发送消息到MessageHub服务
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-03-03
|
||||
* MessageHub 客户端服务实现。
|
||||
* 通过 RabbitMQ 发送消息到 MessageHub 服务。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MessageHubClientServiceImpl implements MessageHubClientService {
|
||||
|
||||
private static final String SMS_QUEUE = "smsQueue";
|
||||
private static final String SOURCE_SYSTEM = "yuminail";
|
||||
private static final String VERIFY_TEMPLATE_CODE = "SPUG0001";
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
private static final String SMS_QUEUE = "smsQueue";
|
||||
|
||||
@Override
|
||||
public void sendSmsVerificationCode(String phone, String code) {
|
||||
try {
|
||||
@@ -37,30 +37,31 @@ public class MessageHubClientServiceImpl implements MessageHubClientService {
|
||||
messageBody.put("receiver", phone);
|
||||
messageBody.put("channelType", "SMS");
|
||||
messageBody.put("msgType", "VERIFICATION");
|
||||
messageBody.put("templateCode", "SPUG0001");
|
||||
messageBody.put("sourceSystem", "yuminail");
|
||||
messageBody.put("templateCode", VERIFY_TEMPLATE_CODE);
|
||||
messageBody.put("sourceSystem", SOURCE_SYSTEM);
|
||||
messageBody.put("uniqueId", UUID.randomUUID().toString());
|
||||
messageBody.put("sendMethod", "SPUG");
|
||||
|
||||
Map<String, Object> templateParams = new HashMap<>();
|
||||
templateParams.put("name", "屿Nail");
|
||||
templateParams.put("name", "YumiNail");
|
||||
templateParams.put("code", code);
|
||||
templateParams.put("number", "5");
|
||||
messageBody.put("templateParams", templateParams);
|
||||
|
||||
String jsonBody = objectMapper.writeValueAsString(messageBody);
|
||||
|
||||
Message message = MessageBuilder
|
||||
.withBody(jsonBody.getBytes())
|
||||
.withBody(jsonBody.getBytes(StandardCharsets.UTF_8))
|
||||
.setContentType("application/json")
|
||||
.setContentEncoding(StandardCharsets.UTF_8.name())
|
||||
.setMessageId(UUID.randomUUID().toString())
|
||||
.build();
|
||||
|
||||
rabbitTemplate.convertAndSend(SMS_QUEUE, message);
|
||||
|
||||
log.info("短信验证码消息已发送到队列,手机号: {}, 验证码: {}", phone, code);
|
||||
} catch (Exception e) {
|
||||
log.error("发送短信验证码失败", e);
|
||||
throw new RuntimeException("发送短信验证码失败: " + e.getMessage(), e);
|
||||
log.info("短信验证码消息已发送到队列,手机号: {}, sourceSystem: {}, templateCode: {}",
|
||||
phone, SOURCE_SYSTEM, VERIFY_TEMPLATE_CODE);
|
||||
} catch (Exception exception) {
|
||||
log.error("发送短信验证码失败", exception);
|
||||
throw new RuntimeException("发送短信验证码失败: " + exception.getMessage(), exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-19
@@ -9,28 +9,24 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 验证码服务实现
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-03-03
|
||||
* 验证码服务实现。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class VerificationCodeServiceImpl implements VerificationCodeService {
|
||||
|
||||
private final StringRedisTemplate redisTemplate;
|
||||
private final MessageHubClientService messageHubClientService;
|
||||
|
||||
private static final String CODE_PREFIX = "verification:code:";
|
||||
private static final String SEND_TIME_PREFIX = "verification:send_time:";
|
||||
private static final int CODE_LENGTH = 6;
|
||||
private static final int CODE_EXPIRE_MINUTES = 5;
|
||||
private static final int RESEND_INTERVAL_SECONDS = 60;
|
||||
|
||||
private final StringRedisTemplate redisTemplate;
|
||||
private final MessageHubClientService messageHubClientService;
|
||||
|
||||
@Override
|
||||
public String generateVerificationCode() {
|
||||
SecureRandom random = new SecureRandom();
|
||||
@@ -44,34 +40,33 @@ public class VerificationCodeServiceImpl implements VerificationCodeService {
|
||||
@Override
|
||||
public void sendVerificationCode(String phone) {
|
||||
String code = generateVerificationCode();
|
||||
|
||||
|
||||
String codeKey = CODE_PREFIX + phone;
|
||||
String sendTimeKey = SEND_TIME_PREFIX + phone;
|
||||
|
||||
|
||||
redisTemplate.opsForValue().set(codeKey, code, Duration.ofMinutes(CODE_EXPIRE_MINUTES));
|
||||
redisTemplate.opsForValue().set(sendTimeKey, String.valueOf(System.currentTimeMillis()),
|
||||
redisTemplate.opsForValue().set(sendTimeKey, String.valueOf(System.currentTimeMillis()),
|
||||
Duration.ofSeconds(RESEND_INTERVAL_SECONDS));
|
||||
|
||||
|
||||
messageHubClientService.sendSmsVerificationCode(phone, code);
|
||||
|
||||
log.info("验证码已发送,手机号: {}, 验证码: {}", phone, code);
|
||||
log.info("验证码已发送,手机号: {}", phone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyCode(String phone, String code) {
|
||||
String codeKey = CODE_PREFIX + phone;
|
||||
String storedCode = redisTemplate.opsForValue().get(codeKey);
|
||||
|
||||
|
||||
if (storedCode == null) {
|
||||
log.warn("验证码不存在或已过期,手机号: {}", phone);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!storedCode.equals(code)) {
|
||||
log.warn("验证码错误,手机号: {}, 输入: {}, 正确: {}", phone, code, storedCode);
|
||||
log.warn("验证码错误,手机号: {}", phone);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
redisTemplate.delete(codeKey);
|
||||
log.info("验证码验证成功,手机号: {}", phone);
|
||||
return true;
|
||||
@@ -83,4 +78,4 @@ public class VerificationCodeServiceImpl implements VerificationCodeService {
|
||||
String sendTime = redisTemplate.opsForValue().get(sendTimeKey);
|
||||
return sendTime == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
# MessageHub 完整 SQL 与 YumiNail 调用复核
|
||||
|
||||
## 日期
|
||||
|
||||
2026-03-23
|
||||
|
||||
## 本轮目标
|
||||
|
||||
- 整理一份可手工执行的完整 SQL 文件
|
||||
- 把旧配置文件中的短信/邮件通道写成 SQL
|
||||
- 复核 YumiNail 当前调用 MessageHub 的链路
|
||||
|
||||
## 结论摘要
|
||||
|
||||
### 1. 已新增完整 SQL 文件
|
||||
|
||||
新增文件:
|
||||
|
||||
- [2026-03-23_messagehub_complete_manual_init.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_messagehub_complete_manual_init.sql)
|
||||
|
||||
这份 SQL 已包含:
|
||||
|
||||
- `push_template`
|
||||
- `push_log`
|
||||
- `message_channel_config`
|
||||
- `message_source_system`
|
||||
- `message_source_system_channel`
|
||||
- 旧 `MessageHub.yaml` 中的 Spug / Gmail / QQMail 通道种子数据
|
||||
- `yuminail` 来源系统
|
||||
- `SPUG0001` 验证码模板
|
||||
- `yuminail` 对应的默认短信/邮件通道映射
|
||||
|
||||
### 2. 旧配置文件可落库的内容
|
||||
|
||||
从仓库内旧配置文件可明确提取出的配置有:
|
||||
|
||||
- `sms.platform = spug`
|
||||
- `sms.spug.base-url = https://push.spug.cc`
|
||||
- `sms.spug.template-id = your-template-id`
|
||||
- `sms.spug.api-key = your-api-key`
|
||||
- `email.platform = gmail`
|
||||
- `email.gmail.*`
|
||||
- `email.qqmail.*`
|
||||
|
||||
说明:
|
||||
|
||||
- 这些邮件/短信账号密码在仓库里是占位值,不是真实线上秘钥
|
||||
- 我已经按仓库真实可见内容写成 SQL
|
||||
- 执行前你可以直接把 SQL 里的占位值替换成你自己的真实值
|
||||
|
||||
### 3. YumiNail 调用检查结果
|
||||
|
||||
当前 `YumiNail-Core` 到 MessageHub 的调用主链是正确的:
|
||||
|
||||
- 队列仍然是 `smsQueue`
|
||||
- 已带 `sourceSystem = yuminail`
|
||||
- 消息类型、模板编码、唯一标识都符合 MessageHub 现有规则
|
||||
|
||||
本轮发现并修复的问题:
|
||||
|
||||
- 模板参数 `name` 原来是乱码值,现已改为 `YumiNail`
|
||||
- RabbitMQ 消息体原来使用平台默认编码转字节,现改为显式 `UTF-8`
|
||||
- 发送验证码相关日志不再打印明文验证码
|
||||
|
||||
### 4. 额外补齐说明
|
||||
|
||||
仅有通道和来源系统还不够,`YumiNail-Core` 当前还依赖:
|
||||
|
||||
- 模板编码:`SPUG0001`
|
||||
|
||||
如果数据库里没有这条模板,验证码短信仍然会失败,所以我已经把模板种子一起写进完整 SQL。
|
||||
|
||||
### 5. 编译复核
|
||||
|
||||
已重新执行:
|
||||
|
||||
- `YumiNail-Core`:`mvn -q -DskipTests compile`
|
||||
- `MessageHub`:`mvn -q -DskipTests compile`
|
||||
|
||||
结果:
|
||||
|
||||
- 两个模块都已编译通过
|
||||
- 本轮未执行真实 MySQL 导入,只完成了 SQL 文本与调用链复核
|
||||
|
||||
## 推荐执行方式
|
||||
|
||||
建议执行:
|
||||
|
||||
- [2026-03-23_messagehub_complete_manual_init.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_messagehub_complete_manual_init.sql)
|
||||
|
||||
如果你更偏向拆开执行,也可以继续使用:
|
||||
|
||||
1. [2026-03-23_message_channel_management_patch.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_message_channel_management_patch.sql)
|
||||
2. [2026-03-23_message_source_system_patch.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_message_source_system_patch.sql)
|
||||
|
||||
但这种拆开执行方式不会自动补齐:
|
||||
|
||||
- `push_template`
|
||||
- `push_log`
|
||||
- 旧配置通道种子数据
|
||||
- `yuminail` 来源系统与映射
|
||||
|
||||
## 涉及文件
|
||||
|
||||
- [MessageHubClientServiceImpl.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/MessageHubClientServiceImpl.java)
|
||||
- [VerificationCodeServiceImpl.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/VerificationCodeServiceImpl.java)
|
||||
- [2026-03-23_messagehub_complete_manual_init.sql](/E:/code/xiaowang/MessageHub/src/main/resources/sql/2026-03-23_messagehub_complete_manual_init.sql)
|
||||
|
||||
## 备注
|
||||
|
||||
- 本轮没有替你执行数据库 SQL
|
||||
- 旧 YAML 中的真实生产秘钥如果不在仓库里,本轮无法自动恢复,只能按仓库现有配置口径整理
|
||||
Reference in New Issue
Block a user