|
@@ -14,11 +14,13 @@ import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
@@ -40,22 +42,42 @@ public class TMessageCodeController {
|
|
@Autowired
|
|
@Autowired
|
|
TMessageCodeService tMessageCodeService;
|
|
TMessageCodeService tMessageCodeService;
|
|
|
|
|
|
|
|
+ @ApiOperation(value = "获取上次发送验证码的时间")
|
|
|
|
+ @GetMapping("/getLastSendTime")
|
|
|
|
+ public ResponseModel<?> getLastSendTime(String phoneOrEmail) {
|
|
|
|
+ if (StringUtils.isEmpty(phoneOrEmail)) {
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0100, "手机号或邮箱为空!");
|
|
|
|
+ }
|
|
|
|
+ // 查询该 手机号/邮箱 最后一次发送验证码的时间
|
|
|
|
+ Date lastSendTime = tMessageCodeService.getLastSendTime(phoneOrEmail);
|
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+// String format = sdf.format(lastSendTime);
|
|
|
|
+// return R.ok(format);
|
|
|
|
+ return R.ok(lastSendTime); // 返回时间戳
|
|
|
|
+ }
|
|
|
|
+
|
|
@ApiOperation(value = "发送注册验证码")
|
|
@ApiOperation(value = "发送注册验证码")
|
|
@PostMapping("/sentRegisterCode")
|
|
@PostMapping("/sentRegisterCode")
|
|
public ResponseModel<?> sentRegisterCode(String ifForeign, String phoneOrEmail) {
|
|
public ResponseModel<?> sentRegisterCode(String ifForeign, String phoneOrEmail) {
|
|
|
|
+ if (StringUtils.isEmpty(phoneOrEmail)) {
|
|
|
|
+ // 说明参数为空
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0100, "手机号或邮箱为空!");
|
|
|
|
+ }
|
|
|
|
+ // 查询该 手机号/邮箱 最后一次发送验证码的时间
|
|
|
|
+ Date lastSendTime = tMessageCodeService.getLastSendTime(phoneOrEmail);
|
|
|
|
+ long lastTime = lastSendTime.getTime();
|
|
|
|
+ long currentTime = new Date().getTime();
|
|
|
|
+ if (currentTime - lastTime < 10 * 60 * 1000) {
|
|
|
|
+ return R.fail("请勿频繁发送,10分钟后再试");
|
|
|
|
+ }
|
|
// 如果是国内
|
|
// 如果是国内
|
|
if (ifForeign.equals("0")) {
|
|
if (ifForeign.equals("0")) {
|
|
- if (StringUtils.isEmpty(phoneOrEmail)) {
|
|
|
|
- // 说明参数为空
|
|
|
|
- return R.fail(ResponseCodesEnum.A0100, "手机号或邮箱为空!");
|
|
|
|
- }
|
|
|
|
// 定义国内手机号和邮箱的正则表达式
|
|
// 定义国内手机号和邮箱的正则表达式
|
|
String phoneReg = "^1[3-9]\\d{9}$";
|
|
String phoneReg = "^1[3-9]\\d{9}$";
|
|
String emailReg = "^[a-zA-Z0-9_-]+([a-zA-Z0-9_.-]*[a-zA-Z0-9])*@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
|
|
String emailReg = "^[a-zA-Z0-9_-]+([a-zA-Z0-9_.-]*[a-zA-Z0-9])*@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
|
|
|
|
|
|
// 判断 phoneOrEmail 是手机号还是邮箱
|
|
// 判断 phoneOrEmail 是手机号还是邮箱
|
|
if (Pattern.matches(phoneReg, phoneOrEmail)) {
|
|
if (Pattern.matches(phoneReg, phoneOrEmail)) {
|
|
- System.out.println("这是一个手机号");
|
|
|
|
//检测是否已有手机号注册
|
|
//检测是否已有手机号注册
|
|
LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
query.eq(TAdmin::getPhone, phoneOrEmail);
|
|
query.eq(TAdmin::getPhone, phoneOrEmail);
|
|
@@ -67,7 +89,6 @@ public class TMessageCodeController {
|
|
String result = tMessageCodeService.sentMessage("0", phoneOrEmail);
|
|
String result = tMessageCodeService.sentMessage("0", phoneOrEmail);
|
|
return R.ok(result);
|
|
return R.ok(result);
|
|
} else if (Pattern.matches(emailReg, phoneOrEmail)) {
|
|
} else if (Pattern.matches(emailReg, phoneOrEmail)) {
|
|
- System.out.println("这是一个邮箱地址");
|
|
|
|
// 检测是否已有邮箱注册
|
|
// 检测是否已有邮箱注册
|
|
LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
query.eq(TAdmin::getEmail, phoneOrEmail);
|
|
query.eq(TAdmin::getEmail, phoneOrEmail);
|
|
@@ -84,9 +105,9 @@ public class TMessageCodeController {
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// 海外
|
|
// 海外
|
|
- if (StringUtils.isEmpty(phoneOrEmail)) {
|
|
|
|
- return R.fail(ResponseCodesEnum.A0100, "邮箱为空!");
|
|
|
|
- }
|
|
|
|
|
|
+// if (StringUtils.isEmpty(phoneOrEmail)) {
|
|
|
|
+// return R.fail(ResponseCodesEnum.A0100, "邮箱为空!");
|
|
|
|
+// }
|
|
//检测是否已有邮箱注册
|
|
//检测是否已有邮箱注册
|
|
LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
query.eq(TAdmin::getEmail, phoneOrEmail);
|
|
query.eq(TAdmin::getEmail, phoneOrEmail);
|