From 780ff45fdc167cadf4724c6c94530929b7445aab Mon Sep 17 00:00:00 2001
From: zwl <1051256694@qq.com>
Date: 星期一, 16 三月 2026 10:37:51 +0800
Subject: [PATCH] 完善许可证

---
 src/main/java/com/zy/system/entity/license/LicenseVerify.java |   76 +++++++++++--------------------------
 1 files changed, 23 insertions(+), 53 deletions(-)

diff --git a/src/main/java/com/zy/system/entity/license/LicenseVerify.java b/src/main/java/com/zy/system/entity/license/LicenseVerify.java
index fd95fca..1e319a1 100644
--- a/src/main/java/com/zy/system/entity/license/LicenseVerify.java
+++ b/src/main/java/com/zy/system/entity/license/LicenseVerify.java
@@ -3,14 +3,15 @@
 import de.schlichtherle.license.*;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.apache.tomcat.util.http.fileupload.IOUtils;
 
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.text.DateFormat;
 import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
+import java.util.Base64;
 import java.util.prefs.Preferences;
 
 /**
@@ -22,25 +23,19 @@
     /**
      * 瀹夎License璇佷功
      */
-    public synchronized LicenseContent install(LicenseVerifyParam param){
+    public synchronized LicenseContent install(LicenseVerifyParam param, String license) {
         LicenseContent result = null;
         DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
-        //1. 瀹夎璇佷功
-        try{
+        try {
             LicenseManager licenseManager = LicenseManagerHolder.getInstance(initLicenseParam(param));
             licenseManager.uninstall();
 
-            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(param.getLicensePath());
-            File file = new File(param.getLicensePath());
-            try (FileOutputStream out = new FileOutputStream(file)) {
-                IOUtils.copy(inputStream, out);
-            }
-
-            result = licenseManager.install(new File(param.getLicensePath()));
-            logger.info(MessageFormat.format("璁稿彲璇佸姞杞芥垚鍔燂紝璁稿彲璇佹湁鏁堟湡锛歿0} - {1}",format.format(result.getNotBefore()),format.format(result.getNotAfter())));
-        }catch (Exception e){
-            logger.error("璁稿彲璇佸姞杞藉け璐ワ紒",e);
+            File tempFileFromBase64 = createTempFileFromBase64(license);
+            result = licenseManager.install(tempFileFromBase64);
+            logger.info(MessageFormat.format("璁稿彲璇佸姞杞芥垚鍔燂紝璁稿彲璇佹湁鏁堟湡锛歿0} - {1}", format.format(result.getNotBefore()), format.format(result.getNotAfter())));
+        } catch (Exception e) {
+            logger.error("璁稿彲璇佸姞杞藉け璐ワ紒", e);
         }
 
         return result;
@@ -53,11 +48,6 @@
         try {
             LicenseManager licenseManager = LicenseManagerHolder.getInstance(null);
             DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
-            if (!updateSystemTime()) {
-                //鏃堕棿鏇存柊澶辫触锛岀郴缁熸椂闂磋鏇存敼
-                return false;
-            }
 
             LicenseContent licenseContent = licenseManager.verify();
             logger.info(MessageFormat.format("璁稿彲璇佹牎楠岄�氳繃锛岃鍙瘉鏈夋晥鏈燂細{0} - {1}",format.format(licenseContent.getNotBefore()),format.format(licenseContent.getNotAfter())));
@@ -73,11 +63,6 @@
      */
     public LicenseContent getVerifyInfo(){
         LicenseManager licenseManager = LicenseManagerHolder.getInstance(null);
-
-        if (!updateSystemTime()) {
-            //鏃堕棿鏇存柊澶辫触锛岀郴缁熸椂闂磋鏇存敼
-            return null;
-        }
 
         //鏍¢獙璇佷功
         try {
@@ -111,32 +96,17 @@
                 ,cipherParam);
     }
 
-    /**
-     * 鏇存柊鏃堕棿鍒版敞鍐岃〃涓�
-     */
-    private boolean updateSystemTime() {
-        // 鑾峰彇鐢ㄦ埛鏍硅妭鐐�
-        Preferences userRoot = Preferences.userRoot();
-        // 鑾峰彇鎸囧畾璺緞涓嬬殑鑺傜偣
-        Preferences node = userRoot.node("/zhongyang");
-        String key = "time";
-        // 璇诲彇娉ㄥ唽琛�
-        String value = node.get(key, null);
-        if (value != null) {
-            long originTime = Long.parseLong(value);
-            long now = System.currentTimeMillis();
-            long diff = now - originTime;//鐜板湪鏃堕棿 - 婧愭椂闂� = 鏃堕棿宸�
-            if (diff > 0) {
-                //鏃堕棿宸ぇ浜�0鎵嶅厑璁告洿鏂版敞鍐岃〃鏃堕棿
-                node.put(key, String.valueOf(System.currentTimeMillis()));
-                return true;
-            }
-        }else {
-            // 鍐欏叆娉ㄥ唽琛�
-            node.put(key, String.valueOf(System.currentTimeMillis()));
-            return true;
-        }
-        return false;
+    public File base64ToTempFile(String base64String, String filePrefix, String fileSuffix)
+            throws IOException {
+        byte[] decodedBytes = Base64.getDecoder().decode(base64String);
+        Path tempPath = Files.createTempFile(filePrefix, fileSuffix);
+        Files.write(tempPath, decodedBytes);
+        tempPath.toFile().deleteOnExit();
+        return tempPath.toFile();
     }
 
-}
\ No newline at end of file
+    public File createTempFileFromBase64(String base64Data) throws IOException {
+        return base64ToTempFile(base64Data, "temp_license_", ".bin");
+    }
+
+}

--
Gitblit v1.9.1