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