自动化立体仓库 - WMS系统
luxiaotao1123
2020-08-01 b3ac00069f9594f6ec0077cbb91516e26e13c3b6
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
60
61
62
63
64
65
66
67
68
69
package com.zy.common.properties;
 
import com.core.common.AesUtils;
 
import java.io.*;
 
/**
 * Created by vincent on 2020/8/1
 */
public class SystemProperties {
 
    // 激活码加密盐 -- 16位
    public static final String SALT = "123456789qwertyu";
 
    // 系统激活状态 (默认未激活)
    public static boolean SYSTEM_ACTIVATION = Boolean.FALSE;
 
    public static String getActivationCode(String fileName){
        StringBuilder activationCode = new StringBuilder();
        try {
            FileReader f = new FileReader(fileName);
            BufferedReader buf = new BufferedReader(f);
            String s;
            while ((s = buf.readLine()) != null) {
                activationCode.append(s);
            }
            f.close();
            buf.close();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("读取WMS系统激活码失败!!!\n读取路径 " + fileName);
        }
        return activationCode.toString();
    }
 
    public static boolean saveActivationCode(String filePath, String code){
        try {
            // 防止文件建立或读取失败,用catch捕捉错误并打印,也可以throw
            File file = new File(filePath);// 相对路径,如果没有则要建立一个新的output。txt文件
            if (file.exists()) {
                file.delete();
            }
            boolean newFile = file.createNewFile();// 创建新文件
            if (newFile) {
                BufferedWriter out = new BufferedWriter(new FileWriter(file, true));
                out.write(code); // \r\n即为换行
                out.flush(); // 把缓存区内容压入文件
                out.close(); // 最后记得关闭文件
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("写入WMS系统激活码失败!!!\n路径 " + filePath);
        }
        return true;
    }
 
 
    // 生成激活码
    public static void main(String[] args) {
        String code = AesUtils.encrypt("20200801152500", SystemProperties.SALT);
        System.out.println(code);
//        saveActivationCode(SysOsType.Windows.getActivationCodePath(), code);
//        String activationCode = getActivationCode(OSinfo.getOSname().getActivationCodePath());
//        String decrypt = AesUtils.decrypt(activationCode, "123456789qwertyu");
//        Date convert = DateUtils.convert(decrypt, DateUtils.yyyyMMddHHmmss);
//        System.out.println(DateUtils.convert(convert));
    }
 
}