Forráskód Böngészése

修改付款码检验范围

july 4 éve
szülő
commit
006449f0f1

+ 30 - 20
ldt-core/src/main/java/org/springblade/common/utils/OtpUtils.java

@@ -9,6 +9,7 @@ import javax.crypto.spec.SecretKeySpec;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.math.BigInteger;
 import java.security.GeneralSecurityException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
@@ -16,18 +17,26 @@ import java.util.Objects;
 
 /**
  * @author: lianghanqiang
- * @description:	TOP 一次性加密口令
+ * @description: TOP 一次性加密口令
  * @since: 8/2/21 -- 10:48 AM
  */
 public class OtpUtils {
-//	649957
+	//	649957
 	public static void main(String[] args) {
-		System.out.println(generateMyTOTP("1430417679637835778"));
+		Date date = new Date();
+		System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(date));
+		System.out.println(date.getTime());
+		System.out.println(generateMyTOTP("1430417679637835778", date.getTime()));
+		System.out.println("----------------------------------------");
+		date.setTime(date.getTime() + 60 * 1000);
+		System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(date));
+		System.out.println(date.getTime());
+		System.out.println(generateMyTOTP("1430417679637835778", date.getTime()));
 	}
 
 	/**
-	 * 	id变形常量
-	 * */
+	 * id变形常量
+	 */
 	private static final Long TRANSFORM_PARAMS = 95963L;
 
 	/**
@@ -76,15 +85,14 @@ public class OtpUtils {
 	 * @param id
 	 * @return String
 	 */
-	public static String generateMyTOTP(String id) {
-		Assert.notBlank(id,()-> new ServiceException(ResCode.ID_NOT_NULL));
-		long now = new Date().getTime();
+	public static String generateMyTOTP(String id, long now) {
+		Assert.notBlank(id, () -> new ServiceException(ResCode.ID_NOT_NULL));
+		//long now = new Date().getTime();
 		String time = Long.toHexString(timeFactor(now)).toUpperCase();
 		return generateTOTP(id + SECRET_KEY, time);
 	}
 
 
-
 	/**
 	 * 获取动态因子
 	 *
@@ -163,21 +171,23 @@ public class OtpUtils {
 
 
 	/**
-	 * 	校验口令
-	 * */
-	public static boolean validate(String id,String code) {
-		String s = generateMyTOTP(id);
-		return Objects.equals(s,code);
+	 * 校验口令
+	 */
+	public static boolean validate(String id, String code) {
+		Date date = new Date();
+		String current = generateMyTOTP(id, date.getTime());
+		String before = generateMyTOTP(id, date.getTime() + 60 * 1000);
+		return Objects.equals(current, code) || Objects.equals(before, code);
 	}
 
 
 	/**
-	 * 	根据code获取用户Id
-	 * */
-	public static Map<String,String> decodeParams(String code) {
-		return new HashMap<String,String>(){{
-			put(PARAMS_ID,code.substring(0,19));
-			put(PARAMS_SECRET,code.substring(code.length()-6));
+	 * 根据code获取用户Id
+	 */
+	public static Map<String, String> decodeParams(String code) {
+		return new HashMap<String, String>() {{
+			put(PARAMS_ID, code.substring(0, 19));
+			put(PARAMS_SECRET, code.substring(code.length() - 6));
 		}};
 	}
 

+ 5 - 1
ldt-core/src/main/java/org/springblade/ldt/bills/entity/FrozenRec.java

@@ -66,11 +66,15 @@ public class FrozenRec extends BaseEntity {
 	 */
 	@ApiModelProperty(value = "冻结用户id")
 	private Long userId;
-
 	/**
 	 * 冻结状态
 	 */
 	@ApiModelProperty(value = "冻结状态")
 	private FrozenSatus frozenSatus;
+	/**
+	 * 冻结用户名
+	 */
+	@ApiModelProperty(value = "冻结用户名")
+	private String userName;
 
 }

+ 1 - 0
ldt-core/src/main/java/org/springblade/ldt/bills/service/impl/FrozenRecServiceImpl.java

@@ -55,6 +55,7 @@ public class FrozenRecServiceImpl extends BaseServiceImpl<FrozenRecMapper, Froze
 		FrozenRec frozenRec = new FrozenRec();
 		frozenRec.setFrozenNum(handlePrice);
 		frozenRec.setUserId(user.getId());
+		frozenRec.setUserName(user.getNickName());
 		frozenRec.setTradeNo(bills.getId());
 		frozenRec.setFrozenType(type);
 		frozenRec.setStatus(1);