|
|
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
@@ -181,6 +182,7 @@ public class GroupRelationController {
|
|
|
DateTime now = DateTime.now();
|
|
|
Integer count = doubleVerifyRecordMapper.selectCount(Wrappers.lambdaQuery(DoubleVerifyClickRecord.class)
|
|
|
.eq(DoubleVerifyClickRecord::getUserId, userId)
|
|
|
+ .eq(DoubleVerifyClickRecord::getRelationId, relationId)
|
|
|
.eq(DoubleVerifyClickRecord::getAccountId, groupsRelationView.getAccountId())
|
|
|
.between(DoubleVerifyClickRecord::getCreatedTime, DateUtil.beginOfMonth(now), DateUtil.endOfMonth(now)));
|
|
|
SysConfig double_verify_num = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.ACCOUNT_DOUBLE_VERIFY_KEY));
|
|
|
@@ -190,9 +192,9 @@ public class GroupRelationController {
|
|
|
}
|
|
|
if (count >= num) throw BusinessRuntimeException.getInstance("获取双重验证码次数上限");
|
|
|
int second = now.second();
|
|
|
- if (second < 30 && 30 - second < 18) {
|
|
|
+ if (second < 30 && 30 - second < 3) {
|
|
|
ThreadUtil.sleep(30 - second + 1, TimeUnit.SECONDS);
|
|
|
- } else if (second > 30 && 60 - second < 18) {
|
|
|
+ } else if (second > 30 && 60 - second < 3) {
|
|
|
ThreadUtil.sleep(60 - second + 1, TimeUnit.SECONDS);
|
|
|
}
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
@@ -210,9 +212,57 @@ public class GroupRelationController {
|
|
|
doubleVerifyClickRecord.setAccount(groupsRelationView.getTripsAccount());
|
|
|
doubleVerifyClickRecord.setSkuId(groupsRelationView.getSkuId());
|
|
|
doubleVerifyRecordMapper.insert(doubleVerifyClickRecord);
|
|
|
+
|
|
|
+ redisService.set(String.format("%s-%s", userId, sb.toString()), 0, 60 * 60l);
|
|
|
+ redisService.set(String.format("%s/%s", userId, sb.toString()), groupsRelationView.getApiSecret(), 60 * 60l);
|
|
|
} catch (Exception e) {
|
|
|
throw BusinessRuntimeException.getInstance("获取双重验证码错误,请联系客服");
|
|
|
}
|
|
|
+ JSONObject re = new JSONObject();
|
|
|
+ re.putOpt("code", sb.toString());
|
|
|
+ int nowSecond = DateTime.now().second();
|
|
|
+ int time = 0;
|
|
|
+ if (nowSecond < 30) {
|
|
|
+ time = 30 - nowSecond;
|
|
|
+ } else {
|
|
|
+ time = 60 - nowSecond;
|
|
|
+ }
|
|
|
+ re.putOpt("time", time);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(re.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新验证码
|
|
|
+ */
|
|
|
+ @GetMapping("/refresh/code")
|
|
|
+ public Result<String> refreshCode(String code) {
|
|
|
+ long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
+ String key = String.format("%s-%s", userId, code);
|
|
|
+ String apiSecretKey = String.format("%s/%s", userId, code);
|
|
|
+ Object value = redisService.get(key);
|
|
|
+ if (value == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请重新获取双重验证码");
|
|
|
+ }
|
|
|
+ Integer refreshNum = Integer.parseInt(value.toString());
|
|
|
+ if (refreshNum >= 3) {
|
|
|
+ redisService.del(key);
|
|
|
+ redisService.del(apiSecretKey);
|
|
|
+ throw BusinessRuntimeException.getInstance("刷新次数已达到3次,请重新获取验证码");
|
|
|
+ }
|
|
|
+ String apiSecret = redisService.getStr(apiSecretKey);
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ try {
|
|
|
+ long c = GoogleGenerator.getCode(apiSecret, DateTime.now().getTime());
|
|
|
+ sb.append(c);
|
|
|
+ while (sb.length() < 6) {
|
|
|
+ sb.insert(0, 0);
|
|
|
+ }
|
|
|
+ redisService.incr(key, 1l);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw BusinessRuntimeException.getInstance("刷新双重验证码错误,请联系客服");
|
|
|
+ }
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(sb.toString());
|
|
|
}
|
|
|
+
|
|
|
}
|