From d615fc515fc52d6ed970c11d59a017e48de4be32 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Tue, 16 Jun 2026 16:43:58 +0800
Subject: [PATCH] 1
---
src/main/java/com/nq/service/impl/UserServiceImpl.java | 75 ++++++++++++++++++++++---------------
1 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/UserServiceImpl.java b/src/main/java/com/nq/service/impl/UserServiceImpl.java
index 609ffcd..4305c74 100644
--- a/src/main/java/com/nq/service/impl/UserServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserServiceImpl.java
@@ -120,15 +120,25 @@
return ServerResponse.createByErrorMsg("注册失败, 参数不能为空");
}
+ if (!com.nq.utils.PhoneUtil.isValidChinaMobile(phone)) {
+ return ServerResponse.createByErrorMsg("注册失败, 手机号格式不正确");
+ }
+ phone = com.nq.utils.PhoneUtil.normalizeChinaMobile(phone);
-// String keys = "AliyunSmsCode:" + phone;
-// String redis_yzm = RedisShardedPoolUtils.get(keys);
-//
-// log.info("redis_yzm = {},yzmCode = {}", redis_yzm, yzmCode);
-// if (!yzmCode.equals(redis_yzm) && !"6666".equals(yzmCode)) {
-// return ServerResponse.createByErrorMsg("注册失败, 验证码错误");
-// }
+ if (com.nq.utils.sms.SmsConstants.isVerifyEnabled()) {
+ if (StringUtils.isBlank(yzmCode)) {
+ return ServerResponse.createByErrorMsg("注册失败, 请输入短信验证码");
+ }
+ String keys = com.nq.utils.sms.SmsConstants.SMS_CODE_PREFIX + phone;
+ String redis_yzm = RedisShardedPoolUtils.get(keys);
+
+ log.info("redis_yzm = {},yzmCode = {}", redis_yzm, yzmCode);
+ if (StringUtils.isBlank(redis_yzm) || !yzmCode.equals(redis_yzm)) {
+ return ServerResponse.createByErrorMsg("注册失败, 验证码错误或已过期");
+ }
+ RedisShardedPoolUtils.del(keys);
+ }
AgentUser agentUser = this.iAgentUserService.findByCode(agentCode);
if (agentUser == null) {
@@ -157,19 +167,10 @@
user.setIsActive(Integer.valueOf(0));
user.setRegTime(new Date());
-// String uip = IpUtils.getIp(request);
-// user.setRegIp(uip);
-// // IP地址查询改为异步处理,避免阻塞注册接口
-// final String finalUip = uip;
-// final String finalPhone = phone;
-// new Thread(() -> {
-// try {
-// String uadd = JuheIpApi.ip2Add(finalUip);
-// log.info("用户注册IP地址查询完成 手机 {} , ip = {} 地址 = {}", finalPhone, finalUip, uadd);
-// } catch (Exception e) {
-// log.error("IP地址查询异常", e);
-// }
-// }).start();
+ String uip = IpUtils.getIp(request);
+ user.setRegIp(StringUtils.isBlank(uip) ? "--" : uip);
+ String uadd = JuheIpApi.ip2Add(uip);
+ user.setRegAddress(StringUtils.isBlank(uadd) ? "未知" : uadd);
user.setIsLogin(Integer.valueOf(0));
@@ -195,7 +196,7 @@
String newAgentCode = generateUniqueAgentCode();
agentUser.setAgentCode(newAgentCode);
iAgentUserService.updateAgentCode(agentUser);
- log.info("用户注册成功 手机 {} , ip = {}", phone, "123123");
+ log.info("用户注册成功 手机 {} , ip = {}", phone, uip);
return ServerResponse.createBySuccessMsg("注册成功.请登录");
}
return ServerResponse.createBySuccessMsg("注册出错, 请重试");
@@ -219,6 +220,10 @@
if (StringUtils.isBlank(phone) || StringUtils.isBlank(userPwd)) {
return ServerResponse.createByErrorMsg("手机号和密码不能为空");
}
+ if (!com.nq.utils.PhoneUtil.isValidChinaMobile(phone)) {
+ return ServerResponse.createByErrorMsg("手机号格式不正确");
+ }
+ phone = com.nq.utils.PhoneUtil.normalizeChinaMobile(phone);
userPwd = SymmetricCryptoUtil.encryptPassword(userPwd);
User user = this.userMapper.login(phone, userPwd);
if (user != null) {
@@ -442,6 +447,10 @@
public ServerResponse checkPhone(String phone) {
+ if (!com.nq.utils.PhoneUtil.isValidChinaMobile(phone)) {
+ return ServerResponse.createByErrorMsg("手机号格式不正确");
+ }
+ phone = com.nq.utils.PhoneUtil.normalizeChinaMobile(phone);
User user = this.userMapper.findByPhone(phone);
if (user != null) {
return ServerResponse.createBySuccessMsg("用户已存在");
@@ -452,19 +461,25 @@
public ServerResponse updatePwd(String phone, String code, String newPwd) {
- if (StringUtils.isBlank(phone) ||
- StringUtils.isBlank(code) ||
- StringUtils.isBlank(newPwd)) {
+ if (StringUtils.isBlank(phone) || StringUtils.isBlank(newPwd)) {
return ServerResponse.createByErrorMsg("参数不能为空");
}
+ if (com.nq.utils.sms.SmsConstants.isVerifyEnabled() && StringUtils.isBlank(code)) {
+ return ServerResponse.createByErrorMsg("参数不能为空");
+ }
+ if (!com.nq.utils.PhoneUtil.isValidChinaMobile(phone)) {
+ return ServerResponse.createByErrorMsg("手机号格式不正确");
+ }
+ phone = com.nq.utils.PhoneUtil.normalizeChinaMobile(phone);
+ if (com.nq.utils.sms.SmsConstants.isVerifyEnabled()) {
+ String keys = "AliyunSmsCode:" + phone;
+ String redis_yzm = RedisShardedPoolUtils.get(keys);
- String keys = "AliyunSmsCode:" + phone;
- String redis_yzm = RedisShardedPoolUtils.get(keys);
-
- log.info("redis_yzm = {} , code = {}", redis_yzm, code);
- if (!code.equals(redis_yzm)) {
- return ServerResponse.createByErrorMsg("修改密码失败,验证码错误");
+ log.info("redis_yzm = {} , code = {}", redis_yzm, code);
+ if (!code.equals(redis_yzm)) {
+ return ServerResponse.createByErrorMsg("修改密码失败,验证码错误");
+ }
}
User user = this.userMapper.findByPhone(phone);
--
Gitblit v1.9.3