|
@@ -1,7 +1,10 @@
|
|
|
package com.tianhu.system.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.keao.tianhu.core.entity.R;
|
|
|
+import com.tianhu.common.core.utils.CommonUtil;
|
|
|
+import com.tianhu.common.core.utils.DateUtils;
|
|
|
import com.tianhu.common.core.web.controller.BaseController;
|
|
|
import com.tianhu.common.core.web.domain.AjaxResult;
|
|
|
import com.tianhu.common.log.annotation.Log;
|
|
@@ -9,6 +12,8 @@ import com.tianhu.common.log.enums.BusinessType;
|
|
|
import com.tianhu.common.redis.common.RedisUtils;
|
|
|
import com.tianhu.system.common.IMessageUtilsService;
|
|
|
import com.tianhu.system.common.ValidateCodeService;
|
|
|
+import com.tianhu.system.domain.PubVerifyCode;
|
|
|
+import com.tianhu.system.service.IPubVerifyCodeService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -16,8 +21,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 短信
|
|
@@ -33,6 +43,8 @@ public class MessageController extends BaseController
|
|
|
private IMessageUtilsService iMessageUtilsService;
|
|
|
@Autowired
|
|
|
private ValidateCodeService validateCodeService;
|
|
|
+ @Autowired
|
|
|
+ private IPubVerifyCodeService iPubVerifyCodeService;
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -54,6 +66,44 @@ public class MessageController extends BaseController
|
|
|
@Transactional(rollbackFor=Exception.class)
|
|
|
@PostMapping("/sendShortMessage")
|
|
|
public AjaxResult sendShortMessage(@RequestBody Map<String, String> requestBody) throws Exception {
|
|
|
+ List<Map<String,String>> resultList = new ArrayList<>();
|
|
|
+ //手机号
|
|
|
+ String phone = requestBody.get("phone");
|
|
|
+ //查询五分钟之内发送验证码的次数
|
|
|
+ LambdaQueryWrapper<PubVerifyCode> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(PubVerifyCode::getPvcPhone,phone);
|
|
|
+ List<PubVerifyCode> list = iPubVerifyCodeService.findPubVerifyCodes(queryWrapper);
|
|
|
+ //获取时间差
|
|
|
+ for (PubVerifyCode pubVerifyCode : list){
|
|
|
+ //最后发送时间
|
|
|
+ Date date = pubVerifyCode.getPvcLastTime();
|
|
|
+ Instant instantDate = date.toInstant();
|
|
|
+ ZoneId zoneIdDate = ZoneId.systemDefault();
|
|
|
+ LocalDateTime localDate = instantDate.atZone(zoneIdDate).toLocalDateTime();
|
|
|
+ //当前时间
|
|
|
+ Date time = DateUtils.getNowDate();
|
|
|
+ Instant instantTime = time.toInstant();
|
|
|
+ ZoneId zoneIdTime = ZoneId.systemDefault();
|
|
|
+ LocalDateTime localTime = instantTime.atZone(zoneIdTime).toLocalDateTime();
|
|
|
+ //算出时间差
|
|
|
+ Duration differenceValue = Duration.between(localDate, localTime);
|
|
|
+ Long seconds = differenceValue.getSeconds();
|
|
|
+ BigInteger cond = BigInteger.valueOf(seconds);
|
|
|
+ BigInteger big = BigInteger.valueOf(Long.valueOf("60"));
|
|
|
+ BigInteger ans = cond.divide(big);
|
|
|
+ String rence = String.valueOf(ans);
|
|
|
+ //时间差
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(rence);
|
|
|
+ BigDecimal tow = new BigDecimal("5");
|
|
|
+ if(tow.compareTo(bigDecimal) > -1){
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("diffrence", "五分钟之内存在");
|
|
|
+ resultList.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(resultList.size() > 3){
|
|
|
+ throw new Exception("服务器繁忙,请半小时后再获取验证码");
|
|
|
+ }
|
|
|
validateCodeService.checkCapcha(requestBody.get("imgCode"), requestBody.get("uuid"), false);
|
|
|
String random = iMessageUtilsService.genRandomNum(6);
|
|
|
Map<String, String> param = new HashMap<>();
|