需求:
1.输入手机号,获取验证码
2.每个手机号每天只能获取三次
3.比较验证码与输入的是否相同
@SuppressWarnings({"all"})
public class TestCode {
/***
* cont1:表示验证码的位数
* cont2:表示每日可获取验证码的次数
* cont3:表示验证码有效时常,单位 s
*/
private int cont1 = 6;
private int cont2 = 3;
private int cont3 = 300;
public static void main(String[] args) {
//连接reids
Jedis jedis = new Jedis("hadoop100",6379);
TestCode testCode = new TestCode();
Scanner scanner = new Scanner(System.in);
System.out.print("请输入手机号:");
String phone = scanner.next();
String codeKey = phone + "Code";
boolean yes = testCode.doRedis(phone);
if (!yes) {
//获取验证码失败,直接返回
return;
}
//获取验证码成功,在验证码有效时间内,可多次输入验证码
while (yes) {
Syst