Java实现短信验证码--设置发送间隔时间,以及有效时间(Java+Redis)
这篇文章,实现了Java发送手机短信验证码发送的间隔时间,以及手机验证码的有效时间和手机验证码格式的合法性验证,可以防止恶意刷接口
代码部分
package com.zxjs.controller.app;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 发送短信验证码
*/
@Api(value="发送短信验证码",description = "发送短信验证码,默认发送短信的间隔是一分钟",tags = {"发送短信验证码"})
@RestController
@RequestMapping("appISendSms")
public class SendSMS {
private final static Logger