修改实名认证校验
This commit is contained in:
@@ -34,8 +34,9 @@ public class ApiAccessLimitUtil {
|
||||
|
||||
/**
|
||||
* 默认 当月5次
|
||||
* @param id 唯一值
|
||||
* @param key 接口名称 sys:limit:接口名称
|
||||
*
|
||||
* @param id 唯一值
|
||||
* @param key 接口名称 sys:limit:接口名称
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAccessAllowed(String id, String key) {
|
||||
@@ -58,9 +59,10 @@ public class ApiAccessLimitUtil {
|
||||
|
||||
/**
|
||||
* 默认月 month/月/自然月
|
||||
* @param id 唯一值
|
||||
* @param key 接口名称 sys:limit:接口名称
|
||||
* @param count 次数限制
|
||||
*
|
||||
* @param id 唯一值
|
||||
* @param key 接口名称 sys:limit:接口名称
|
||||
* @param count 次数限制
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAccessAllowed(String id, String key, Integer count) {
|
||||
@@ -82,9 +84,10 @@ public class ApiAccessLimitUtil {
|
||||
|
||||
/**
|
||||
* 默认 5次
|
||||
*
|
||||
* @param id 唯一值
|
||||
* @param key 接口名称 sys:limit:接口名称
|
||||
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
||||
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAccessAllowed(String id, String key, String timeFormat) {
|
||||
@@ -108,7 +111,7 @@ public class ApiAccessLimitUtil {
|
||||
* @param id 唯一值
|
||||
* @param key 接口名称 sys:limit:接口名称
|
||||
* @param count 次数限制
|
||||
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
||||
* @param timeFormat day/天/自然天 week/周/本周日 month/月/自然月 year/年/自然年
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAccessAllowed(String id, String key, Integer count, String timeFormat) {
|
||||
@@ -118,7 +121,7 @@ public class ApiAccessLimitUtil {
|
||||
long expireAt;
|
||||
if (StrUtil.isBlank(timeFormat)) {
|
||||
expireAt = count;
|
||||
}else {
|
||||
} else {
|
||||
// 根据不同时间周期设置过期时间并初始化访问次数为1
|
||||
expireAt = calculateExpireAt(timeFormat);
|
||||
}
|
||||
@@ -133,14 +136,40 @@ public class ApiAccessLimitUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean getCertAuthIsAccessAllowed(String id, String key, Integer count) {
|
||||
String redisKey = generateRedisKey(key, id);
|
||||
Object countObj = redisUtils.get(redisKey);
|
||||
if (countObj == null) {
|
||||
return true;
|
||||
}
|
||||
return Integer.parseInt(countObj.toString()) < count;
|
||||
}
|
||||
|
||||
public static void setCertAuthIsAccessAllowed(String id, String key, Integer count, String timeFormat) {
|
||||
String redisKey = generateRedisKey(key, id);
|
||||
Object countObj = redisUtils.get(redisKey);
|
||||
if (countObj == null) {
|
||||
long expireAt;
|
||||
if (StrUtil.isBlank(timeFormat)) {
|
||||
expireAt = count;
|
||||
} else {
|
||||
// 根据不同时间周期设置过期时间并初始化访问次数为1
|
||||
expireAt = calculateExpireAt(timeFormat);
|
||||
}
|
||||
redisUtils.set(redisKey, 1, expireAt);
|
||||
} else {
|
||||
redisUtils.incr(redisKey);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeKey(String id, String key) {
|
||||
String redisKey = generateRedisKey(key, id);
|
||||
redisUtils.delete(redisKey);
|
||||
}
|
||||
|
||||
|
||||
public static<T> T runFunAndCheckKey(Supplier<T> supplier, String lockKey, Integer seconds) {
|
||||
try{
|
||||
public static <T> T runFunAndCheckKey(Supplier<T> supplier, String lockKey, Integer seconds) {
|
||||
try {
|
||||
// 创建线程id, 用作判断
|
||||
String clientId = UUID.randomUUID().toString();
|
||||
// 设置分布式锁
|
||||
@@ -154,12 +183,12 @@ public class ApiAccessLimitUtil {
|
||||
lock = Boolean.TRUE.equals(redisUtils.setIfAbsent(lockKey, clientId, seconds));
|
||||
}
|
||||
return supplier.get();
|
||||
} catch (RuntimeException e){
|
||||
} catch (RuntimeException e) {
|
||||
log.error("执行出错", e);
|
||||
throw e;
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally{
|
||||
} finally {
|
||||
redisUtils.delete(lockKey);
|
||||
}
|
||||
}
|
||||
@@ -189,7 +218,7 @@ public class ApiAccessLimitUtil {
|
||||
Date now = DateUtil.beginOfDay(DateUtil.date());
|
||||
Date expireDate = null;
|
||||
if ("day".equals(timePeriod)) {
|
||||
expireDate = DateUtil.endOfDay(now);
|
||||
expireDate = DateUtil.endOfDay(now);
|
||||
} else if ("week".equals(timePeriod)) {
|
||||
expireDate = DateUtil.endOfWeek(now);
|
||||
} else if ("month".equals(timePeriod)) {
|
||||
|
||||
Reference in New Issue
Block a user