From 2a317babc9254bf55a66ad4b64218e4dd10a6dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E6=B5=A9?= Date: Sun, 4 Feb 2024 09:43:23 +0000 Subject: [PATCH] Update 4 files - /src/main/java/com/license/bean/LicenseInfo.java - /src/main/java/com/license/utils/HaspUtil.java - /src/main/java/com/license/controller/LicenseController.java - /src/main/resources/application.properties --- .../java/com/license/bean/LicenseInfo.java | 2 +- .../license/controller/LicenseController.java | 72 ++++--------------- src/main/java/com/license/utils/HaspUtil.java | 46 +++--------- src/main/resources/application.properties | 2 +- 4 files changed, 25 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/license/bean/LicenseInfo.java b/src/main/java/com/license/bean/LicenseInfo.java index 988a03c..29335bd 100644 --- a/src/main/java/com/license/bean/LicenseInfo.java +++ b/src/main/java/com/license/bean/LicenseInfo.java @@ -11,7 +11,7 @@ import lombok.Data; @Data public class LicenseInfo { - private String V2C; + private String param; private String vendorCode; diff --git a/src/main/java/com/license/controller/LicenseController.java b/src/main/java/com/license/controller/LicenseController.java index e30b2d3..52ada65 100644 --- a/src/main/java/com/license/controller/LicenseController.java +++ b/src/main/java/com/license/controller/LicenseController.java @@ -1,26 +1,17 @@ package com.license.controller; -import cn.hutool.core.map.MapUtil; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import cn.hutool.log.Log; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; import com.license.bean.LicenseInfo; import com.license.bean.Rets; -import com.license.cache.CacheManager; import com.license.utils.Constant; -import com.license.utils.GetIpProtUtil; import com.license.utils.HaspUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.*; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.client.RestTemplate; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.util.Map; -import java.util.concurrent.CompletableFuture; +import cn.hutool.log.Log; /** * @author fengjunfeng @@ -33,8 +24,6 @@ public class LicenseController { private static final Log log = Log.get(); @Autowired public RestTemplate restTemplate; - @Value("${bifang-api.server.port}") - private String port; /** * license锁信息交互 * @@ -42,15 +31,12 @@ public class LicenseController { */ @PostMapping("/licenseOperation") public Object licenseOperation(@RequestBody LicenseInfo licenseInfo) { - if (!verify(licenseInfo.getServerId())){ - return Rets.failure(""); - } if (licenseInfo.getType().equals(Constant.LICENSE_C2V)){ //获取C2V信息 return Rets.success(HaspUtil.readC2V(licenseInfo.getVendorCode(),licenseInfo.getFeatureId())); }else if (licenseInfo.getType().equals(Constant.LICENSE_UPDATE)){ //上传license信息 - return Rets.success(HaspUtil.updateKeyWithLicense(licenseInfo.getV2C())); + return Rets.success(HaspUtil.updateKeyWithLicense(licenseInfo.getParam())); }else if (licenseInfo.getType().equals(Constant.LICENSE_QUERY)){ //获取license信息 return Rets.success(HaspUtil.getLicenseInfo(licenseInfo.getVendorCode(),licenseInfo.getFeatureId())); @@ -62,44 +48,10 @@ public class LicenseController { return Rets.failure(""); } } - - /** - * - * @author fengjunfeng - * @date 2022/1/20 - * @time 11:14 - * @description - * - **/ - public boolean verify(String serverId){ - try { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - HttpEntity httpEntity = new HttpEntity<>(null, headers); - String url = "http://" + GetIpProtUtil.getLocalIP() +":" + port + "/getServerId"; - String str = restTemplate.exchange(url, HttpMethod.GET,httpEntity,String.class).getBody(); - log.info("license bifang_api server id: {}", str); - if (str.equals(serverId)){ - return true; - } - }catch (SocketException | UnknownHostException e){ - log.error("获取ip出错"); - } - return false; + + public static void main(String[] args) { + String vendorCode="AzIceaqfA1hX5wS+M8cGnYh5ceevUnOZIzJBbXFD6dgf3tBkb9cvUF/Tkd/iKu2fsg9wAysYKw7RMAsVvIp4KcXle/v1RaXrLVnNBJ2H2DmrbUMOZbQUFXe698qmJsqNpLXRA367xpZ54i8kC5DTXwDhfxWTOZrBrh5sRKHcoVLumztIQjgWh37AzmSd1bLOfUGI0xjAL9zJWO3fRaeB0NS2KlmoKaVT5Y04zZEc06waU2r6AU2Dc4uipJqJmObqKM+tfNKAS0rZr5IudRiC7pUwnmtaHRe5fgSI8M7yvypvm+13Wm4Gwd4VnYiZvSxf8ImN3ZOG9wEzfyMIlH2+rKPUVHI+igsqla0Wd9m7ZUR9vFotj1uYV0OzG7hX0+huN2E/IdgLDjbiapj1e2fKHrMmGFaIvI6xzzJIQJF9GiRZ7+0jNFLKSyzX/K3JAyFrIPObfwM+y+zAgE1sWcZ1YnuBhICyRHBhaJDKIZL8MywrEfB2yF+R3k9wFG1oN48gSLyfrfEKuB/qgNp+BeTruWUk0AwRE9XVMUuRbjpxa4YA67SKunFEgFGgUfHBeHJTivvUl0u4Dki1UKAT973P+nXy2O0u239If/kRpNUVhMg8kpk7s8i6Arp7l/705/bLCx4kN5hHHSXIqkiG9tHdeNV8VYo5+72hgaCx3/uVoVLmtvxbOIvo120uTJbuLVTvT8KtsOlb3DxwUrwLzaEMoAQAFk6Q9bNipHxfkRQER4kR7IYTMzSoW5mxh3H9O8Ge5BqVeYMEW36q9wnOYfxOLNw6yQMf8f9sJN4KhZty02xm707S7VEfJJ1KNq7b5pP/3RjE0IKtB2gE6vAPRvRLzEohu0m7q1aUp8wAvSiqjZy7FLaTtLEApXYvLvz6PEJdj4TegCZugj7c8bIOEqLXmloZ6EgVnjQ7/ttys7VFITB3mazzFiyQuKf4J6+b/a/Y"; + String licenseInfo = HaspUtil.readC2V(vendorCode,30000); + System.out.println(licenseInfo); } - - -// @PostMapping("/test") -// public Object test() { -// verify("1111"); -// -// if (CacheManager.getCache("test") == null){ -// CacheManager.addCache("test","11111"); -// }else { -// System.out.println(CacheManager.getCache("test")); -// } -// return null; -// } - } diff --git a/src/main/java/com/license/utils/HaspUtil.java b/src/main/java/com/license/utils/HaspUtil.java index 0cf8a38..a5da410 100644 --- a/src/main/java/com/license/utils/HaspUtil.java +++ b/src/main/java/com/license/utils/HaspUtil.java @@ -1,16 +1,14 @@ package com.license.utils; import Aladdin.Hasp; import Aladdin.HaspStatus; -import cn.hutool.core.util.XmlUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.log.Log; -import org.w3c.dom.Document; -import org.w3c.dom.Element; public class HaspUtil { private static final Log log = Log.get(); /** Runtime query scope */ - protected final static String KEY_SCOPE = "\n" + protected final static String KEY_SCOPE = "\n" + "\n" + "\n" + "\n"; @@ -33,7 +31,7 @@ public class HaspUtil { protected final static String KEY_C2V_FORMAT = ""; - protected final static String KEY_ID_FORMAT = "\n" + + protected final static String KEY_ID_FORMAT = "\n" + "\n" + " \n" + " \n" + @@ -112,11 +110,10 @@ public class HaspUtil { int status = hasp.getLastError(); log.info("query license status: {}", status); if(status == HaspStatus.HASP_STATUS_OK) { - String licenseInfo = hasp.getSessionInfo(LICENSE_STATUS); + String licenseInfo = hasp.getSessionInfo(ALL_FORMAT); status = hasp.getLastError(); -// log.info("license status: {}", status); if (status != HaspStatus.HASP_STATUS_OK) { - + log.error("Error: updateLicense Fails with status code :{}", StrUtil.toString(HaspStatusEnum.getHaspStatusByStatus(status))); } return licenseInfo; }else if (status == HaspStatus.HASP_FEATURE_EXPIRED){ @@ -158,41 +155,22 @@ public class HaspUtil { */ public static String readC2V(String vendorCode, Integer featureId) { Hasp hasp = new Hasp(featureId); + String infos = ""; hasp.login(vendorCode); int status = hasp.getLastError(); -// log.info("license status: {}", status); - if(status == HaspStatus.HASP_STATUS_OK) { - //如果已经安装过license ,读取指纹和 hasp id - String licenseInfo = hasp.getSessionInfo(KEY_C2V_FORMAT); - -// String info = hasp.getSessionInfo(KEY_ID_FORMAT); -// Document document = XmlUtil.parseXml(info); -// Element rootEle = document.getDocumentElement(); -// Element haspElement=XmlUtil.getElement(rootEle,"hasp"); -// String id = haspElement.getAttribute("id"); -// String licenseInfo = hasp.getInfo("\n" + -// "\n" + -// " \n" + -// "",KEY_C2V_FORMAT,vendorCode); - status = hasp.getLastError(); - log.info("getLicense c2v license status: {}", status); - if (status != HaspStatus.HASP_STATUS_OK) { - log.error("Error: Download Fails with status code :{}",status); - } - return licenseInfo; - }else { + log.info("login status:"+status); + infos = hasp.getInfo(KEY_SCOPE, KEY_C2V_FORMAT, vendorCode); + if(infos == null || infos.equals("")) { hasp = new Hasp(featureId); - String infos = hasp.getInfo(KEY_SCOPE, KEY_VIEW, vendorCode); + infos = hasp.getInfo(KEY_SCOPE, KEY_VIEW, vendorCode); status = hasp.getLastError(); log.info("getLicense c2v license status: {}", status); if(status != HaspStatus.HASP_STATUS_OK) { log.error("Error: getLicense c2v Fails with status code :{}",status); throw new RuntimeException(); } - return infos; } + return infos; } public static int verify(String vendorCode, Integer fetureId) { @@ -206,6 +184,4 @@ public class HaspUtil { hasp.logout(); return status; } - - } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 11359b6..9c7d8f8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -9,7 +9,7 @@ server.tomcat.min-spare-threads=100 #server.address=127.0.0.1 -bifang-api.server.port=8080 +cn-api.server.port=8090 #设置连接超时时间,单位毫秒 http.connectTimeout=120000 #http clilent中从connetcion pool中获得一个connection的超时时间,单位毫秒