调整生成c2v方式getInfo

This commit is contained in:
fengjunfeng
2022-01-10 16:16:10 +08:00
parent 7106c3328d
commit 0552e11b68

View File

@@ -1,8 +1,10 @@
package com.sentinel.license.utils; package com.sentinel.license.utils;
import Aladdin.Hasp; import Aladdin.Hasp;
import Aladdin.HaspStatus; import Aladdin.HaspStatus;
import cn.hutool.core.util.XmlUtil;
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 {
@@ -31,6 +33,13 @@ 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" +
"<haspformat root=\"haspscope\">\n" +
" <hasp>\n" +
" <attribute name=\"id\" />\n" +
" </hasp>\n" +
"</haspformat>";
public final static String ALL_FORMAT = "<haspformat>\n" + public final static String ALL_FORMAT = "<haspformat>\n" +
" <hasp>\n" + " <hasp>\n" +
" <element name=\"id\"/>\n" + " <element name=\"id\"/>\n" +
@@ -154,8 +163,17 @@ public class HaspUtil {
// log.info("license status: {}", status); // log.info("license status: {}", status);
if(status == HaspStatus.HASP_STATUS_OK) { if(status == HaspStatus.HASP_STATUS_OK) {
//如果已经安装过license ,读取指纹和 hasp id //如果已经安装过license ,读取指纹和 hasp id
// String licenseInfo = hasp.getSessionInfo(KEY_C2V_FORMAT); String info = hasp.getSessionInfo(KEY_ID_FORMAT);
String licenseInfo = hasp.getInfo(KEY_SCOPE,KEY_C2V_FORMAT,vendorCode); 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(); 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) {