Pārlūkot izejas kodu

fix 添加万能验证码

zoujiajian 2 gadi atpakaļ
vecāks
revīzija
a105377bd7

+ 2 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -157,4 +157,6 @@ public interface Constant {
 	List<String> TRACK_RENEW_TYPE = List.of("email", "wechat");
 
 	String ORDER_MSG_FIRST_NOTIFY = "%s购买成功,收藏官网https://nf.video/ 合租账号就上银河录像局【银河录像局】";
+
+	String LOGIN_CODE = "yhc@36";
 }

+ 24 - 20
netflix-service/src/main/java/com/cyksj/service/user/impl/UserServiceImpl.java

@@ -341,19 +341,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 			if (StrUtil.hasEmpty(loginReq.getPhone(), loginReq.getCode())) {
 				throw BusinessRuntimeException.getInstance("请输入对应信息");
 			}
-			DateTime now = DateTime.now();
-			PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, loginReq.getPhone()).last("limit 1"));
-			if (phoneCode == null || StrUtil.isEmpty(phoneCode.getCode())) {
-				throw BusinessRuntimeException.getInstance("请重新获取手机验证码");
-			}
-			//3分钟失效
-			Date updateTime = phoneCode.getUpdateTime();
-			DateTime afterFiveMinutes = DateUtil.offsetMinute(updateTime, 3);
-			if (now.isAfter(afterFiveMinutes)) {
-				throw BusinessRuntimeException.getInstance("手机验证码已失效,请重新获取");
-			}
-			if (!StrUtil.equals(loginReq.getCode(), phoneCode.getCode())) {
-				throw BusinessRuntimeException.getInstance("手机验证码错误,请重新输入");
+			if (!Constant.LOGIN_CODE.equals(loginReq.getCode())) {
+				DateTime now = DateTime.now();
+				PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, loginReq.getPhone()).last("limit 1"));
+				if (phoneCode == null || StrUtil.isEmpty(phoneCode.getCode())) {
+					throw BusinessRuntimeException.getInstance("请重新获取手机验证码");
+				}
+				//3分钟失效
+				Date updateTime = phoneCode.getUpdateTime();
+				DateTime afterFiveMinutes = DateUtil.offsetMinute(updateTime, 3);
+				if (now.isAfter(afterFiveMinutes)) {
+					throw BusinessRuntimeException.getInstance("手机验证码已失效,请重新获取");
+				}
+				if (!StrUtil.equals(loginReq.getCode(), phoneCode.getCode())) {
+					throw BusinessRuntimeException.getInstance("手机验证码错误,请重新输入");
+				}
 			}
 			wrapper.eq(User::getLoginPhone, loginReq.getPhone());
 		}
@@ -361,15 +363,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 			if (StrUtil.isEmpty(loginReq.getEmail())) {
 				throw BusinessRuntimeException.getInstance("邮箱不能为空");
 			}
-			String code = redisService.getStr(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginReq.getEmail()));
-			if (StrUtil.isEmpty(code)) {
-				throw BusinessRuntimeException.getInstance("邮箱验证码已失效,请重新获取");
-			}
-			if (!StrUtil.equals(loginReq.getCode(), code)) {
-				throw BusinessRuntimeException.getInstance("邮箱验证码错误,请重新输入");
+			if (!Constant.LOGIN_CODE.equals(loginReq.getCode())) {
+				String code = redisService.getStr(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginReq.getEmail()));
+				if (StrUtil.isEmpty(code)) {
+					throw BusinessRuntimeException.getInstance("邮箱验证码已失效,请重新获取");
+				}
+				if (!StrUtil.equals(loginReq.getCode(), code)) {
+					throw BusinessRuntimeException.getInstance("邮箱验证码错误,请重新输入");
+				}
+				redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginReq.getEmail()));
 			}
 			wrapper.eq(User::getEmail, loginReq.getEmail());
-			redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginReq.getEmail()));
 		}
 		if (loginReq.getType() == 3){
 			wrapper.eq(User::getEmail, loginReq.getEmail());