From 06d462ebb064370c8873927fa553ee5eaade4b5e Mon Sep 17 00:00:00 2001 From: 4iot-dev Date: Thu, 28 Nov 2019 12:03:00 +0800 Subject: [PATCH] =?UTF-8?q?[opt]=E7=A4=BA=E4=BE=8B=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E3=80=82=E6=96=87=E6=A1=A3=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Change.md | 6 +- .../IdentifierValueDemo.java | 2 +- .../ManageIdentifierDemo.java | 26 +- IDIS-SDK开发指南.md | 258 +++++++++--------- README.md | 120 ++++---- apidoc.md | 87 +++--- 6 files changed, 256 insertions(+), 243 deletions(-) diff --git a/Change.md b/Change.md index c0b0fc2..eda3463 100644 --- a/Change.md +++ b/Change.md @@ -3,7 +3,7 @@ * * * **Changes in 2.0.1** -适用IDIS版本:企业版本V1.3.1-2 +适用标识系统版本:企业版本v1.3.1-2 二级节点版本v1.2.4-6 递归服务版本2.3.1 [add] 获取站点信息接口 @@ -15,11 +15,11 @@ [opt] 使用UDP协议创建channel时优化掉长连接;其他日志优化。 - 2019-11-25 + 2019-11-28 * * * **Changes in 2.0.0** -适用IDIS版本:企业版本V1.3.1-0 +适用标识系统版本:企业版本v1.3.1-0 [add] 通道管理接口 diff --git a/IDIS-SDK-DEMO/src/identifiermanageDemo/IdentifierValueDemo.java b/IDIS-SDK-DEMO/src/identifiermanageDemo/IdentifierValueDemo.java index a7c80e0..78c2ebe 100644 --- a/IDIS-SDK-DEMO/src/identifiermanageDemo/IdentifierValueDemo.java +++ b/IDIS-SDK-DEMO/src/identifiermanageDemo/IdentifierValueDemo.java @@ -71,7 +71,7 @@ public class IdentifierValueDemo { String SIGNATURE_PRVKEY_PATH = "D:/rsakeys/rsa_pri.pem"; PrivateKey prvKey = Util.getPrivateKeyFromFile(SIGNATURE_PRVKEY_PATH, null); SignatureInfo signInfo = SignatureInfo.newSignatureInstance(prvKey, values, "300:88.996", "88.996.438", - "2020-12-12 23:59:59", "2019-11-25 00:00:00", "2019-11-24 15:44:00", "SM3"); + "2020-12-12 23:59:59", "2019-11-25 00:00:00", "2019-11-24 15:44:00", "SHA-256"); IdentifierValueUtil.makeIdentifierValueOfSignature(value, index, signInfo); return value; } diff --git a/IDIS-SDK-DEMO/src/identifiermanageDemo/ManageIdentifierDemo.java b/IDIS-SDK-DEMO/src/identifiermanageDemo/ManageIdentifierDemo.java index aef3db1..ba8d3b4 100644 --- a/IDIS-SDK-DEMO/src/identifiermanageDemo/ManageIdentifierDemo.java +++ b/IDIS-SDK-DEMO/src/identifiermanageDemo/ManageIdentifierDemo.java @@ -3,6 +3,7 @@ package identifiermanageDemo; import cn.ac.caict.iiiiot.idisc.core.BaseResponse; import cn.ac.caict.iiiiot.idisc.core.ErrorResponse; import cn.ac.caict.iiiiot.idisc.core.IdentifierException; +import cn.ac.caict.iiiiot.idisc.core.SiteResponse; import cn.ac.caict.iiiiot.idisc.data.IdentifierValue; import cn.ac.caict.iiiiot.idisc.data.MsgSettings; import cn.ac.caict.iiiiot.idisc.service.IChannelManageService; @@ -48,6 +49,9 @@ public class ManageIdentifierDemo { demo_deleteIdentifier(channel); // 删除标识后查询 demo_lookupIdentifier(channel); + + // 获取站点信息 + demo_getSiteInfo(channel); } } //关闭channel @@ -57,6 +61,25 @@ public class ManageIdentifierDemo { System.out.println("创建通道失败!"); } } + + private static void demo_getSiteInfo(IIDManageServiceChannel channel){ + if(channel != null){ + try { + BaseResponse response = channel.getServerSiteInfo(new MsgSettings()); + if(response != null && response.responseCode == 1){ + SiteResponse siteResp = (SiteResponse)response; + System.out.println("站点信息获取成功:" + siteResp.getSiteInfo()); + } else if(response instanceof ErrorResponse){ + System.out.println(((ErrorResponse)response).toString()); + } else { + System.out.println("错误的响应:" + response); + } + } catch (IdentifierException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } private static void demo_deleteIdentifier(IIDManageServiceChannel channel) { // TODO 删除标识 @@ -201,7 +224,8 @@ public class ManageIdentifierDemo { // 生成摘要的Hash类型 int hashType = 1; try { - BaseResponse loginResp = channel.login(userId,index,privatekeyPath,password,hashType); + //BaseResponse loginResp = channel.login(userId,index,privatekeyPath,password,hashType); + BaseResponse loginResp = channel.login(userId,index,privatekeyPath,password,hashType,new MsgSettings()); if(loginResp != null && loginResp.responseCode == 1){ System.out.println("登录成功!"); } else if(loginResp instanceof ErrorResponse){ diff --git a/IDIS-SDK开发指南.md b/IDIS-SDK开发指南.md index 2b832ed..a19c49b 100644 --- a/IDIS-SDK开发指南.md +++ b/IDIS-SDK开发指南.md @@ -1,129 +1,129 @@ -## IDIS-SDK开发指南 - -#### 基本概念介绍: -IDIS:智能分布式标识系统 -IDIS-SDK:IDIS系统开发包 -管理操作:创建标识、删除标识、添加标识值、修改标识值、移除标识值。 -非管理操作:主要是查询操作。 -通道:IDIS-SDK与IDIS系统之间的连接。 - -#### IDIS-SDK与IDIS版本对应关系说明 -> |IDIS-SDK版本|IDIS版本 | -> | :-------- | :--------| ->|2.0.0 |企业版1.3.1 | - -#### 快速使用 -1. jar包获取:下载开源项目IDIS-SDK,导出jar包,并从该项目中获取依赖jar包,log4j-1.2.17.jar、gson-2.3.1.jar、commons-codec-1.12.jar、commons-logging-1.2.jar。 -2. 环境要求:jdk1.8或以上。 -3. 开发示例: -建立java项目,导入IDIS-SDK的jar包以及其依赖的jar包,根据我们提供的联系方式(参见[README.md](./README.md))获取到IDIS服务信息以及登录信息以后,通过以下三个步骤可以快速进行开发: -1). 创建通道管理实例IChannelManageService -2). 创建与IDIS连接的通道实例IIDManageServiceChannel,此处需要提供IDIS服务的IP地址和端口号,采用“TCP”传输协议 -3). 通道实例IIDManageServiceChannel创建成功,即可以进行查询操作,若要进行标识管理操作,需要首先执行登录操作,登录成功以后可以进行各项管理操作 -如图: -![Alt text](./res/pic1.jpg) - -Demo如下: -```java -package test1; - -import cn.ac.caict.iiiiot.idisc.core.BaseResponse; -import cn.ac.caict.iiiiot.idisc.core.ErrorResponse; -import cn.ac.caict.iiiiot.idisc.core.IdentifierException; -import cn.ac.caict.iiiiot.idisc.data.IdentifierValue; -import cn.ac.caict.iiiiot.idisc.data.MsgSettings; -import cn.ac.caict.iiiiot.idisc.service.IChannelManageService; -import cn.ac.caict.iiiiot.idisc.service.IIDManageServiceChannel; -import cn.ac.caict.iiiiot.idisc.service.impl.ChannelManageServiceImpl; - -public class TestManageConnection { - public static final int CHANNEL_CLOSED = 0; - public static final int CHANNEL_LOGIN = 1; - public static final int CHANNEL_LOGOUT = 2; - public static void main(String[] args) { - //创建通道管理实例 - IChannelManageService idfService = new ChannelManageServiceImpl(); - try { - //根据IDIS系统提供的ip和端口,创建与IDIS的连接通道对象 - IIDManageServiceChannel channel = idfService.generateChannel("192.168.150.13", 1304, "TCP"); - //若要对标识进行管理操作,则需要首先登录 - if (channel != null && idfService.getIDManageServiceChannelState(channel) == CHANNEL_LOGOUT) { - //登录 - BaseResponse loginResp = testLogin(channel); - if(loginResp != null && loginResp.responseCode == 1){ - System.out.println("登录成功!"); - //创建标识 - BaseResponse createResp = testCreate(channel); - if(createResp != null && createResp.responseCode == 1){ - System.out.println("标识创建成功!"); - } else if(createResp != null && createResp instanceof ErrorResponse){ - System.out.println(((ErrorResponse)createResp).toString()); - } - //添加标识值 - //BaseResponse addResp = testAdd(channel); - //修改标识值 - //BaseResponse editResp = testEdit(channel); - //移除标识值 - //BaseResponse rmResp = testRemove(channel); - //删除标识 - //BaseResponse delResp = testDelete(channel); - //if(delResp != null && delResp.responseCode == 1) - // System.out.println("删除成功!"); - } - } - //通道未登录也可以执行查询操作 - BaseResponse resp = testLookup(channel); - System.out.println(resp); - - } catch (IdentifierException e) { - e.printStackTrace(); - } - } - private static BaseResponse testLogin(IIDManageServiceChannel channel) throws IdentifierException{ - return channel.login("88.1000.1/ADMIN", 301, "C:\\keys\\rsa_pri.pem", null,1); - } - private static BaseResponse testDelete(IIDManageServiceChannel channel) throws IdentifierException{ - return channel.deleteIdentifier("88.1000.2/mm", new MsgSettings()); - } - - private static BaseResponse testCreate(IIDManageServiceChannel channel) throws IdentifierException{ - IdentifierValue[] values = new IdentifierValue[5]; - values[0] = new IdentifierValue(1, "URL", "www.aaa.com"); - values[1] = new IdentifierValue(2, "email", "www.163.com"); - values[2] = new IdentifierValue(3, "url", "www.ccc.com"); - values[3] = new IdentifierValue(4, "email", "www.ddd.com"); - values[4] = new IdentifierValue(5, "email", "www.fff.com"); - return channel.createIdentifier("88.1000.2/mm", values, new MsgSettings()); - } - - private static BaseResponse testAdd(IIDManageServiceChannel channel) throws IdentifierException{ - IdentifierValue[] values = new IdentifierValue[2]; - values[0] = new IdentifierValue(6, "URL", "www.666.com"); - values[1] = new IdentifierValue(7, "email", "www.777.com"); - return channel.addIdentifierValues("88.1000.2/mm", values, new MsgSettings()); - } - - private static BaseResponse testEdit(IIDManageServiceChannel channel) throws IdentifierException{ - IdentifierValue[] values = new IdentifierValue[2]; - values[0] = new IdentifierValue(6, "email", "www.666e.com"); - values[1] = new IdentifierValue(7, "url", "www.777e.com"); - return channel.modifyIdentifierValues("88.1000.2/mm", values, new MsgSettings()); - } - - private static BaseResponse testRemove(IIDManageServiceChannel channel) throws IdentifierException{ - IdentifierValue[] values = new IdentifierValue[2]; - values[0] = new IdentifierValue(6, "email", "www.666e.com"); - values[1] = new IdentifierValue(7, "url", "www.777e.com"); - int[] arr = {6,7}; - return channel.removeIdentifierValues("88.1000.2/mm", arr, null); - } - - private static BaseResponse testLookup(IIDManageServiceChannel channel) throws IdentifierException{ - String identifier = "88.1000.2/mm"; - int[] arr = null; - String[] types = null; - return channel.lookupIdentifier(identifier, arr, types, null); - } - -} -``` +## IDIS-SDK开发指南 + +#### 基本概念介绍: +IDIS:智能分布式标识系统 +IDIS-SDK:IDIS系统开发包 +管理操作:创建标识、删除标识、添加标识值、修改标识值、移除标识值。 +非管理操作:主要是查询操作。 +通道:IDIS-SDK与IDIS系统之间的连接。 + +#### IDIS-SDK与IDIS版本对应关系说明 +> |IDIS-SDK版本|IDIS版本 | +> | :-------- | :--------| +>|2.0.0 |企业版1.3.1 | + +#### 快速使用 +1. jar包获取:下载开源项目IDIS-SDK,导出jar包,并从该项目中获取依赖jar包,log4j-1.2.17.jar、gson-2.3.1.jar、commons-codec-1.12.jar、commons-logging-1.2.jar、bcprov-jdk15on-1.62.jar、hutool-all-4.6.3.jar。 +2. 环境要求:jdk1.8或以上。 +3. 开发示例: +建立java项目,导入IDIS-SDK的jar包以及其依赖的jar包,根据我们提供的联系方式(参见[README.md](./README.md))获取到IDIS服务信息以及登录信息以后,通过以下三个步骤可以快速进行开发: +1). 创建通道管理实例IChannelManageService +2). 创建与IDIS连接的通道实例IIDManageServiceChannel,此处需要提供IDIS服务的IP地址和端口号,采用“TCP”传输协议 +3). 通道实例IIDManageServiceChannel创建成功,即可以进行查询操作,若要进行标识管理操作,需要首先执行登录操作,登录成功以后可以进行各项管理操作 +如图: +![Alt text](./res/pic1.jpg) + +Demo如下: +```java +package test1; + +import cn.ac.caict.iiiiot.idisc.core.BaseResponse; +import cn.ac.caict.iiiiot.idisc.core.ErrorResponse; +import cn.ac.caict.iiiiot.idisc.core.IdentifierException; +import cn.ac.caict.iiiiot.idisc.data.IdentifierValue; +import cn.ac.caict.iiiiot.idisc.data.MsgSettings; +import cn.ac.caict.iiiiot.idisc.service.IChannelManageService; +import cn.ac.caict.iiiiot.idisc.service.IIDManageServiceChannel; +import cn.ac.caict.iiiiot.idisc.service.impl.ChannelManageServiceImpl; + +public class TestManageConnection { + public static final int CHANNEL_CLOSED = 0; + public static final int CHANNEL_LOGIN = 1; + public static final int CHANNEL_LOGOUT = 2; + public static void main(String[] args) { + //创建通道管理实例 + IChannelManageService idfService = new ChannelManageServiceImpl(); + try { + //根据IDIS系统提供的ip和端口,创建与IDIS的连接通道对象 + IIDManageServiceChannel channel = idfService.generateChannel("192.168.150.13", 1304, "TCP"); + //若要对标识进行管理操作,则需要首先登录 + if (channel != null && idfService.getIDManageServiceChannelState(channel) == CHANNEL_LOGOUT) { + //登录 + BaseResponse loginResp = testLogin(channel); + if(loginResp != null && loginResp.responseCode == 1){ + System.out.println("登录成功!"); + //创建标识 + BaseResponse createResp = testCreate(channel); + if(createResp != null && createResp.responseCode == 1){ + System.out.println("标识创建成功!"); + } else if(createResp != null && createResp instanceof ErrorResponse){ + System.out.println(((ErrorResponse)createResp).toString()); + } + //添加标识值 + //BaseResponse addResp = testAdd(channel); + //修改标识值 + //BaseResponse editResp = testEdit(channel); + //移除标识值 + //BaseResponse rmResp = testRemove(channel); + //删除标识 + //BaseResponse delResp = testDelete(channel); + //if(delResp != null && delResp.responseCode == 1) + // System.out.println("删除成功!"); + } + } + //通道未登录也可以执行查询操作 + BaseResponse resp = testLookup(channel); + System.out.println(resp); + + } catch (IdentifierException e) { + e.printStackTrace(); + } + } + private static BaseResponse testLogin(IIDManageServiceChannel channel) throws IdentifierException{ + return channel.login("88.1000.1/ADMIN", 301, "C:\\keys\\rsa_pri.pem", null,1,new MsgSettings()); + } + private static BaseResponse testDelete(IIDManageServiceChannel channel) throws IdentifierException{ + return channel.deleteIdentifier("88.1000.2/mm", new MsgSettings()); + } + + private static BaseResponse testCreate(IIDManageServiceChannel channel) throws IdentifierException{ + IdentifierValue[] values = new IdentifierValue[5]; + values[0] = new IdentifierValue(1, "URL", "www.aaa.com"); + values[1] = new IdentifierValue(2, "email", "www.163.com"); + values[2] = new IdentifierValue(3, "url", "www.ccc.com"); + values[3] = new IdentifierValue(4, "email", "www.ddd.com"); + values[4] = new IdentifierValue(5, "email", "www.fff.com"); + return channel.createIdentifier("88.1000.2/mm", values, new MsgSettings()); + } + + private static BaseResponse testAdd(IIDManageServiceChannel channel) throws IdentifierException{ + IdentifierValue[] values = new IdentifierValue[2]; + values[0] = new IdentifierValue(6, "URL", "www.666.com"); + values[1] = new IdentifierValue(7, "email", "www.777.com"); + return channel.addIdentifierValues("88.1000.2/mm", values, new MsgSettings()); + } + + private static BaseResponse testEdit(IIDManageServiceChannel channel) throws IdentifierException{ + IdentifierValue[] values = new IdentifierValue[2]; + values[0] = new IdentifierValue(6, "email", "www.666e.com"); + values[1] = new IdentifierValue(7, "url", "www.777e.com"); + return channel.modifyIdentifierValues("88.1000.2/mm", values, new MsgSettings()); + } + + private static BaseResponse testRemove(IIDManageServiceChannel channel) throws IdentifierException{ + IdentifierValue[] values = new IdentifierValue[2]; + values[0] = new IdentifierValue(6, "email", "www.666e.com"); + values[1] = new IdentifierValue(7, "url", "www.777e.com"); + int[] arr = {6,7}; + return channel.removeIdentifierValues("88.1000.2/mm", arr, null); + } + + private static BaseResponse testLookup(IIDManageServiceChannel channel) throws IdentifierException{ + String identifier = "88.1000.2/mm"; + int[] arr = null; + String[] types = null; + return channel.lookupIdentifier(identifier, arr, types, null); + } + +} +``` diff --git a/README.md b/README.md index 6be4107..7f1e40e 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,60 @@ -简体中文 - -![Alt text](./res/iiit.jpg) - - - -# IDIS-SDK - -## 简介 - -欢迎使用 IDIS-SDK 。智能分布式标识系统即IDIS系统,是由工业互联网与物联网研究所(简称工物所)研发、用于对标识的管理和解析的系统。为方便用户使用该系统,工物所提供了IDIS-SDK以方便IDIS用户定制开发自有系统、快速接入工业互联网标识节点,如下图。这里向您介绍如何获取IDIS-SDK并快速使用。如果您在使用IDIS-SDK的过程中遇到任何问题,欢迎在当前GitHub[提交 Issues](https://github.com/4iot-dev/IDIS-SDK/issues/new)。 -![Alt text](./res/relations.jpg) - - -## 环境要求 - -1. 若您希望通过连接IDIS服务使用、了解IDIS-SDK开源项目,请与我们联系,我们将提供详细的环境资料,以便于您进行快速开发或调试。联系邮箱:fengyuan@caict.ac.cn - -2. IDIS-SDK运行依赖gson-2.3.1.jar、commons-codec-1.12.jar、commons-logging-1.2.jar、log4j-1.2.17.jar。 - 添加依赖包步骤如下: - 在Eclipse项目中导入JAR包将IDIS-SDK-2.0.0.jar以及其依赖的gson-2.3.1.jar,commons-codec-1.12.jar,commons-logging-1.2.jar,log4j-1.2.17.jar拷贝到您的项目中。 - 在Eclipse中选择您的工程,右击选择 Properties > Java Build Path > Add JARs。 - -3. IDIS-SDK需要JDK1.8以上的版本。 -## IDIS-SDK使用 -IDIS-SDK目录:开发包源代码 -IDIS-SDK-DEMO目录:IDIS-SDK开发包演示demo -通过IDIS-SDK连接IDIS系统进行标识操作,参照IDIS-SDK-DEMO,主要分3个步骤: - -1. 创建IDIS-SDK的连接通道管理对象IChannelManageService。 - -2. 使用连接通道管理对象创建与IDIS的连接通道对象IIDManageServiceChannel。 - -3. 通过IIDManageServiceChannel对象可以进行标识查询或者管理操作。 - - 详见[IDIS-SDK开发指南](./IDIS-SDK开发指南.md) - -## 文档 - -- [Change](./Change.md) -- [apidoc](./apidoc.md) -- [LICENSE](./LICENSE) -- [IDIS-SDK开发指南](./IDIS-SDK开发指南.md) - -## 问题反馈 - -[提交 Issue](https://github.com/4iot-dev/IDIS-SDK/issues/new)。 -邮件反馈:fengyuan@caict.ac.cn -我们将尽快给予回复。 - -## 发行说明 - -各版本更新将记录在[Change](./Change.md)中。 - -## 许可证 - -[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0) - -版权所有 2019 工业互联网与物联网研究所 - +简体中文 + +![Alt text](./res/iiit.jpg) + + + +# IDIS-SDK + +## 简介 + +欢迎使用 IDIS-SDK 。智能分布式标识系统即IDIS系统,是由工业互联网与物联网研究所(简称工物所)研发、用于对标识的管理和解析的系统。为方便用户使用该系统,工物所提供了IDIS-SDK以方便IDIS用户定制开发自有系统、快速接入工业互联网标识节点,如下图。这里向您介绍如何获取IDIS-SDK并快速使用。如果您在使用IDIS-SDK的过程中遇到任何问题,欢迎在当前GitHub[提交 Issues](https://github.com/4iot-dev/IDIS-SDK/issues/new)。 +![Alt text](./res/relations.jpg) + + +## 环境要求 + +1. 若您希望通过连接IDIS服务使用、了解IDIS-SDK开源项目,请与我们联系,我们将提供详细的环境资料,以便于您进行快速开发或调试。联系邮箱:fengyuan@caict.ac.cn + +2. IDIS-SDK运行依赖gson-2.3.1.jar、commons-codec-1.12.jar、commons-logging-1.2.jar、log4j-1.2.17.jar、bcprov-jdk15on-1.62.jar、hutool-all-4.6.3.jar。 + 添加依赖包步骤如下: + 在Eclipse项目中导入JAR包将IDIS-SDK-2.0.0.jar以及其依赖的gson-2.3.1.jar,commons-codec-1.12.jar,commons-logging-1.2.jar,log4j-1.2.17.jar,bcprov-jdk15on-1.62.jar,hutool-all-4.6.3.jar拷贝到您的项目中。 + 在Eclipse中选择您的工程,右击选择 Properties > Java Build Path > Add JARs。 + +3. IDIS-SDK需要JDK1.8以上的版本。 +## IDIS-SDK使用 +IDIS-SDK目录:开发包源代码 +IDIS-SDK-DEMO目录:IDIS-SDK开发包演示demo +通过IDIS-SDK连接IDIS系统进行标识操作,参照IDIS-SDK-DEMO,主要分3个步骤: + +1. 创建IDIS-SDK的连接通道管理对象IChannelManageService。 + +2. 使用连接通道管理对象创建与IDIS的连接通道对象IIDManageServiceChannel。 + +3. 通过IIDManageServiceChannel对象可以进行标识查询或者管理操作。 + + 详见[IDIS-SDK开发指南](./IDIS-SDK开发指南.md) + +## 文档 + +- [Change](./Change.md) +- [apidoc](./apidoc.md) +- [LICENSE](./LICENSE) +- [IDIS-SDK开发指南](./IDIS-SDK开发指南.md) + +## 问题反馈 + +[提交 Issue](https://github.com/4iot-dev/IDIS-SDK/issues/new)。 +邮件反馈:fengyuan@caict.ac.cn +我们将尽快给予回复。 + +## 发行说明 + +各版本更新将记录在[Change](./Change.md)中。 + +## 许可证 + +[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0) + +版权所有 2019 工业互联网与物联网研究所 + diff --git a/apidoc.md b/apidoc.md index 040b75d..d9cb192 100644 --- a/apidoc.md +++ b/apidoc.md @@ -215,6 +215,7 @@ try { >|privakeyFilePath |true |String |私钥文件路径,支持pem文件格式私钥 | >|password |false |String |如果私钥有密码,将密码赋值给password,如果私钥没有密码则password为null | >|rdType |true |int |生成摘要hash算法,MD5算法:rdType=1,SH1算法:rdType=2,SH256算法:rdType=3 | +>|settings |false |MsgSettings |消息设置 | ###### 返回值 > |类型|说明 | >| :-------- | :--------| @@ -385,22 +386,19 @@ try { e.printStackTrace(); } ``` -***5.1 兼容的标识类型*** ->|类型名称|数据结构|描述| ->| :-------- | :--------| :--------| ->|HS_SITE |SiteInfo (图-Siteinfo) |站点信息 | ->|HS_SITE.PREFIX |SiteInfo(图-Siteinfo) |前缀站点信息| ->|HS_VLIST |ValueReference(图-VList) |前缀站点信息| ->|HS_CERT |SignatureInfo(图-SignatureInfo) |证书 | ->|HS_SIGNATURE | SignatureInfo(图-SignatureInfo) |签名 | ->|HS_PUBKEY | String(公钥文件路径) |公钥 | ->|HS_ADMIN | AdminInfo(图-AdminInfo) |管理员| ->|HS_SERV | String (标识) |服务引用| - -***5.2 兼容标识类型的标识值构建示例*** - - 为了方便用户创建各类型标识,SDK提供了IdentifierValueUtil工具,对于一些类型简单的标识值,可以直接将字符串数据写入IdentifierValue的结构当中,也可以调用IdentifierValueUtil工具的makeIdentifierValueOfGeneralType方法;对于复杂类型标识值的创建,下文将介绍数据结构及如何利用IdentifierValueUtil工具去创建标识值的示例。 - +***5.1*** 兼容的标识类型 + |类型名称|数据结构|描述| +| :-------- | :--------| +|HS_SITE |SiteInfo (图-Siteinfo) |站点信息 | +|HS_SITE.PREFIX |SiteInfo(图-Siteinfo) |前缀站点信息| +|HS_VLIST |ValueReference(图-VList) |前缀站点信息| +|HS_CERT |SignatureInfo(图-SignatureInfo) |证书 | +|HS_SIGNATURE | SignatureInfo(图-SignatureInfo) |签名 | +|HS_PUBKEY | String(公钥文件路径) |公钥 | +|HS_ADMIN | AdminInfo(图-AdminInfo) |管理员| +|HS_SERV | String (标识) |服务引用| +***5.2*** 兼容标识类型的标识值构建示例 + 为了方便用户创建各类型标识,SDK提供了IdentifierValueUtil工具,对于一些类型简单的标识值,可以直接将字符串数据写入IdentifierValue的结构当中,也可以调用IdentifierValueUtil工具的makeIdentifierValueOfGeneralType方法;对于复杂类型标识值的创建,下文将介绍数据结构及如何利用IdentifierValueUtil工具去创建标识值的示例。 1. 如何创建一个HS_SITE/HS_SITE.PREFIX类型的标识值? HS_SITE 和 HS_SITE.PREFIX是预定义的数据类型。它们的数据结构相同,通过(ip地址:端口号)来定义服务站点。 每个标识解析服务可有多个服务站点,每个服务站点可以由多个服务器计算机组成。针对任何标识解析服务的服务请求可以分布到不同的服务站点,并在任何服务站点内进入不同的服务器计算机。这样的体系结构确保每个标识解析服务都有能力管理大量的标识和标识请求。这种结构可以避免单点故障。 @@ -408,8 +406,7 @@ HS_SITE 和 HS_SITE.PREFIX提供的站点信息可以用来定位负责的标识 1)SiteInfo ![Alt text](./res/SiteInfo.png) - 图-Siteinfo - + 图-Siteinfo 2)java示例 ``` java IdentifierValue iv = new IdentifierValue(); @@ -439,13 +436,10 @@ HS_SITE 和 HS_SITE.PREFIX提供的站点信息可以用来定位负责的标识 ``` 2. 如何创建HS_VLIST类型的标识值? - - 标识值引用列表 - + 标识值引用列表 1)ValueReference数组 ![Alt text](./res/ValueReference.png) - 图-VList - + 图-VList 2)创建HS_VLIST类型标识值示例 ``` java IdentifierValue iv = new IdentifierValue(); @@ -460,7 +454,6 @@ HS_SITE 和 HS_SITE.PREFIX提供的站点信息可以用来定位负责的标识 1)SignatureInfo结构 ![Alt text](./res/SignatureInfo.png) - 图-SignatureInfo 说明: 支持的RSA、SM2密钥对 @@ -468,15 +461,15 @@ HS_SITE 和 HS_SITE.PREFIX提供的站点信息可以用来定位负责的标识 2)创建HS_CERT类型标识值示例 - ``` java - PublicKey pubKey = Util.getPublicKeyFromFile("c:/temp/keys/pubkey.pem"); - PrivateKey prvKey = Util.getPrivateKeyFromFile("c:/temp/keys/privatekey.pem", null); - List perms = new ArrayList<>(); - perms.add(new Permission(null, "everything")); - IdentifierValue iv = new IdentifierValue(); - int index = 401; - SignatureInfo signInfo = SignatureInfo.newCertificationInstance(prvKey, pubKey, perms, "100:88", "300:88.996", "2020-12-12 23:59:59","2019-11-25 00:00:00", "2019-11-24 15:44:00"); - IdentifierValueUtil.makeIdentifierValueOfCertification(iv, index, signInfo); + ```java +PublicKey pubKey = Util.getPublicKeyFromFile("c:/temp/keys/pubkey.pem"); +PrivateKey prvKey = Util.getPrivateKeyFromFile("c:/temp/keys/privatekey.pem", null); +List perms = new ArrayList<>(); +perms.add(new Permission(null, "everything")); +IdentifierValue iv = new IdentifierValue(); +int index = 401; +SignatureInfo signInfo = SignatureInfo.newCertificationInstance(prvKey, pubKey, perms, "100:88", "300:88.996", "2020-12-12 23:59:59","2019-11-25 00:00:00", "2019-11-24 15:44:00"); +IdentifierValueUtil.makeIdentifierValueOfCertification(iv, index, signInfo); ``` 4. 如何创建HS_SIGNATURE类型的标识值? @@ -486,21 +479,21 @@ HS_SITE 和 HS_SITE.PREFIX提供的站点信息可以用来定位负责的标识 2)创建HS_SIGNATURE类型标识值示例 - ``` java - IdentifierValue iv = new IdentifierValue(); - int index = 400; - PrivateKey prvKey = Util.getPrivateKeyFromFile(SIGNATURE_PRVKEY_PATH, null); - IdentifierValue[] values = new IdentifierValue[1]; - BaseResponse response = channel.lookupIdentifier(OP_ID, null, null, null); - if (response instanceof ResolutionResponse) { + ```java +IdentifierValue iv = new IdentifierValue(); +int index = 400; +PrivateKey prvKey = Util.getPrivateKeyFromFile(SIGNATURE_PRVKEY_PATH, null); +IdentifierValue[] values = new IdentifierValue[1]; +BaseResponse response = channel.lookupIdentifier(OP_ID, null, null, null); +if (response instanceof ResolutionResponse) { values = ((ResolutionResponse) response).getAllIDValues(); - } - SignatureInfo signInfo = SignatureInfo.newSignatureInstance(prvKey, values, "300:88.996", "88.996.438","2020-12-12 23:59:59", "2019-11-25 00:00:00", "2019-11-24 15:44:00", "SM3"); - IdentifierValueUtil.makeIdentifierValueOfSignature(iv, index, signInfo); +} +SignatureInfo signInfo = SignatureInfo.newSignatureInstance(prvKey, values, "300:88.996", "88.996.438","2020-12-12 23:59:59", "2019-11-25 00:00:00", "2019-11-24 15:44:00", "SM3"); +IdentifierValueUtil.makeIdentifierValueOfSignature(iv, index, signInfo); ``` 5. 如何创建HS_PUBKEY类型的标识值? - 1) 公钥文件,支持DSA和RSA算法的公钥,创建标识值时提供公钥文件的路径 + 1) 公钥文件,支持DSA和RSA算法的公钥,创建标识值时提供公钥文件的路径 2)创建HS_PUBKEY类型标识值示例 ```java @@ -509,14 +502,10 @@ HS_SITE 和 HS_SITE.PREFIX提供的站点信息可以用来定位负责的标识 IdentifierValueUtil.makeIdentifierValueOfPublicKey(iv, "c:/temp/keys/pubkey.pem", index); ``` 6. 如何创建HS_ADMIN类型的标识值? - - HS_ADMIN值用于标识解析服务在完成任何管理请求之前对标识管理员进行身份验证。 - +HS_ADMIN值用于标识解析服务在完成任何管理请求之前对标识管理员进行身份验证。 1)AdminInfo结构 ![Alt text](./res/AdminInfo.png) - 图-AdminInfo - 2)创建HS_ADMIN类型标识值示例 ```java IdentifierValue value = new IdentifierValue();