From d174064c9c48a409d8ee6cdc1d65a5ffe1b2ed0f Mon Sep 17 00:00:00 2001
From: lty <876263681@qq.com>
Date: 星期二, 05 八月 2025 10:32:04 +0800
Subject: [PATCH] #许可证2.0

---
 src/main/java/com/zy/system/entity/license/LicenseVerify.java |   84 +++++++++++++++++-------------------------
 1 files changed, 34 insertions(+), 50 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..da239c0 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,21 @@
     /**
      * 瀹夎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{
-            LicenseManager licenseManager = LicenseManagerHolder.getInstance(initLicenseParam(param));
+        try {
+            LicenseParam licenseParam = initLicenseParam(param);
+            LicenseManager licenseManager = LicenseManagerHolder.getInstance(licenseParam);
             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 +50,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 +65,6 @@
      */
     public LicenseContent getVerifyInfo(){
         LicenseManager licenseManager = LicenseManagerHolder.getInstance(null);
-
-        if (!updateSystemTime()) {
-            //鏃堕棿鏇存柊澶辫触锛岀郴缁熸椂闂磋鏇存敼
-            return null;
-        }
 
         //鏍¢獙璇佷功
         try {
@@ -112,31 +99,28 @@
     }
 
     /**
-     * 鏇存柊鏃堕棿鍒版敞鍐岃〃涓�
+     * 灏咮ase64瀛楃涓茶浆鎹负涓存椂鏂囦欢
+     * @param base64String Base64缂栫爜鐨勫瓧绗︿覆
+     * @param filePrefix 鏂囦欢鍚嶅墠缂�锛堜緥濡� "license_"锛�
+     * @param fileSuffix 鏂囦欢鍚庣紑锛堜緥濡� ".lic"锛�
+     * @return 鐢熸垚鐨勪复鏃禙ile瀵硅薄锛堣嚜鍔ㄥ湪JVM閫�鍑烘椂鍒犻櫎锛�
+     * @throws IOException
      */
-    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 {
+        // 瑙g爜Base64
+        byte[] decodedBytes = Base64.getDecoder().decode(base64String);
+        // 鍒涘缓涓存椂鏂囦欢
+        Path tempPath = Files.createTempFile(filePrefix, fileSuffix);
+        // 鍐欏叆鍐呭
+        Files.write(tempPath, decodedBytes);
+        // 璁剧疆JVM閫�鍑烘椂鑷姩鍒犻櫎
+        tempPath.toFile().deleteOnExit();
+        return tempPath.toFile();
+    }
+
+    public File createTempFileFromBase64(String base64Data) throws IOException {
+        return base64ToTempFile(base64Data, "temp_license_", ".bin");
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.1