软加密
parent
7842d651f3
commit
3b887f8463
@ -1,69 +0,0 @@
|
|||||||
package com.leaper.web.service;
|
|
||||||
|
|
||||||
import com.leaper.common.util.FileUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class LPLicense {
|
|
||||||
|
|
||||||
private static LocalDateTime lastUpdate = null;
|
|
||||||
|
|
||||||
private static String lic_str = null;
|
|
||||||
|
|
||||||
private static String lic_path = "./lp.lic";
|
|
||||||
|
|
||||||
private static String key_path = "./lp.key";
|
|
||||||
|
|
||||||
|
|
||||||
public static void createLicKeyIfNotExist(){
|
|
||||||
File file = new File(key_path);
|
|
||||||
if(!file.exists()){
|
|
||||||
try {
|
|
||||||
Process process = Runtime.getRuntime().exec(
|
|
||||||
new String[] { "wmic", "cpu", "get", "ProcessorId" });
|
|
||||||
process.getOutputStream().close();
|
|
||||||
Scanner sc = new Scanner(process.getInputStream());
|
|
||||||
String property = sc.next();
|
|
||||||
String cpu = sc.next();
|
|
||||||
FileUtil.save(cpu,key_path);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
log.error("createLicKeyIfNotExist error:{}",e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLic(){
|
|
||||||
//每小时读取一次lic文件
|
|
||||||
if(lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()){
|
|
||||||
lastUpdate = LocalDateTime.now();
|
|
||||||
lic_str = FileUtil.getText(lic_path);
|
|
||||||
}
|
|
||||||
return lic_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkLic(String pathStr){
|
|
||||||
//todo 检测
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkLic(){
|
|
||||||
String licStr = getLic();
|
|
||||||
if(StringUtils.isEmpty(licStr)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return checkLic(licStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
createLicKeyIfNotExist();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue