|
@@ -89,16 +89,16 @@ public class DefaultCaptchaSmsHandler implements CaptchaSmsHandler {
|
|
// 如果目标手机号属于白名单手机号则将手机号后{{length}}位作为验证码,否则获取真实的验证码
|
|
// 如果目标手机号属于白名单手机号则将手机号后{{length}}位作为验证码,否则获取真实的验证码
|
|
try {
|
|
try {
|
|
String key = this.key(mobile);
|
|
String key = this.key(mobile);
|
|
- String token = StringUtils.uuid();
|
|
|
|
|
|
+ String id = StringUtils.uuid();
|
|
boolean whitelisted = this.isCaptchaWhitelisted(mobile);
|
|
boolean whitelisted = this.isCaptchaWhitelisted(mobile);
|
|
String code = whitelisted ? mobile.substring(mobile.length() - length) : this.random(length);
|
|
String code = whitelisted ? mobile.substring(mobile.length() - length) : this.random(length);
|
|
- Captcha captcha = Captcha.builder().token(token).code(code).mobile(mobile).build();
|
|
|
|
|
|
+ Captcha captcha = Captcha.builder().id(id).code(code).mobile(mobile).build();
|
|
if (!whitelisted) {
|
|
if (!whitelisted) {
|
|
Objects.requireNonNull(this.handler).send(this.properties.getTemplate(), captcha);
|
|
Objects.requireNonNull(this.handler).send(this.properties.getTemplate(), captcha);
|
|
}
|
|
}
|
|
RedisContextHolder.getDefaultTemplate().opsForValue()
|
|
RedisContextHolder.getDefaultTemplate().opsForValue()
|
|
.set(key, captcha, this.properties.getExpiration(), TimeUnit.SECONDS);
|
|
.set(key, captcha, this.properties.getExpiration(), TimeUnit.SECONDS);
|
|
- return SmsSession.builder().token(token).expiration(this.properties.getExpiration()).build();
|
|
|
|
|
|
+ return SmsSession.builder().id(id).expiration(this.properties.getExpiration()).build();
|
|
} catch (RuntimeException e) {
|
|
} catch (RuntimeException e) {
|
|
// 保证验证码发送失败场景下及时释放锁
|
|
// 保证验证码发送失败场景下及时释放锁
|
|
RedisContextHolder.unlock(lock, secret);
|
|
RedisContextHolder.unlock(lock, secret);
|
|
@@ -120,14 +120,14 @@ public class DefaultCaptchaSmsHandler implements CaptchaSmsHandler {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public boolean check(@NonNull String token, @NonNull String mobile, @NonNull String code) {
|
|
|
|
|
|
+ public boolean check(@NonNull String id, @NonNull String mobile, @NonNull String code) {
|
|
Captcha captcha = this.getCaptcha(mobile);
|
|
Captcha captcha = this.getCaptcha(mobile);
|
|
- return captcha != null && captcha.check(token, mobile, code);
|
|
|
|
|
|
+ return captcha != null && captcha.check(id, mobile, code);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public boolean validate(@NonNull String token, @NonNull String mobile, @NonNull String code) {
|
|
|
|
- boolean available = this.check(token, mobile, code);
|
|
|
|
|
|
+ public boolean validate(@NonNull String id, @NonNull String mobile, @NonNull String code) {
|
|
|
|
+ boolean available = this.check(id, mobile, code);
|
|
if (available) {
|
|
if (available) {
|
|
RedisContextHolder.getDefaultTemplate().delete(this.key(mobile));
|
|
RedisContextHolder.getDefaultTemplate().delete(this.key(mobile));
|
|
}
|
|
}
|