From 042eb4875c91a38b19f160bf68fb658552f7e7bc Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 14 一月 2025 16:04:08 +0800
Subject: [PATCH] 1

---
 se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java      |   11 ++
 se-modules/se-system/src/main/java/com/se/system/service/LiceVerifyInstallListener.java   |  139 ++++++++++++++++++++++++++++++++++
 se-modules/se-system/src/main/java/com/se/system/service/CustomVerifyListenerService.java |   48 ++++++++++++
 3 files changed, 198 insertions(+), 0 deletions(-)

diff --git a/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java
index 86aa99b..a3a639c 100644
--- a/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java
+++ b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java
@@ -88,4 +88,15 @@
                 ", publicKeysStorePath='" + publicKeysStorePath + '\'' +
                 '}';
     }
+
+    public LicenseVerifyParamVo getVerifyParam() {
+        LicenseVerifyParamVo param = new LicenseVerifyParamVo();
+        param.setSubject(subject);
+        param.setPublicAlias(publicAlias);
+        param.setStorePass(storePass);
+        param.setLicensePath(licensePath);
+        param.setPublicKeysStorePath(publicKeysStorePath);
+
+        return param;
+    }
 }
diff --git a/se-modules/se-system/src/main/java/com/se/system/service/CustomVerifyListenerService.java b/se-modules/se-system/src/main/java/com/se/system/service/CustomVerifyListenerService.java
new file mode 100644
index 0000000..36ab72f
--- /dev/null
+++ b/se-modules/se-system/src/main/java/com/se/system/service/CustomVerifyListenerService.java
@@ -0,0 +1,48 @@
+package com.se.system.service;
+
+import com.se.system.domain.vo.LicenseExtraParamVo;
+import com.se.system.service.inte.IACustomVerifyListener;
+
+@SuppressWarnings("ALL")
+public class CustomVerifyListenerService extends IACustomVerifyListener {
+    /**
+     * 鍗曚緥Bean,杩欎釜闈欐�佸彉閲忎細缂撳瓨璇佷功涓渶澶х敤鎴锋敞鍐屾暟鐨�
+     */
+    private static Long registerAmount = 0L;
+
+    @Override
+    public boolean verify(LicenseExtraParamVo licenseExtra) {
+        registerAmount = null == licenseExtra.getRegisterAmount() ? 0 : licenseExtra.getRegisterAmount();
+        System.out.println("======= 鑷畾涔夎瘉涔﹂獙璇佺洃鍚櫒A 瀹炵幇verify鏂规硶  =======");
+        System.out.println("璇佷功鏈�澶ч獙璇佷汉鏁版槸锛�" + registerAmount);
+        /**
+         * 杩欓噷锛屽彲浠ュ仛涓�浜涘拰涓氬姟绯荤粺鏈夊叧鐨勫弬鏁伴獙璇�
+         * 鍦ㄨ繖涓笟鍔$郴缁熻繖涓洃鍚柟娉曚腑锛屾垜浠彲浠ュ厛鍘籾ser琛ㄦ煡璇笅锛屽綋鍓嶇郴缁熺殑娉ㄥ唽鐢ㄦ埛鏁伴噺
+         * 鐒跺悗鎷跨潃杩欎釜鏁伴噺鍜宭ic鍙傛暟涓害鏉熺殑鏈�澶ф敞鍐岀敤鎴烽噺杩涜姣旇緝锛屽鏋�>锛屽垯鎶涘嚭寮傚父
+         * 杩欐牱鍋氱殑鐩殑鏄槻姝笟鍔$郴缁熼儴缃插埌瀹㈡埛绔湰鍦版湇鍔″櫒涓婃椂锛屾暟鎹簱鏄叕寮�鐨勶紝闃叉瀵规柟閫氳繃鎵嬪姩鏀硅〃鏉ユ坊鍔犵敤鎴�
+         */
+        long count = 1001;
+        if (count >= registerAmount) {
+            System.out.println("绯荤粺褰撳墠鐢ㄦ埛鏁拌秴杩囨渶澶х敤鎴锋敞鍐岄檺鍒舵暟銆�" + registerAmount + "銆�");
+        }
+
+        System.out.println("绯荤粺娉ㄥ唽鏈�澶х敤鎴锋暟閲忔湭瓒呰繃" + count + "锛岄獙璇佺敤杩囷紒");
+        return true;
+    }
+
+    /**
+     * 杩欎釜鍗曠嫭鐨勯噸杞界殑楠岃瘉鏂规硶锛屼富瑕佹槸鐢ㄤ簬涓氬姟绯荤粺涓繘琛岃皟鐢紝甯﹀弬鏁扮殑verify鏂规硶鐢ㄤ簬娉ㄨВ
+     * 鑰岃繖涓笉甯﹀弬鏁扮殑verify锛屾洿鍔犵伒娲讳簺,姣斿鍦ㄧ郴缁熶腑娉ㄥ唽鎺ュ彛锛圕ontroller锛変笂锛岄櫎浜嗚嚜韬獲VLicense娉ㄨВ澶栵紝
+     * 鍙互鍦ㄨ皟鐢ㄨ繖涓柟娉曪紝鏉ラ澶栫殑楠岃瘉娉ㄥ唽浜烘暟鏄惁宸叉弧
+     *
+     * @return
+     * @throws
+     */
+    public boolean verify() {
+        Long count = 100L;
+        if (count.equals(registerAmount)) {
+            System.out.println("绯荤粺褰撳墠鐢ㄦ埛鏁板凡杈惧埌鏈�澶х敤鎴锋敞鍐岄檺鍒舵暟銆�" + registerAmount + "銆戯紝鏃犳硶鍐嶆敞鍐屾柊鐢ㄦ埛銆傚闇�鎵╁厖鐢ㄦ埛娉ㄥ唽鐨勬暟閲忥紝璇疯仈绯绘垜浠噸鏂拌喘涔癓icense锛�");
+        }
+        return true;
+    }
+}
diff --git a/se-modules/se-system/src/main/java/com/se/system/service/LiceVerifyInstallListener.java b/se-modules/se-system/src/main/java/com/se/system/service/LiceVerifyInstallListener.java
new file mode 100644
index 0000000..3bc26c4
--- /dev/null
+++ b/se-modules/se-system/src/main/java/com/se/system/service/LiceVerifyInstallListener.java
@@ -0,0 +1,139 @@
+package com.se.system.service;
+
+import com.se.system.domain.vo.LicenseResultVo;
+import com.se.system.domain.vo.LicenseVerifyMg;
+import com.se.system.domain.vo.LicenseVerifyParamVo;
+import com.se.system.utils.CommonUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+@SuppressWarnings("ALL")
+public class LiceVerifyInstallListener {
+    public LicenseVerifyParamVo licenseVerifyProperties;
+
+    private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
+
+    private ScheduledFuture<?> scheduledFuture;
+
+    // 鍚姩瀹氭椂浠诲姟
+    public void startTimer() {
+        scheduledFuture = scheduler.scheduleAtFixedRate(this::timer, 0, 15, TimeUnit.SECONDS);
+    }
+
+    // 鍋滄瀹氭椂浠诲姟
+    public void stopTimer() {
+        if (scheduledFuture != null) {
+            scheduledFuture.cancel(false);
+        }
+    }
+
+    /**
+     * 鏂囦欢鍞竴韬唤鏍囪瘑 == 鐩稿綋浜庝汉绫荤殑鎸囩汗涓�鏍�
+     */
+    private static String md5 = "";
+
+    private static boolean isLoad = false;
+
+    public static void LicenseVerifyInstall(LicenseVerifyParamVo licenseVerifyProperties) {
+        new LiceVerifyInstallListener(licenseVerifyProperties);
+    }
+
+    public LiceVerifyInstallListener(LicenseVerifyParamVo licenseVerifyProperties) {
+        // startTimer();
+        this.licenseVerifyProperties = licenseVerifyProperties;
+        if (CommonUtils.isNotEmpty(licenseVerifyProperties.getLicensePath())) {
+            install();
+            try {
+                String readMd5 = getMd5(licenseVerifyProperties.getLicensePath());
+                isLoad = true;
+                if (LiceVerifyInstallListener.md5 == null || "".equals(LiceVerifyInstallListener.md5)) {
+                    LiceVerifyInstallListener.md5 = readMd5;
+                }
+            } catch (Exception e) {
+
+            }
+        }
+    }
+
+    /**
+     * 15绉掓娴嬩竴娆★紝涓嶈兘澶揩涔熶笉鑳藉お鎱�
+     */
+    protected void timer() {
+        if (!isLoad) {
+            return;
+        }
+        String readMd5 = null;
+        try {
+            readMd5 = getMd5(licenseVerifyProperties.getLicensePath());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        // 涓嶇浉绛夛紝璇存槑lic鍙樺寲浜�
+        if (!readMd5.equals(LiceVerifyInstallListener.md5)) {
+            install();
+            LiceVerifyInstallListener.md5 = readMd5;
+        }
+    }
+
+    private void install() {
+        System.out.println("++++++++ 寮�濮嬪畨瑁呰瘉涔� ++++++++");
+        LicenseVerifyMg licenseVerifyManager = new LicenseVerifyMg();
+        /** 璧板畾涔夋牎楠岃瘉涔﹀苟瀹夎 */
+        LicenseResultVo result = licenseVerifyManager.install(licenseVerifyProperties.getVerifyParam());
+        if (result.getResult()) {
+            System.out.println("++++++++ 璇佷功瀹夎鎴愬姛 ++++++++");
+        } else {
+            System.out.println("++++++++ 璇佷功瀹夎澶辫触 ++++++++");
+        }
+    }
+
+    /**
+     * <p>鑾峰彇鏂囦欢鐨刴d5</p>
+     */
+    public String getMd5(String filePath) throws Exception {
+        File file;
+        String md5 = "";
+        try {
+            file = new File(filePath);
+            if (file.exists()) {
+                FileInputStream is = new FileInputStream(file);
+                byte[] data = new byte[is.available()];
+                is.read(data);
+                md5 = calculateMD5(data);
+                is.close();
+            }
+        } catch (FileNotFoundException e) {
+
+        }
+        return md5;
+    }
+
+    public static String calculateMD5(byte[] data) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            byte[] hashBytes = md.digest(data);
+
+            StringBuilder hexString = new StringBuilder();
+            for (byte b : hashBytes) {
+                String hex = Integer.toHexString(0xff & b);
+                if (hex.length() == 1) {
+                    hexString.append('0');
+                }
+                hexString.append(hex);
+            }
+
+            return hexString.toString();
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace(); // 澶勭悊寮傚父锛屼緥濡傛墦鍗伴敊璇俊鎭�
+            return null;
+        }
+    }
+}

--
Gitblit v1.9.3