地质所 沉降监测网建设项目
chenhuan
2024-05-16 0fdd42e318f51f9e3c6581473416af1cca69877f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.javaweb.platform.utils;
 
import java.util.Random;
 
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
 
public class CaptCodeUtils {
    
     private static long timeout = 1000* 60 ;//1分钟过期        
     
     //用户缓存hash表
     public static TimedCache<String, String> captcodeCache = CacheUtil.newTimedCache(timeout);
    
     public static String verifyCode(){
            int a = 1234567890;
            String b ="abcdefghijklmnopqrstuvwxyz";
            String B=b.toUpperCase();
            String c=a+b+B;
            char[] d=c.toCharArray();
            Random random = new Random();
            String f="";
            for (int k = 0; k < 6; k++) {
                int index = random.nextInt(d.length);
                f+=d[index];
            }
            //添加缓存
            setCahce(f);
            return f;
      }
     
     //设置
     public  static void setCahce(String code){
         captcodeCache.put(code, code, timeout);
     } 
     
     //验证码是否存在
     public static boolean isExistCode(String code){
        String s = captcodeCache.get(code, false);
        if(s !=null){
            return true;
        }    
        return false;    
     }
     
     //删除
     public static void remove(String code){
         captcodeCache.remove(code);
     }
     //清空
     public static void clear(){
         captcodeCache.clear();
     }
     
    
    
 
 
}