Commit 30ef854b by 陶湘宇

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

parent 1903fb68
......@@ -222,12 +222,16 @@ public class LoginController {
// 6位随机数验证码
try {
Integer code = (int) ((Math.random() * 9 + 1) * 100000);
if (phone == null || "".equals(phone)) {
phone = entRegisterDto.getUsername();
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);
Integer useId = (Integer) list.get(0);
JSONObject j = (JSONObject) list.get(1);
......@@ -257,10 +261,8 @@ public class LoginController {
String message = j.getString("Message");
if ("OK".equals(message)) {
redisUtil.set(phone, code);
// redisTemplate.set(phone, code);
// redisTemplate.expire(phone, 60);
return ResultUtil.data("发送验证码成功");
} else {
return ResultUtil.error("发送验证码失败");
......@@ -289,12 +291,15 @@ public class LoginController {
// 6位随机数验证码
try {
Integer code = (int) ((Math.random() * 9 + 1) * 100000);
if (phone == null || "".equals(phone)) {
phone = entRegisterDto.getUsername();
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);
Integer useId = (Integer) list.get(0);
JSONObject j = (JSONObject) list.get(1);
......@@ -303,7 +308,6 @@ public class LoginController {
String message = j.getString("Message");
if ("OK".equals(message)) {
//session.setAttribute(phone, code);
redisUtil.set(phone, code,60*5);
return ResultUtil.data("发送验证码成功");
} else {
return ResultUtil.error("发送验证码失败");
......@@ -328,7 +332,7 @@ public class LoginController {
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.equals(code)) {
......@@ -368,7 +372,7 @@ public class LoginController {
} else {
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)) {
return ResultUtil.error("短信验证码错误");
}
......@@ -403,7 +407,7 @@ public class LoginController {
String code = entRegisterDto.getCode();
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) {
return ResultUtil.error("请填写验证码");
}
......@@ -469,7 +473,7 @@ public class LoginController {
String phone = entRegisterDto.getPhone();
String code = entRegisterDto.getCode();
// 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.equals(code)) {
......@@ -745,7 +749,7 @@ public class LoginController {
return ResultUtil.error("请输入验证码");
}
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.equals(code)) {
......
......@@ -184,7 +184,7 @@ public class ZpglWxgzptController {
return ResultUtil.error("请输入验证码");
}
//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.equals(code)) {
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