Administrator 2 năm trước cách đây
mục cha
commit
d84e33b947

+ 2 - 0
src/main/java/com/xiesx/fastboot/core/body/cfg/HeaderCfg.java

@@ -19,6 +19,8 @@ public class HeaderCfg implements WebMvcConfigurer {
 
     public static final String DEVICE = "device";
 
+    public static final String CURRENT_TIME = "currentTime";
+
     public static final String OSVERSION = "osVersion";
 
     public static final String APVERSION = "apVersion";

+ 4 - 0
src/main/java/com/xiesx/fastboot/core/body/handle/HeaderArgumentResolver.java

@@ -34,6 +34,10 @@ public class HeaderArgumentResolver implements HandlerMethodArgumentResolver {
         if (ObjectUtils.isNotEmpty(device)) {
             builder.device(device);
         }
+        String currentTime = request.getHeader(HeaderCfg.CURRENT_TIME);
+        if (ObjectUtils.isNotEmpty(currentTime)) {
+            builder.currentTime(currentTime);
+        }
         String osVersion = request.getHeader(HeaderCfg.OSVERSION);
         if (ObjectUtils.isNotEmpty(osVersion)) {
             builder.osVersion(osVersion);

+ 10 - 0
src/main/java/com/xiesx/fastboot/utils/DateUtils.java

@@ -64,6 +64,16 @@ public class DateUtils {
         return date;
     }
 
+    /**
+     * 时间偏差验证
+     * @param checkInTime 需要验证的时间
+     * @param deviationValue  偏差值 (毫秒)
+     * @return
+     */
+    public static boolean dateTimeDeviation(long checkInTime, long deviationValue){
+        return Math.abs(System.currentTimeMillis() - checkInTime) > deviationValue;
+    }
+
     // point time
 
     /**