From 4af15e05f3d44d35470b7618948d61021555b747 Mon Sep 17 00:00:00 2001 From: MrZhai Date: Fri, 11 Mar 2022 14:09:55 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0redis=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E9=AA=8C=E8=AF=81=E7=A0=81=E5=A4=B1=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/auth/RegisterController.java | 56 +++++++++---------- .../com/glxp/sale/admin/util/Constant.java | 5 ++ .../main/resources/application-pro.properties | 17 ++++++ 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/controller/auth/RegisterController.java b/api-admin/src/main/java/com/glxp/sale/admin/controller/auth/RegisterController.java index e1c06ca..8ee7ee7 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/controller/auth/RegisterController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/controller/auth/RegisterController.java @@ -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()); } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/util/Constant.java b/api-admin/src/main/java/com/glxp/sale/admin/util/Constant.java index 11b6f43..fd2e657 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/util/Constant.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/util/Constant.java @@ -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:"; + } diff --git a/api-admin/src/main/resources/application-pro.properties b/api-admin/src/main/resources/application-pro.properties index c43c13f..338d6fe 100644 --- a/api-admin/src/main/resources/application-pro.properties +++ b/api-admin/src/main/resources/application-pro.properties @@ -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 \ No newline at end of file