自动化立体仓库 - WMS系统
Junjie
2024-08-01 a073250f6f4f8c32888bc60b24ff6984e29af51e
src/main/java/com/zy/system/entity/license/LicenseVerify.java
@@ -3,8 +3,11 @@
import de.schlichtherle.license.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.util.IOUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
@@ -28,7 +31,12 @@
            LicenseManager licenseManager = LicenseManagerHolder.getInstance(initLicenseParam(param));
            licenseManager.uninstall();
            result = licenseManager.install(new File(param.getLicensePath()));
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(param.getLicensePath());
            File file = new File(param.getLicensePath());
            try (FileOutputStream out = new FileOutputStream(file)) {
                IOUtils.copy(inputStream, out);
            }
            result = licenseManager.install(file);
            logger.info(MessageFormat.format("许可证加载成功,许可证有效期:{0} - {1}",format.format(result.getNotBefore()),format.format(result.getNotAfter())));
        }catch (Exception e){
            logger.error("许可证加载失败!",e);
@@ -41,19 +49,16 @@
     * 校验License证书
     */
    public boolean verify(){
        LicenseManager licenseManager = LicenseManagerHolder.getInstance(null);
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (!updateSystemTime()) {
            //时间更新失败,系统时间被更改
            return false;
        }
        //2. 校验证书
        try {
            LicenseContent licenseContent = licenseManager.verify();
//            System.out.println(licenseContent.getSubject());
            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())));
            return true;
        }catch (Exception e){