controller:
/**
* 校验验证码是否正确
* @param smsCode
* @param phone
*/
@RequestMapping(value = "checkSmsCode",method = RequestMethod.POST)
public Result checkSmsCode(String smsCode, String phone) {
return authService.checkSmsCode(smsCode, phone);
}
service:
/**
* 校验验证码是否正确
*
* @param smsCode
* @param phone
*/
public Result checkSmsCode(String smsCode, String phone) {
Result result = new Result();
if (redisTemplate.opsForValue().get(phone) == null) {
result.setStatus(1);
result.setMsg("短信验证码输入超时!");
} else {
String code = redisTemplate.opsForValue().get(phone).toString();
if (!code.equals(smsCode)) {
result.setStatus(2);
result.setMsg(短信验证码错误!");
} else {
result.setStatus(0);
result.setMsg("成功!");
}
}
return result;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6c513cc1550bc3e47eb360170c5be4e5.png)