Explorar o código

feat(sms): 发送短信时永久存储验证码

- 在阿里云短信服务中增加验证码的持久化存储功能
- 新增调用 StoreVerificationCodeMapper 插入验证码记录
- 设置验证码实体属性如应用类型、业务类型及时间戳
- 保留原有的 Redis 缓存机制用于短期验证
- 添加了创建时间和更新时间字段以支持审计追踪
fcw hai 1 semana
pai
achega
897baa185e
Modificáronse 1 ficheiros con 16 adicións e 0 borrados
  1. 16 0
      alien-lawyer/src/main/java/shop/alien/lawyer/util/AliSms.java

+ 16 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/util/AliSms.java

@@ -9,10 +9,13 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
+import shop.alien.entity.store.StoreVerificationCode;
+import shop.alien.mapper.StoreVerificationCodeMapper;
 import shop.alien.util.common.RandomCreateUtil;
 import shop.alien.lawyer.config.BaseRedisService;
 
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -28,6 +31,8 @@ import java.util.List;
 public class AliSms {
     private final BaseRedisService baseRedisService;
 
+    private final StoreVerificationCodeMapper storeVerificationCodeMapper;
+
     @Value("${ali.sms.accessKeyId}")
     private String accessKeyId;
 
@@ -88,6 +93,17 @@ public class AliSms {
             }
             // 验证码发送成功,将验证码保存到redis中 设置60秒过期
             baseRedisService.setString("verification_lawyer_"+phone,code.toString(),Long.valueOf(300));
+            // 永久存储验证码
+            StoreVerificationCode entity = new StoreVerificationCode();
+            entity.setAppType(2);
+            entity.setBusinessType(7);
+            entity.setPhone(phone);
+            entity.setCode(String.valueOf(code));
+            Date now = new Date();
+            entity.setCreatedTime(now);
+            entity.setUpdatedTime(now);
+            entity.setDeleteFlag(0);
+            storeVerificationCodeMapper.insert(entity);
             return code;
         } catch (Exception e) {
             log.error("AliSmsConfig.sendSms ERROR Msg={}", e.getMessage());