woody преди 1 година
родител
ревизия
bfca982dda

+ 5 - 6
framework-sms/src/main/java/com/chelvc/framework/sms/Captcha.java

@@ -24,9 +24,9 @@ import lombok.ToString;
 @AllArgsConstructor
 public class Captcha implements Serializable {
     /**
-     * 令牌
+     * 令牌标识
      */
-    private String token;
+    private String id;
 
     /**
      * 验证码
@@ -41,13 +41,12 @@ public class Captcha implements Serializable {
     /**
      * 检测验证码是否正确
      *
-     * @param token  令牌标识
+     * @param id     令牌标识
      * @param mobile 手机号
      * @param code   验证码
      * @return true/false
      */
-    public boolean check(String token, String mobile, String code) {
-        return Objects.equals(this.token, token) && Objects.equals(this.mobile, mobile)
-                && Objects.equals(this.code, code);
+    public boolean check(String id, String mobile, String code) {
+        return Objects.equals(this.id, id) && Objects.equals(this.mobile, mobile) && Objects.equals(this.code, code);
     }
 }

+ 4 - 4
framework-sms/src/main/java/com/chelvc/framework/sms/CaptchaSmsHandler.java

@@ -45,20 +45,20 @@ public interface CaptchaSmsHandler {
     /**
      * 检测验证码是否正确
      *
-     * @param token  令牌标识
+     * @param id     短信标识
      * @param mobile 手机号
      * @param code   验证码
      * @return true/false
      */
-    boolean check(String token, String mobile, String code);
+    boolean check(String id, String mobile, String code);
 
     /**
      * 校验验证码是否正确(校验成功后移除)
      *
-     * @param token  令牌标识
+     * @param id     短信标识
      * @param mobile 手机号
      * @param code   验证码
      * @return true/false
      */
-    boolean validate(String token, String mobile, String code);
+    boolean validate(String id, String mobile, String code);
 }

+ 2 - 2
framework-sms/src/main/java/com/chelvc/framework/sms/SmsSession.java

@@ -23,9 +23,9 @@ import lombok.ToString;
 @AllArgsConstructor
 public class SmsSession implements Serializable {
     /**
-     * 短信令牌
+     * 短信标识
      */
-    private String token;
+    private String id;
 
     /**
      * 令牌有效期(秒)

+ 7 - 7
framework-sms/src/main/java/com/chelvc/framework/sms/support/DefaultCaptchaSmsHandler.java

@@ -89,16 +89,16 @@ public class DefaultCaptchaSmsHandler implements CaptchaSmsHandler {
         // 如果目标手机号属于白名单手机号则将手机号后{{length}}位作为验证码,否则获取真实的验证码
         try {
             String key = this.key(mobile);
-            String token = StringUtils.uuid();
+            String id = StringUtils.uuid();
             boolean whitelisted = this.isCaptchaWhitelisted(mobile);
             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) {
                 Objects.requireNonNull(this.handler).send(this.properties.getTemplate(), captcha);
             }
             RedisContextHolder.getDefaultTemplate().opsForValue()
                     .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) {
             // 保证验证码发送失败场景下及时释放锁
             RedisContextHolder.unlock(lock, secret);
@@ -120,14 +120,14 @@ public class DefaultCaptchaSmsHandler implements CaptchaSmsHandler {
     }
 
     @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);
-        return captcha != null && captcha.check(token, mobile, code);
+        return captcha != null && captcha.check(id, mobile, code);
     }
 
     @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) {
             RedisContextHolder.getDefaultTemplate().delete(this.key(mobile));
         }