1.增加redis配置,修复用户注册手机验证码失效问题

master
MrZhai 3 years ago
parent 1f81fb1c79
commit 4af15e05f3

@ -24,12 +24,12 @@ import com.glxp.sale.admin.service.auth.CustomerInfoService;
import com.glxp.sale.admin.service.auth.UserRegisterService;
import com.glxp.sale.admin.service.auth.impl.CustomerContactService;
import com.glxp.sale.admin.service.basic.BasicUnitMaintainService;
import com.glxp.sale.admin.service.info.AliCertService;
import com.glxp.sale.admin.service.info.ApilogService;
import com.glxp.sale.admin.service.info.CompanyService;
import com.glxp.sale.admin.service.info.SetupService;
import com.glxp.sale.admin.service.param.SystemParamConfigService;
import com.glxp.sale.admin.util.Constant;
import com.glxp.sale.admin.util.DateUtil;
import com.glxp.sale.admin.util.RedisUtil;
import com.glxp.sale.admin.util.UuidUtils;
import com.glxp.sale.common.enums.ResultEnum;
import com.glxp.sale.common.res.BaseResponse;
@ -68,21 +68,17 @@ public class RegisterController {
private CustomerInfoService customerInfoService;
@Resource
private CustomerContactService customerContactService;
@Resource
private SetupService setupService;
@Resource
private CompanyService companyService;
@Resource
private AliCertService aliCertService;
@Resource
ApilogService apilogService;
@Resource
private BasicUnitMaintainService basicUnitMaintainService;
@Resource
private SystemParamConfigService systemParamConfigService;
@Resource
RedisUtil redisUtil;
@AuthRuleAnnotation("")
@GetMapping("salewarehouse/register/list")
@ -130,14 +126,14 @@ public class RegisterController {
json.put("memPhone", checkCodeRequest.getPhoneNum());
json.put("code", mobile_code);
json.put("createTime", System.currentTimeMillis());
// 将认证码存入SESSION
httpSession.setAttribute("code", json);
log.info(httpSession.getId() + "---" + httpSession);
//验证码存入redis中
redisUtil.set(Constant.CAPTCHAS + checkCodeRequest.getPhoneNum(), json, 300L);
return ResultVOUtils.success("发送成功" + " " + mobile_code);
} else
return ResultVOUtils.error(500, "验证码发送失败");
}
@GetMapping("salewarehouse/register/checkCompany")
public BaseResponse checkCompany(@RequestParam("companyName") String companyName) {
if (StringUtils.isBlank(companyName)) return ResultVOUtils.error(ResultEnum.DATA_ERROR, "企业名称不能为空");
@ -149,6 +145,7 @@ public class RegisterController {
}
}
@GetMapping("salewarehouse/register/getRegisterConfig")
public BaseResponse getRegisterConfig() {
@ -198,23 +195,22 @@ public class RegisterController {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
log.info(httpSession.getId());
// JSONObject userCode = (JSONObject) httpSession.getAttribute("code");
// if (userCode == null) {
// return ResultVOUtils.error(500, "验证码已失效,请重新获取");
// }
// long lastTime = userCode.getLong("createTime");
// int checkCode = (Integer) userCode.get("code");
// String phoneNum = userCode.getString("memPhone");
// if ((System.currentTimeMillis() - lastTime) > 1000 * 60 * 5) {
// return ResultVOUtils.error(500, "验证码已过期,请重新获取");
// }
// if (checkCode != userRegisterEntity.getCheckCode()) {
// return ResultVOUtils.error(500, "验证码错误,请重新获取");
// }
// if (!phoneNum.equals(userRegisterEntity.getMobile())) {
// return ResultVOUtils.error(500, "手机号与获取验证码不一致");
// }
JSONObject userCode = JSONObject.parseObject(String.valueOf(redisUtil.get(Constant.CAPTCHAS + userRegisterEntity.getMobile())));
if (userCode == null) {
return ResultVOUtils.error(500, "验证码已失效,请重新获取");
}
long lastTime = userCode.getLong("createTime");
int checkCode = (Integer) userCode.get("code");
String phoneNum = userCode.getString("memPhone");
if ((System.currentTimeMillis() - lastTime) > 1000 * 60 * 5) {
return ResultVOUtils.error(500, "验证码已过期,请重新获取");
}
if (checkCode != userRegisterEntity.getCheckCode()) {
return ResultVOUtils.error(500, "验证码错误,请重新获取");
}
if (!phoneNum.equals(userRegisterEntity.getMobile())) {
return ResultVOUtils.error(500, "手机号与获取验证码不一致");
}
boolean isExitPhone = userRegisterService.isExit(userRegisterEntity.getMobile());
if (isExitPhone) {
return ResultVOUtils.error(500, "该手机号已被注册");
@ -239,6 +235,8 @@ public class RegisterController {
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
//注册成功,删除验证码缓存
redisUtil.del(Constant.CAPTCHAS + userRegisterEntity.getMobile());
return ResultVOUtils.success(userRegisterEntity.getUserName());
}

@ -7,5 +7,10 @@ public class Constant {
public static final String dlThrOrders = "THR_DOWNLOAD_ORDERS";
public static final String dlThrCorps = "THR_DOWNLOAD_CORPS";
/**
*
*/
public static final String CAPTCHAS = "captchas:";
}

@ -51,3 +51,20 @@ STOCK_PRINT_POST=http://139.159.187.130/UDI_WMS_MC/udiwms/stockprint/post
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
spring.main.allow-bean-definition-overriding=true
# Redis \u6570\u636E\u5E93\u7F16\u53F7
spring.redis.database=4
# Redis \u670D\u52A1\u5668IP
spring.redis.host=127.0.0.1
# Redis \u7AEF\u53E3\u53F7
spring.redis.port=6379
# Redis \u5BC6\u7801
spring.redis.password=
#\u6700\u5927\u6D3B\u8DC3\u8FDE\u63A5\u6570
spring.redis.jedis.pool.max-active=8
#\u6700\u5927\u7B49\u5F85\u65F6\u95F4
spring.redis.jedis.pool.max-wait=-1
#\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5\u6570
spring.redis.jedis.pool.max-idle=8
#\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5\u6570
spring.redis.jedis.pool.min-idle=0
Loading…
Cancel
Save