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
This commit is contained in:
@@ -11,7 +11,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class LicenseInfo {
|
public class LicenseInfo {
|
||||||
|
|
||||||
private String V2C;
|
private String param;
|
||||||
|
|
||||||
private String vendorCode;
|
private String vendorCode;
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,17 @@
|
|||||||
package com.license.controller;
|
package com.license.controller;
|
||||||
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import cn.hutool.json.JSONObject;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import cn.hutool.json.JSONUtil;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import cn.hutool.log.Log;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import com.license.bean.LicenseInfo;
|
import com.license.bean.LicenseInfo;
|
||||||
import com.license.bean.Rets;
|
import com.license.bean.Rets;
|
||||||
import com.license.cache.CacheManager;
|
|
||||||
import com.license.utils.Constant;
|
import com.license.utils.Constant;
|
||||||
import com.license.utils.GetIpProtUtil;
|
|
||||||
import com.license.utils.HaspUtil;
|
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 cn.hutool.log.Log;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author fengjunfeng
|
* @author fengjunfeng
|
||||||
@@ -33,8 +24,6 @@ public class LicenseController {
|
|||||||
private static final Log log = Log.get();
|
private static final Log log = Log.get();
|
||||||
@Autowired
|
@Autowired
|
||||||
public RestTemplate restTemplate;
|
public RestTemplate restTemplate;
|
||||||
@Value("${bifang-api.server.port}")
|
|
||||||
private String port;
|
|
||||||
/**
|
/**
|
||||||
* license锁信息交互
|
* license锁信息交互
|
||||||
*
|
*
|
||||||
@@ -42,15 +31,12 @@ public class LicenseController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/licenseOperation")
|
@PostMapping("/licenseOperation")
|
||||||
public Object licenseOperation(@RequestBody LicenseInfo licenseInfo) {
|
public Object licenseOperation(@RequestBody LicenseInfo licenseInfo) {
|
||||||
if (!verify(licenseInfo.getServerId())){
|
|
||||||
return Rets.failure("");
|
|
||||||
}
|
|
||||||
if (licenseInfo.getType().equals(Constant.LICENSE_C2V)){
|
if (licenseInfo.getType().equals(Constant.LICENSE_C2V)){
|
||||||
//获取C2V信息
|
//获取C2V信息
|
||||||
return Rets.success(HaspUtil.readC2V(licenseInfo.getVendorCode(),licenseInfo.getFeatureId()));
|
return Rets.success(HaspUtil.readC2V(licenseInfo.getVendorCode(),licenseInfo.getFeatureId()));
|
||||||
}else if (licenseInfo.getType().equals(Constant.LICENSE_UPDATE)){
|
}else if (licenseInfo.getType().equals(Constant.LICENSE_UPDATE)){
|
||||||
//上传license信息
|
//上传license信息
|
||||||
return Rets.success(HaspUtil.updateKeyWithLicense(licenseInfo.getV2C()));
|
return Rets.success(HaspUtil.updateKeyWithLicense(licenseInfo.getParam()));
|
||||||
}else if (licenseInfo.getType().equals(Constant.LICENSE_QUERY)){
|
}else if (licenseInfo.getType().equals(Constant.LICENSE_QUERY)){
|
||||||
//获取license信息
|
//获取license信息
|
||||||
return Rets.success(HaspUtil.getLicenseInfo(licenseInfo.getVendorCode(),licenseInfo.getFeatureId()));
|
return Rets.success(HaspUtil.getLicenseInfo(licenseInfo.getVendorCode(),licenseInfo.getFeatureId()));
|
||||||
@@ -62,44 +48,10 @@ public class LicenseController {
|
|||||||
return Rets.failure("");
|
return Rets.failure("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
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";
|
||||||
* @author fengjunfeng
|
String licenseInfo = HaspUtil.readC2V(vendorCode,30000);
|
||||||
* @date 2022/1/20
|
System.out.println(licenseInfo);
|
||||||
* @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<JSONObject> 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
package com.license.utils;
|
package com.license.utils;
|
||||||
import Aladdin.Hasp;
|
import Aladdin.Hasp;
|
||||||
import Aladdin.HaspStatus;
|
import Aladdin.HaspStatus;
|
||||||
import cn.hutool.core.util.XmlUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.log.Log;
|
import cn.hutool.log.Log;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
|
|
||||||
public class HaspUtil {
|
public class HaspUtil {
|
||||||
private static final Log log = Log.get();
|
private static final Log log = Log.get();
|
||||||
/** Runtime query scope */
|
/** Runtime query scope */
|
||||||
protected final static String KEY_SCOPE = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
protected final static String KEY_SCOPE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||||
+ "<haspscope>\n"
|
+ "<haspscope>\n"
|
||||||
+ "<license_manager hostname=\"localhost\" />\n"
|
+ "<license_manager hostname=\"localhost\" />\n"
|
||||||
+ "</haspscope>\n";
|
+ "</haspscope>\n";
|
||||||
@@ -33,7 +31,7 @@ public class HaspUtil {
|
|||||||
|
|
||||||
protected final static String KEY_C2V_FORMAT = "<haspformat format=\"updateinfo\"/>";
|
protected final static String KEY_C2V_FORMAT = "<haspformat format=\"updateinfo\"/>";
|
||||||
|
|
||||||
protected final static String KEY_ID_FORMAT = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
protected final static String KEY_ID_FORMAT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||||
"<haspformat root=\"haspscope\">\n" +
|
"<haspformat root=\"haspscope\">\n" +
|
||||||
" <hasp>\n" +
|
" <hasp>\n" +
|
||||||
" <attribute name=\"id\" />\n" +
|
" <attribute name=\"id\" />\n" +
|
||||||
@@ -112,11 +110,10 @@ public class HaspUtil {
|
|||||||
int status = hasp.getLastError();
|
int status = hasp.getLastError();
|
||||||
log.info("query license status: {}", status);
|
log.info("query license status: {}", status);
|
||||||
if(status == HaspStatus.HASP_STATUS_OK) {
|
if(status == HaspStatus.HASP_STATUS_OK) {
|
||||||
String licenseInfo = hasp.getSessionInfo(LICENSE_STATUS);
|
String licenseInfo = hasp.getSessionInfo(ALL_FORMAT);
|
||||||
status = hasp.getLastError();
|
status = hasp.getLastError();
|
||||||
// log.info("license status: {}", status);
|
|
||||||
if (status != HaspStatus.HASP_STATUS_OK) {
|
if (status != HaspStatus.HASP_STATUS_OK) {
|
||||||
|
log.error("Error: updateLicense Fails with status code :{}", StrUtil.toString(HaspStatusEnum.getHaspStatusByStatus(status)));
|
||||||
}
|
}
|
||||||
return licenseInfo;
|
return licenseInfo;
|
||||||
}else if (status == HaspStatus.HASP_FEATURE_EXPIRED){
|
}else if (status == HaspStatus.HASP_FEATURE_EXPIRED){
|
||||||
@@ -158,41 +155,22 @@ public class HaspUtil {
|
|||||||
*/
|
*/
|
||||||
public static String readC2V(String vendorCode, Integer featureId) {
|
public static String readC2V(String vendorCode, Integer featureId) {
|
||||||
Hasp hasp = new Hasp(featureId);
|
Hasp hasp = new Hasp(featureId);
|
||||||
|
String infos = "";
|
||||||
hasp.login(vendorCode);
|
hasp.login(vendorCode);
|
||||||
int status = hasp.getLastError();
|
int status = hasp.getLastError();
|
||||||
// log.info("license status: {}", status);
|
log.info("login status:"+status);
|
||||||
if(status == HaspStatus.HASP_STATUS_OK) {
|
infos = hasp.getInfo(KEY_SCOPE, KEY_C2V_FORMAT, vendorCode);
|
||||||
//如果已经安装过license ,读取指纹和 hasp id
|
if(infos == null || infos.equals("")) {
|
||||||
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("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
|
||||||
// "<haspscope>\n" +
|
|
||||||
// " <hasp " +
|
|
||||||
// "id= \"" + id +"\""+
|
|
||||||
// "/>\n" +
|
|
||||||
// "</haspscope>",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 {
|
|
||||||
hasp = new Hasp(featureId);
|
hasp = new Hasp(featureId);
|
||||||
String infos = hasp.getInfo(KEY_SCOPE, KEY_VIEW, vendorCode);
|
infos = hasp.getInfo(KEY_SCOPE, KEY_VIEW, vendorCode);
|
||||||
status = hasp.getLastError();
|
status = hasp.getLastError();
|
||||||
log.info("getLicense c2v license status: {}", status);
|
log.info("getLicense c2v license status: {}", status);
|
||||||
if(status != HaspStatus.HASP_STATUS_OK) {
|
if(status != HaspStatus.HASP_STATUS_OK) {
|
||||||
log.error("Error: getLicense c2v Fails with status code :{}",status);
|
log.error("Error: getLicense c2v Fails with status code :{}",status);
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
return infos;
|
|
||||||
}
|
}
|
||||||
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int verify(String vendorCode, Integer fetureId) {
|
public static int verify(String vendorCode, Integer fetureId) {
|
||||||
@@ -206,6 +184,4 @@ public class HaspUtil {
|
|||||||
hasp.logout();
|
hasp.logout();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ server.tomcat.min-spare-threads=100
|
|||||||
|
|
||||||
#server.address=127.0.0.1
|
#server.address=127.0.0.1
|
||||||
|
|
||||||
bifang-api.server.port=8080
|
cn-api.server.port=8090
|
||||||
#设置连接超时时间,单位毫秒
|
#设置连接超时时间,单位毫秒
|
||||||
http.connectTimeout=120000
|
http.connectTimeout=120000
|
||||||
#http clilent中从connetcion pool中获得一个connection的超时时间,单位毫秒
|
#http clilent中从connetcion pool中获得一个connection的超时时间,单位毫秒
|
||||||
|
|||||||
Reference in New Issue
Block a user