From 686fe55892de7bf8d206cddbead77a5fbdb0e091 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期日, 08 三月 2026 19:59:29 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/system/entity/license/LicenseUtils.java | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/system/entity/license/LicenseUtils.java b/src/main/java/com/zy/system/entity/license/LicenseUtils.java
index d0eec17..35cb92e 100644
--- a/src/main/java/com/zy/system/entity/license/LicenseUtils.java
+++ b/src/main/java/com/zy/system/entity/license/LicenseUtils.java
@@ -1,5 +1,15 @@
package com.zy.system.entity.license;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import java.net.InetAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.List;
+
public class LicenseUtils {
/**
@@ -23,4 +33,98 @@
return abstractServerInfos.getServerInfos();
}
+ /**
+ * 鐢熸垚璇锋眰鐮侊紝璇锋眰鐮佷腑鍖呭惈璁稿彲璇佸悕绉板拰褰撳墠鏈嶅姟鍣ㄧ殑纭欢淇℃伅銆�
+ */
+ public static String buildRequestCode(String subject) {
+ return buildRequestCode(subject, getServerInfos());
+ }
+
+ public static String buildRequestCode(String subject, LicenseCheck licenseCheck) {
+ if (isBlank(subject)) {
+ throw new IllegalArgumentException("璁稿彲璇佸悕绉颁笉鑳戒负绌�");
+ }
+
+ LicenseCheck normalized = normalizeLicenseCheck(licenseCheck == null ? new LicenseCheck() : licenseCheck);
+ JSONObject payload = new JSONObject(true);
+ payload.put("version", 2);
+ payload.put("subject", subject);
+ payload.put("licenseBind", buildBindModel(normalized));
+ return Base64.getEncoder().encodeToString(JSON.toJSONString(payload).getBytes(StandardCharsets.UTF_8));
+ }
+
+ private static JSONObject buildBindModel(LicenseCheck licenseCheck) {
+ JSONObject bindModel = new JSONObject(true);
+ bindModel.put("version", 2);
+ bindModel.put("bindMode", "MULTI_NODE");
+ bindModel.put("matchMode", "ANY");
+
+ JSONObject node = new JSONObject(true);
+ node.put("nodeId", getNodeId());
+ node.put("ipAddress", toJsonArray(licenseCheck.getIpAddress()));
+ node.put("macAddress", toJsonArray(licenseCheck.getMacAddress()));
+ node.put("cpuSerial", trimToEmpty(licenseCheck.getCpuSerial()));
+ node.put("mainBoardSerial", trimToEmpty(licenseCheck.getMainBoardSerial()));
+
+ JSONArray nodes = new JSONArray();
+ nodes.add(node);
+ bindModel.put("nodes", nodes);
+ return bindModel;
+ }
+
+ private static LicenseCheck normalizeLicenseCheck(LicenseCheck source) {
+ LicenseCheck target = new LicenseCheck();
+ target.setIpAddress(normalizeList(source.getIpAddress(), false));
+ target.setMacAddress(normalizeList(source.getMacAddress(), true));
+ target.setCpuSerial(trimToEmpty(source.getCpuSerial()));
+ target.setMainBoardSerial(trimToEmpty(source.getMainBoardSerial()));
+ return target;
+ }
+
+ private static List<String> normalizeList(List<String> values, boolean upperCase) {
+ List<String> result = new ArrayList<>();
+ if (values == null || values.isEmpty()) {
+ return result;
+ }
+ for (String value : values) {
+ if (isBlank(value)) {
+ continue;
+ }
+ String normalized = value.trim();
+ normalized = upperCase ? normalized.toUpperCase() : normalized.toLowerCase();
+ if (!result.contains(normalized)) {
+ result.add(normalized);
+ }
+ }
+ Collections.sort(result);
+ return result;
+ }
+
+ private static JSONArray toJsonArray(List<String> values) {
+ JSONArray array = new JSONArray();
+ if (values != null && !values.isEmpty()) {
+ array.addAll(values);
+ }
+ return array;
+ }
+
+ private static String getNodeId() {
+ try {
+ String hostName = InetAddress.getLocalHost().getHostName();
+ if (!isBlank(hostName)) {
+ return hostName.trim();
+ }
+ } catch (Exception ignored) {
+ }
+ return "node-1";
+ }
+
+ private static boolean isBlank(String value) {
+ return value == null || value.trim().isEmpty();
+ }
+
+ private static String trimToEmpty(String value) {
+ return value == null ? "" : value.trim();
+ }
+
}
--
Gitblit v1.9.1