From 5b6e33867d337b6aaeaf91b2fcd1b6e94c07de6c Mon Sep 17 00:00:00 2001
From: dubin <bindu_bean@163.com>
Date: 星期三, 22 十月 2025 11:02:11 +0800
Subject: [PATCH] 许可证2.0
---
src/main/java/com/zy/system/entity/license/LicenseVerify.java | 75 +++++++++++++++++--------------------
1 files changed, 34 insertions(+), 41 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 2175930..da239c0 100644
--- a/src/main/java/com/zy/system/entity/license/LicenseVerify.java
+++ b/src/main/java/com/zy/system/entity/license/LicenseVerify.java
@@ -5,9 +5,13 @@
import org.apache.logging.log4j.Logger;
import java.io.File;
+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;
/**
@@ -19,19 +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();
- 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;
@@ -44,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())));
@@ -64,11 +65,6 @@
*/
public LicenseContent getVerifyInfo(){
LicenseManager licenseManager = LicenseManagerHolder.getInstance(null);
-
- if (!updateSystemTime()) {
- //鏃堕棿鏇存柊澶辫触锛岀郴缁熸椂闂磋鏇存敼
- return null;
- }
//鏍¢獙璇佷功
try {
@@ -103,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