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/timer/LicenseTimer.java | 128 +++++++++++++++++++++++++++++++++++++++++-
1 files changed, 123 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/zy/system/timer/LicenseTimer.java b/src/main/java/com/zy/system/timer/LicenseTimer.java
index 1f0190d..48acdce 100644
--- a/src/main/java/com/zy/system/timer/LicenseTimer.java
+++ b/src/main/java/com/zy/system/timer/LicenseTimer.java
@@ -1,24 +1,142 @@
package com.zy.system.timer;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.core.common.Cools;
+import com.zy.common.utils.HttpHandler;
+import com.zy.system.entity.LicenseInfos;
+import com.zy.system.entity.license.LicenseUtils;
import com.zy.system.entity.license.LicenseVerify;
+import com.zy.system.entity.license.LicenseVerifyParam;
+import com.zy.system.service.LicenseInfosService;
+import de.schlichtherle.license.LicenseContent;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.HashMap;
@Component
public class LicenseTimer {
- private static boolean SYSTEM_SUPPORT = true;//绯荤粺婵�娲荤姸鎬侊紝榛樿鍏抽棴
+ private static boolean SYSTEM_SUPPORT = false;//绯荤粺婵�娲荤姸鎬侊紝榛樿鍏抽棴
private static int LICENSE_DAYS = 0;//璁稿彲璇佸ぉ鏁�
+
+ @Value("${license.subject}")
+ private String subject;
+
+ @Value("${license.publicAlias}")
+ private String publicAlias;
+
+ @Value("${license.storePass}")
+ private String storePass;
+
+ @Value("${license.publicKeysStorePath}")
+ private String publicKeysStorePath;
+
+ @Value("${license.remoteServerUrl:http://net.zoneyung.net:9999/license}")
+ private String remoteServerUrl;
+
+ @Autowired
+ private LicenseInfosService licenseInfosService;
//姣忓ぉ鏅氫笂11鐐规洿鏂扮郴缁熸縺娲荤姸鎬�
@Scheduled(cron = "0 0 23 * * ? ")
public void timer() {
-// System.out.println(SYSTEM_SUPPORT);
- //楠岃瘉璁稿彲璇佹槸鍚︽湁鏁�
+ try {
+ getRemoteLicense();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ verify();
+ } catch (Exception ignored) {
+ }
+ }
+
+ public void getRemoteLicense() {
+ try {
+ String requestCode = LicenseUtils.buildRequestCode(subject);
+ JSONObject response = requestRemoteLicense(buildRequestCodePayload(requestCode));
+ if (isSuccess(response)) {
+ String license = response.getString("data");
+ if (Cools.isEmpty(license)) {
+ return;
+ }
+ LicenseInfos latestLicense = licenseInfosService.getLatestLicenseByRequestCode(requestCode);
+ if (latestLicense != null && Cools.eq(latestLicense.getLicense(), license)) {
+ return;
+ }
+ LicenseInfos licenseInfos = new LicenseInfos();
+ licenseInfos.setLicense(license);
+ licenseInfos.setCreateTime(new Date());
+ licenseInfos.setLicenseTime(response.getString("licenseTime"));
+ licenseInfos.setRequestCode(requestCode);
+ licenseInfosService.insert(licenseInfos);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private JSONObject requestRemoteLicense(String json) {
+ try {
+ String response = new HttpHandler.Builder()
+ .setUri(remoteServerUrl)
+ .setPath("/remoteQueryLicense")
+ .setJson(json)
+ .build()
+ .doPost();
+ if (response == null || response.trim().isEmpty()) {
+ return null;
+ }
+ return JSON.parseObject(response);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ private String buildRequestCodePayload(String requestCode) {
+ HashMap<String, Object> map = new HashMap<>();
+ map.put("subject", subject);
+ map.put("requestCode", requestCode);
+ return JSON.toJSONString(map);
+ }
+
+ private boolean isSuccess(JSONObject jsonObject) {
+ return jsonObject != null && "ok".equalsIgnoreCase(jsonObject.getString("result"));
+ }
+
+ public void verify() {
+ LicenseVerifyParam param = new LicenseVerifyParam();
+ param.setSubject(subject);
+ param.setPublicAlias(publicAlias);
+ param.setStorePass(storePass);
+ param.setPublicKeysStorePath(publicKeysStorePath);
+
+ String requestCode = LicenseUtils.buildRequestCode(subject);
+ LicenseInfos latestLicense = licenseInfosService.getLatestLicenseByRequestCode(requestCode);
+
LicenseVerify licenseVerify = new LicenseVerify();
- boolean verify = licenseVerify.verify();
- setSystemSupport(verify);//鏇存柊绯荤粺婵�娲荤姸鎬�
+ LicenseContent install = null;
+ if (latestLicense != null && !Cools.isEmpty(latestLicense.getLicense())) {
+ install = licenseVerify.install(param, latestLicense.getLicense());
+ }
+
+ if (install != null) {
+ Date start = new Date();
+ Date end = install.getNotAfter();
+ long num = end.getTime() - start.getTime();
+ int day = (int) (num / 24 / 60 / 60 / 1000);
+ setLicenseDays(day);
+ setSystemSupport(true);
+ } else {
+ setLicenseDays(0);
+ setSystemSupport(false);
+ }
}
public boolean getSystemSupport() {
--
Gitblit v1.9.1