优化代码

main
XiaoHH 2 years ago
parent fb79ed8eed
commit cf38d8b300

@ -27,21 +27,4 @@ public class StringUtil {
public static String generationVerificationCode(int length) { public static String generationVerificationCode(int length) {
return String.valueOf((int) ((Math.random() * 9 + 1) * Math.pow(10, length - 1))); return String.valueOf((int) ((Math.random() * 9 + 1) * Math.pow(10, length - 1)));
} }
/**
* true
*
* @param str1 1
* @param str2 2
* @return
*/
public static boolean equal(String str1, String str2) {
if (null == str1 && null == str2) {
return true;
} else if (null != str1) {
return str1.equals(str2);
} else {
return false;
}
}
} }

@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -79,7 +80,7 @@ public class VerificationCodeServiceImpl implements VerificationCodeService {
return new CheckPhoneVerificationCodeVO(VerificationCodeConstant.VERIFICATION_CODE_TIMEOUT); return new CheckPhoneVerificationCodeVO(VerificationCodeConstant.VERIFICATION_CODE_TIMEOUT);
} else { } else {
String verificationCode = verificationCodeRedis.getVerificationCode(); String verificationCode = verificationCodeRedis.getVerificationCode();
if (StringUtil.equal(verificationCode, passengerVerificationCode.getVerificationCode())) { if (Objects.equals(verificationCode, passengerVerificationCode.getVerificationCode())) {
this.redisTemplate.delete(VerificationCodeConstant.PASSENGER_PHONE_VERIFICATION_CODE_PREFIX + verificationToken); this.redisTemplate.delete(VerificationCodeConstant.PASSENGER_PHONE_VERIFICATION_CODE_PREFIX + verificationToken);
return new CheckPhoneVerificationCodeVO(VerificationCodeConstant.VERIFICATION_CODE_RIGHT, verificationCodeRedis.getPassengerPhone()); return new CheckPhoneVerificationCodeVO(VerificationCodeConstant.VERIFICATION_CODE_RIGHT, verificationCodeRedis.getPassengerPhone());
} else { } else {

Loading…
Cancel
Save