Commit 051cd5fc by 陶湘宇 Committed by 284718418@qq.com

短信验证码5分钟保持一致

parent df3d1aee
...@@ -222,12 +222,16 @@ public class LoginController { ...@@ -222,12 +222,16 @@ public class LoginController {
// 6位随机数验证码 // 6位随机数验证码
try { try {
Integer code = (int) ((Math.random() * 9 + 1) * 100000);
if (phone == null || "".equals(phone)) { if (phone == null || "".equals(phone)) {
phone = entRegisterDto.getUsername(); phone = entRegisterDto.getUsername();
entRegisterDto.setPhone(phone); entRegisterDto.setPhone(phone);
} }
Integer code =Integer.parseInt(redisUtil.get(session.getId()+phone)!=null?redisUtil.get(session.getId()+phone).toString():"0");
if(code==0) {
code =(int) ((Math.random() * 9 + 1) * 100000);
redisUtil.set(session.getId()+phone, code,60*5);
}
List<Object> list = aliyunSMS.authCode(entRegisterDto, entRegisterDto.getTc(), code); List<Object> list = aliyunSMS.authCode(entRegisterDto, entRegisterDto.getTc(), code);
Integer useId = (Integer) list.get(0); Integer useId = (Integer) list.get(0);
JSONObject j = (JSONObject) list.get(1); JSONObject j = (JSONObject) list.get(1);
...@@ -257,10 +261,8 @@ public class LoginController { ...@@ -257,10 +261,8 @@ public class LoginController {
String message = j.getString("Message"); String message = j.getString("Message");
if ("OK".equals(message)) { if ("OK".equals(message)) {
redisUtil.set(phone, code);
// redisTemplate.set(phone, code); // redisTemplate.set(phone, code);
// redisTemplate.expire(phone, 60); // redisTemplate.expire(phone, 60);
return ResultUtil.data("发送验证码成功"); return ResultUtil.data("发送验证码成功");
} else { } else {
return ResultUtil.error("发送验证码失败"); return ResultUtil.error("发送验证码失败");
...@@ -289,12 +291,15 @@ public class LoginController { ...@@ -289,12 +291,15 @@ public class LoginController {
// 6位随机数验证码 // 6位随机数验证码
try { try {
Integer code = (int) ((Math.random() * 9 + 1) * 100000);
if (phone == null || "".equals(phone)) { if (phone == null || "".equals(phone)) {
phone = entRegisterDto.getUsername(); phone = entRegisterDto.getUsername();
entRegisterDto.setPhone(phone); entRegisterDto.setPhone(phone);
} }
Integer code =Integer.parseInt(redisUtil.get(session.getId()+phone)!=null?redisUtil.get(session.getId()+phone).toString():"0");
if(code==0) {
code =(int) ((Math.random() * 9 + 1) * 100000);
redisUtil.set(session.getId()+phone, code,60*5);
}
List<Object> list = aliyunSMS.authCode(entRegisterDto, entRegisterDto.getTc(), code); List<Object> list = aliyunSMS.authCode(entRegisterDto, entRegisterDto.getTc(), code);
Integer useId = (Integer) list.get(0); Integer useId = (Integer) list.get(0);
JSONObject j = (JSONObject) list.get(1); JSONObject j = (JSONObject) list.get(1);
...@@ -303,7 +308,6 @@ public class LoginController { ...@@ -303,7 +308,6 @@ public class LoginController {
String message = j.getString("Message"); String message = j.getString("Message");
if ("OK".equals(message)) { if ("OK".equals(message)) {
//session.setAttribute(phone, code); //session.setAttribute(phone, code);
redisUtil.set(phone, code,60*5);
return ResultUtil.data("发送验证码成功"); return ResultUtil.data("发送验证码成功");
} else { } else {
return ResultUtil.error("发送验证码失败"); return ResultUtil.error("发送验证码失败");
...@@ -328,7 +332,7 @@ public class LoginController { ...@@ -328,7 +332,7 @@ public class LoginController {
String code = entRegisterDto.getCode().toString(); String code = entRegisterDto.getCode().toString();
String codeRedis = redisUtil.get(phone) != null ? redisUtil.get(phone).toString() : ""; String codeRedis = redisUtil.get(session.getId()+phone) != null ? redisUtil.get(session.getId()+phone).toString() : "";
if(authentication_code !=null && !("").equals(authentication_code)) { if(authentication_code !=null && !("").equals(authentication_code)) {
if (authentication_code.equals(code)) { if (authentication_code.equals(code)) {
...@@ -368,7 +372,7 @@ public class LoginController { ...@@ -368,7 +372,7 @@ public class LoginController {
} else { } else {
if(authentication_code ==null || ("").equals(authentication_code) || !authentication_code.equals(code)) { if(authentication_code ==null || ("").equals(authentication_code) || !authentication_code.equals(code)) {
String codeRedis = redisUtil.get(phone) != null ? redisUtil.get(phone).toString() : ""; String codeRedis = redisUtil.get(session.getId()+phone) != null ? redisUtil.get(session.getId()+phone).toString() : "";
if (!code.equals(codeRedis)) { if (!code.equals(codeRedis)) {
return ResultUtil.error("短信验证码错误"); return ResultUtil.error("短信验证码错误");
} }
...@@ -403,7 +407,7 @@ public class LoginController { ...@@ -403,7 +407,7 @@ public class LoginController {
String code = entRegisterDto.getCode(); String code = entRegisterDto.getCode();
if (entRegisterDto.getPwUpdateType() != 2) { if (entRegisterDto.getPwUpdateType() != 2) {
String codeRedis = redisUtil.get(phone)!= null ? redisUtil.get(phone).toString() : ""; String codeRedis = redisUtil.get(session.getId()+phone)!= null ? redisUtil.get(session.getId()+phone).toString() : "";
if (code == null) { if (code == null) {
return ResultUtil.error("请填写验证码"); return ResultUtil.error("请填写验证码");
} }
...@@ -469,7 +473,7 @@ public class LoginController { ...@@ -469,7 +473,7 @@ public class LoginController {
String phone = entRegisterDto.getPhone(); String phone = entRegisterDto.getPhone();
String code = entRegisterDto.getCode(); String code = entRegisterDto.getCode();
// String codeRedis = redisTemplate.get(phone).toString(); // String codeRedis = redisTemplate.get(phone).toString();
String codeRedis = redisUtil.get(phone) != null ? redisUtil.get(phone).toString() : ""; String codeRedis = redisUtil.get(session.getId()+phone) != null ? redisUtil.get(session.getId()+phone).toString() : "";
if(authentication_code !=null && !("").equals(authentication_code)) { if(authentication_code !=null && !("").equals(authentication_code)) {
if (authentication_code.equals(code)) { if (authentication_code.equals(code)) {
...@@ -745,7 +749,7 @@ public class LoginController { ...@@ -745,7 +749,7 @@ public class LoginController {
return ResultUtil.error("请输入验证码"); return ResultUtil.error("请输入验证码");
} }
String phone = entRegisterDto.getPhone(); String phone = entRegisterDto.getPhone();
String codeRedis = redisUtil.get(phone)!= null ? redisUtil.get(phone).toString() : ""; String codeRedis = redisUtil.get(session.getId()+phone)!= null ? redisUtil.get(session.getId()+phone).toString() : "";
if(authentication_code !=null && !("").equals(authentication_code)) { if(authentication_code !=null && !("").equals(authentication_code)) {
if (authentication_code.equals(code)) { if (authentication_code.equals(code)) {
......
...@@ -184,7 +184,7 @@ public class ZpglWxgzptController { ...@@ -184,7 +184,7 @@ public class ZpglWxgzptController {
return ResultUtil.error("请输入验证码"); return ResultUtil.error("请输入验证码");
} }
//String codeRedis = session.getAttribute(phone) != null ? session.getAttribute(phone).toString() : ""; //String codeRedis = session.getAttribute(phone) != null ? session.getAttribute(phone).toString() : "";
String codeRedis = redisUtil.get(phone) != null ? redisUtil.get(phone).toString() : null; String codeRedis = redisUtil.get(session.getId()+phone) != null ? redisUtil.get(session.getId()+phone).toString() : null;
if(authentication_code !=null && !("").equals(authentication_code)) { if(authentication_code !=null && !("").equals(authentication_code)) {
if (authentication_code.equals(code)) { if (authentication_code.equals(code)) {
return loginhan(phone,openid); return loginhan(phone,openid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment