Junjie
1 天以前 a4f07b2a0ddb6c210e05afbbb491feeb466203e7
src/main/java/com/zy/system/timer/LicenseTimer.java
@@ -52,6 +52,12 @@
    @Value("${license.publicKeysStorePath}")
    private String publicKeysStorePath;
    /**
     * 许可证服务端地址。
     */
    @Value("${license.remoteServerUrl:http://net.zoneyung.net:9999/license}")
    private String remoteServerUrl;
    @Autowired
    private LicenseInfosService licenseInfosService;
@@ -73,49 +79,61 @@
    public void getRemoteLicense() {
        try {
            AbstractServerInfos abstractServerInfos = null;
            String osName = System.getProperty("os.name");
            // 根据不同操作系统类型选择不同的数据获取方法
            if (osName.startsWith("windows")) {
                abstractServerInfos = new WindowsServerInfos();
            } else if (osName.startsWith("linux")) {
                abstractServerInfos = new LinuxServerInfos();
            } else {// 其他服务器类型
                abstractServerInfos = new WindowsServerInfos();
            String requestCode = LicenseUtils.buildRequestCode(subject);
            LicenseCheck serverInfos = LicenseUtils.getServerInfos();
            JSONObject response = requestRemoteLicense(buildRequestCodePayload(requestCode));
            if (!isSuccess(response)) {
                response = requestRemoteLicense(buildLegacyPayload(serverInfos));
            }
            LicenseCheck serverInfos = abstractServerInfos.getServerInfos();
            HashMap<String, Object> map = new HashMap<>();
            map.put("subject", subject);
            map.put("licenseCheck", serverInfos);
            String response = new HttpHandler.Builder()
                    .setUri("http://net.zoneyung.net:9999/license")
                    .setPath("/remoteQueryLicense")
                    .setJson(JSON.toJSONString(map))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getString("result").equals("ok")) {
            if (isSuccess(response)) {
                LicenseInfos licenseInfos = new LicenseInfos();
                licenseInfos.setLicense(jsonObject.getString("data"));
                licenseInfos.setLicense(response.getString("data"));
                licenseInfos.setCreateTime(new Date());
                licenseInfos.setLicenseTime(jsonObject.getString("licenseTime"));
                licenseInfosService.insert(licenseInfos);
                licenseInfos.setLicenseTime(response.getString("licenseTime"));
                licenseInfos.setRequestCode(requestCode);
                licenseInfosService.save(licenseInfos);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void verify() {
        LicenseInfos latestLicense = licenseInfosService.getLatestLicense();
        if (latestLicense == null) {
            setLicenseDays(0);
            setSystemSupport(false);
            return;
    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 String buildLegacyPayload(LicenseCheck serverInfos) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("subject", subject);
        map.put("licenseCheck", serverInfos);
        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);
@@ -123,10 +141,18 @@
        param.setLicensePath(licensePath);
        param.setPublicKeysStorePath(publicKeysStorePath);
        String requestCode = LicenseUtils.buildRequestCode(subject);
        LicenseInfos latestLicense = licenseInfosService.getLatestLicenseByRequestCode(requestCode);
        // 验证许可证是否有效
        LicenseVerify licenseVerify = new LicenseVerify();
        // 安装证书
        LicenseContent install = licenseVerify.install(param, latestLicense.getLicense());
        LicenseContent install = null;
        if (latestLicense != null) {
            install = licenseVerify.install(param, latestLicense.getLicense());
        }
        if (install == null) {
            install = licenseVerify.install(param);
        }
        if (install != null) {
            Date start = new Date();