package test;
/**
* 短信服务
* @author LBY
* @date 2023年11月16日 15:11
*/
public class SMSVerificationService {
public void sendVerificationCode(String phoneNum){
//判断当前用户短期内是否获取过验证码
if (!repeatCheck(phoneNum)){
String code = buildVerificationCode();
SMSSendVerificationCode(phoneNum,code);
// 在redis记录
RedisUtils.getRedis().set(phoneNum,code,60);
}
}
private boolean repeatCheck(String phoneNum) {
//查询redis60秒内是否获取过验证码
Object value = RedisUtils.getRedis().get(phoneNum);
if (value != null) {
//表明之前已经发送过验证码
return false;
}
return true;
}
private String buildVerificationCode() {
// 生成验证码的代码
return "11111111111";
}
private void SMSSendVerificationCode(String phoneNum,String code){
// 发短信代码
System.out.println("手机号 " + phoneNum + " 验证码:" + code);
}
}
防止恶意获取短信验证码
最新推荐文章于 2025-05-23 17:03:50 发布