Selaa lähdekoodia

fix: fix auth code length is too lang problem

linwenhua 2 vuotta sitten
vanhempi
sitoutus
807ecccfe5

+ 3 - 1
smsb-customer-manager-app/src/main/java/com/inspur/customer/service/authcode/AuthCodeServiceImpl.java

@@ -52,7 +52,7 @@ public class AuthCodeServiceImpl implements AuthCodeService {
         try{
 
             //生成一个6位验证码
-            String authCode = String.valueOf(((Math.random() * 9 + 1) * 100000));
+            String authCode = StringUtils.left(String.valueOf(((Math.random() * 9 + 1) * 100000)), 6);
             Boolean sendResult = commonInformService.sendMessage(AUTH_CODE_MESSAGE_TEMPLATE, getMessage(authCode, authCodeDTO));
             if (Boolean.TRUE.equals(sendResult)) {
                 redisTemplate.opsForValue().set(AUTH_CODE_CACHE_KEY + authCodeDTO.getEmail(), authCode, 5, TimeUnit.MINUTES);
@@ -69,6 +69,7 @@ public class AuthCodeServiceImpl implements AuthCodeService {
 
     private AbstractBaseInformMessage getMessage(String authCode, AuthCodeDTO authCodeDTO) {
         if (StringUtils.isNotBlank(authCodeDTO.getEmail())) {
+            log.info("email auth code");
             EmailInformMessage emailInformMessage = new EmailInformMessage();
             Map<String, String> params = new HashMap<>(1);
             params.put("\\{MSR_AUTH_CODE}", String.valueOf(authCode));
@@ -76,6 +77,7 @@ public class AuthCodeServiceImpl implements AuthCodeService {
             emailInformMessage.setAddressees(Collections.singletonList(authCodeDTO.getEmail()));
             return emailInformMessage;
         } else {
+            log.info("sms auth code");
             SmsInformMessage smsInformMessage = new SmsInformMessage();
             Map<String, String> params = new HashMap<>(1);
             params.put("MSRcode", String.valueOf(authCode));