¶Ô±ÈÐÂÎļþ |
| | |
| | | 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>è·åæä»¶çmd5</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; |
| | | } |
| | | } |
| | | } |