Przeglądaj źródła

refactor: 运行授权vbs提醒

zhanghaijun 3 lat temu
rodzic
commit
7dcb7d76cb

+ 15 - 2
src/main/java/com/cec/plugins/PluginsApplication.java

@@ -1,20 +1,33 @@
 package com.cec.plugins;
 
+import com.cec.plugins.utils.LicenseUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.Banner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
+import java.io.IOException;
+
+@Slf4j
 @EnableAsync
 @EnableScheduling
 @SpringBootApplication
 public class PluginsApplication {
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException {
+        if (LicenseUtil.licenseExpired()) {
+            LicenseUtil.runVbsExpired();
+            log.info("\033[1;33m {} \033[0m", String.format("\n ========== 启动服务 =========="
+                + "\n\t 授权时间已过期,请来及时联系管理员"
+                + "\n\t 授权时间至:\t%s"
+                + "\n\t 授权已过期:\t%s天"
+                + "\n ============================", LicenseUtil.licenseUntil(), LicenseUtil.licenseRemaining()));
+            System.exit(1);
+        }
         SpringApplication springApplication = new SpringApplication(PluginsApplication.class);
         springApplication.setBannerMode(Banner.Mode.OFF);
         springApplication.run(args);
     }
-
 }

+ 34 - 0
src/main/java/com/cec/plugins/utils/LicenseUtil.java

@@ -1,8 +1,12 @@
 package com.cec.plugins.utils;
 
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
 import lombok.experimental.UtilityClass;
+import lombok.extern.slf4j.Slf4j;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 
@@ -11,6 +15,7 @@ import java.util.GregorianCalendar;
  * @date 2023/9/9 13:16
  * @description 授权检查
  */
+@Slf4j
 @UtilityClass
 public class LicenseUtil {
 
@@ -28,4 +33,33 @@ public class LicenseUtil {
         return DateUtil.betweenDay(VALID_UNTIL.getTime(), DateUtil.date(), true);
     }
 
+    public static boolean isWindows() {
+        return System.getProperties().getProperty("os.name").toUpperCase().contains("WINDOWS");
+    }
+
+    public static void runVbsExpired() {
+        try {
+            if (!isWindows()) {
+                return;
+            }
+            if (!FileUtil.exist("C:\\Windows\\System32\\wscript.exe")) {
+                return;
+            }
+            File file = new File("bin\\msgbox.vbs");
+            if (file.exists()) {
+                Runtime.getRuntime().exec(new String[]{"C:\\Windows\\System32\\wscript.exe", file.getAbsolutePath(), "轨道交通插件 & 授权已过期,请联系管理员"});
+                return;
+            } else {
+                log.error("vbs 运行异常:文件未找到:{}", file.getAbsolutePath());
+            }
+            file = new File("src\\assembly\\bin\\msgbox.vbs");
+            if (file.exists()) {
+                Runtime.getRuntime().exec(new String[]{"C:\\Windows\\System32\\wscript.exe", file.getAbsolutePath(), "轨道交通插件 & 授权已过期,请联系管理员"});
+            } else {
+                log.error("vbs 运行异常:文件未找到:{}", file.getAbsolutePath());
+            }
+        } catch (IOException e) {
+            log.error("vbs 运行异常:{}", e.getMessage());
+        }
+    }
 }