@@ -1,45 +0,0 @@ | |||
package com.iformall.controller.market; | |||
import com.iformall.annotation.SystemControllerLog; | |||
import com.iformall.common.ResultData; | |||
import com.iformall.controller.base.BaseController; | |||
import com.iformall.domain.po.PushLimit; | |||
import com.iformall.haikang.alarm.Alarm; | |||
import com.iformall.service.PushLimitService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiOperation; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
@RestController | |||
@RequestMapping("hknetsdk") | |||
public class HaiKangController extends BaseController { | |||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
@Autowired | |||
private Alarm alarm; | |||
@ApiOperation("监听列表") | |||
@GetMapping("listenList") | |||
public ResultData listenList() { | |||
//PushLimit pushLimit = pushLimitService.getPushLimit(getTenantInfo()); | |||
return new ResultData(); | |||
} | |||
@ApiOperation("开启监听") | |||
@GetMapping("startListen") | |||
public ResultData startListen() { | |||
alarm.listen(); | |||
return new ResultData(); | |||
} | |||
@ApiOperation("关闭监听") | |||
@PostMapping("stopListen") | |||
public ResultData stopListen(@RequestBody PushLimit pushLimit) { | |||
alarm.stopListen(); | |||
return new ResultData(); | |||
} | |||
} |
@@ -36,7 +36,7 @@ | |||
<configuration> | |||
<executable>true</executable> | |||
<layout>ZIP</layout> | |||
<!-- <excludeGroupIds> | |||
<excludeGroupIds> | |||
antlr, | |||
cn.afterturn, | |||
ch.qos.logback, | |||
@@ -156,7 +156,7 @@ | |||
tk.mybatis, | |||
xmlpull, | |||
xpp3 | |||
</excludeGroupIds> --> | |||
</excludeGroupIds> | |||
</configuration> | |||
</plugin> | |||
</plugins> | |||
@@ -1,35 +1,215 @@ | |||
package com.iformall.controller; | |||
import com.iformall.annotation.AuthIgnore; | |||
import com.iformall.common.ResultData; | |||
import com.iformall.domain.po.WxMallApply; | |||
import com.iformall.domain.po.WxMsgValidationcode; | |||
import com.iformall.haikang.alarm.Alarm; | |||
import com.iformall.service.WxMallApplyService; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import org.apache.commons.fileupload.FileItem; | |||
import org.apache.commons.fileupload.FileItemFactory; | |||
import org.apache.commons.fileupload.disk.DiskFileItemFactory; | |||
import org.apache.commons.fileupload.servlet.ServletFileUpload; | |||
import org.apache.http.Header; | |||
import org.apache.http.HttpEntity; | |||
import org.apache.http.auth.AuthScope; | |||
import org.apache.http.auth.UsernamePasswordCredentials; | |||
import org.apache.http.client.CredentialsProvider; | |||
import org.apache.http.client.HttpClient; | |||
import org.apache.http.client.methods.CloseableHttpResponse; | |||
import org.apache.http.client.methods.HttpGet; | |||
import org.apache.http.client.methods.HttpPost; | |||
import org.apache.http.entity.StringEntity; | |||
import org.apache.http.impl.client.BasicCredentialsProvider; | |||
import org.apache.http.impl.client.CloseableHttpClient; | |||
import org.apache.http.impl.client.HttpClients; | |||
import org.apache.http.message.BasicHeader; | |||
import org.apache.http.util.EntityUtils; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
@RestController | |||
@RequestMapping("/api/hknetsdk") | |||
public class HaiKangController extends BaseController { | |||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
import com.iformall.annotation.AuthIgnore; | |||
import com.iformall.haikang.HKHttpClientInstanceFactory; | |||
@Autowired | |||
private Alarm alerm; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.ServletOutputStream; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
@AuthIgnore | |||
@PostMapping("listen") | |||
public ResultData add(@RequestBody WxMallApply wxMallApply) { | |||
logger.debug("[" + getIpAddr() + "] WxMallApplyController::add"); | |||
//Assert.notNull(wxMallApply.getName(), "角色名不能为空"); | |||
//Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
return new ResultData(); | |||
import java.io.BufferedReader; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.InputStreamReader; | |||
import java.nio.charset.StandardCharsets; | |||
import java.util.List; | |||
import java.util.UUID; | |||
} | |||
/** | |||
* @author jiangxin | |||
* @create 2021-07-08-15:33 | |||
*/ | |||
@RestController | |||
@RequestMapping("/api/hk") | |||
public class HaiKangController { | |||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
@Autowired | |||
HKHttpClientInstanceFactory httpFactory; | |||
/** | |||
* 监听接口事件解析,设备监听页面设置URL为“/notify” | |||
* @param request | |||
* @param response | |||
* @throws ServletException | |||
* @throws IOException | |||
*/ | |||
@AuthIgnore | |||
@PostMapping("/notify") | |||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |||
//解析multipart/form-data类型报文 | |||
FileItemFactory factory = new DiskFileItemFactory(); | |||
ServletFileUpload sf = new ServletFileUpload(factory); | |||
try { | |||
if (!ServletFileUpload.isMultipartContent(request)) { | |||
throw new Exception("no multipartcontent"); | |||
} | |||
List<FileItem> formData = sf.parseRequest(request); | |||
for (FileItem fi : formData) { | |||
if (fi.isFormField()) { | |||
//解析报文中json | |||
System.out.println("field_name:" + fi.getFieldName()); | |||
//打印json格式上传的事件报文 | |||
System.out.println(fi.getString("UTF-8")); | |||
//通过表单name属性进行解析报文 | |||
switch (fi.getFieldName()) { | |||
case "event_log"://门禁、身份证事件解析 | |||
System.out.println("receive Acs event"); | |||
break; | |||
default: | |||
System.out.println("unknow data"); | |||
} | |||
} else { | |||
//保存报文中的图片数据 | |||
String image_name = fi.getName(); | |||
logger.info("image_name:" + image_name); | |||
if (image_name != "") { | |||
//图片保存路径 | |||
String image_dir_path = "C:\\image\\"; | |||
File image_dir = new File(image_dir_path); | |||
if (!image_dir.exists()) { | |||
image_dir.mkdir(); | |||
} | |||
String file_name = UUID.randomUUID().toString(); | |||
String suffix = image_name.substring(fi.getName().lastIndexOf(".")); | |||
System.out.println("图片报文路径:" + image_dir_path); | |||
System.out.println("图片名称:" + file_name); | |||
System.out.println("图片格式:" + suffix); | |||
fi.write(new File(image_dir_path, file_name + suffix)); | |||
} else { | |||
throw new Exception("no file receive"); | |||
} | |||
} | |||
} | |||
//正常接收平台响应回复 | |||
response.getWriter().write("success"); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
response.getWriter().write("false"); | |||
} | |||
} | |||
/** | |||
* 1. 获取设备系统能力集GET /ISAPI/System/capabilities; | |||
2. 判断是否支持事件订阅isSupportSubscribeEvent存在且为true; | |||
3. 获取布防订阅能力GET /ISAPI/Event/notification/subscribeEventCap; | |||
4. 建立布防订阅连接POST /ISAPI/Event/notification/subscribeEvent客户端需要设置HTTP Headers | |||
中Connection: keep-alive; | |||
5. (可选)修改已有布防订阅连接的订阅参数,如果想要在当前订阅配置基础上修改订阅参数,需要先获取布防订 | |||
阅管理参数GET /ISAPI/Event/notification/subscribeEvent/<subscribeEventID>,在获取到的订阅配置基础上 | |||
修改完成后再调用设置布防订阅管理参数PUT | |||
/ISAPI/Event/notification/subscribeEvent/<subscribeEventID>; | |||
6. 接收设备发送的事件,通过boundary分割解析事件消息,解析说明详见下面的 “事事件件消消息息解解析析”; | |||
7. (可选)取消布防订阅连接PUT /ISAPI/Event/notification/unSubscribeEvent?ID=<subscribeEventID>,当使 | |||
用HTTP方式直接和设备通信时,不需要调用此接口,直接断开布防连接即可。通过萤石、OTAP等方式透传ISAPI | |||
事件订阅时,关闭事件订阅时需要调用此接口通知设备释放资源; | |||
8. 设备不支持事件订阅; | |||
* @param args | |||
*/ | |||
@AuthIgnore | |||
@GetMapping("/regeister") | |||
public void regeister(String ip,String name,String password) { | |||
CloseableHttpClient httpClient = httpFactory.getIpHttpClient(ip, name, password); | |||
String xmlcontent = "<SubscribeEvent xmlns=\"http://www.isapi.org/ver20/XMLSchema\" version=\"2.0\">\n" | |||
+ "<heartbeat>15</heartbeat>\n" | |||
+ "<eventMode>list</eventMode>\n" | |||
+ " <EventList>\n" | |||
+ " <Event>\n" | |||
+ " <type>AccessControllerEvent</type>\n" | |||
+ " <minorAlarm>0x404,0x405,0x406,0x407,0x40a,0x40b,0x40c,0x40d,0x40e,0x40f,0x410,0x408,0x409</minorAlarm>\n" | |||
+ " <minorException>0x26,0x27,0x400,0x407,0x408,0x409,0x40a,0x40f,0x410,0x423,0x424,0x428,0x429,0x41d,0x41e,0x426,0x427,0x451,0x452</minorException>\n" | |||
+ " <minorOperation>0x50,0x5a,0x5d,0x5e,0x70,0x71,0x76,0x77,0x79,0x7a,0x7b,0x7e,0x86,0x87,0xf0,0xf1,0x137,0x138,0x400,0x401,0x402,0x403,0x404,0x405,0x406,0x407,0x40a,0x40b,0x40c,0x40e,0x419,0x41a,0x421,0x422,0x42f,0x430,0x431,0x432,0x433,0x2601,0x41f,0x420</minorOperation>\n" | |||
+ " <minorEvent>0x1,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x31,0x33,0x4b,0x4c,0x50,0x68,0x72,0x73,0x74,0x75,0x82,0x84,0x8e,0x97,0x98,0x9b,0xa4,0xa8,0xb5,0xc1,0xbe,0xbf,0x9f,0xa0,0x2,0x3,0x4,0x5,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x99,0x9a,0x1d,0x1e,0xa2,0xa9,0x77,0xab,0x70,0x71,0x69</minorEvent>\n" | |||
+ " <pictureURLType>binary</pictureURLType>\n" | |||
+ " </Event>\n" | |||
+ " <Event>\n" | |||
+ " <type>IDCardInfoEvent</type>\n" | |||
+ " <minorEvent>0x69,0x70,0x71</minorEvent>\n" | |||
+ " <pictureURLType>binary</pictureURLType>\n" | |||
+ " </Event>\n" | |||
+ " </EventList>\n" | |||
+ "</SubscribeEvent>"; | |||
executePostRequest(httpClient,ip,"/ISAPI/Event/notification/subscribeEvent",xmlcontent); | |||
} | |||
private void executePostRequest(CloseableHttpClient httpClient,String ip,String api,String body) { | |||
HttpPost httpPost = new HttpPost("http://"+ip+":80"+api); | |||
Header[] headers = {new BasicHeader("Connection","keep-alive"),new BasicHeader("asa","ass")}; | |||
httpPost.setHeaders(headers); | |||
StringEntity entity = new StringEntity(body, StandardCharsets.UTF_8); | |||
httpPost.setEntity(entity); | |||
try { | |||
// 执行请求 | |||
CloseableHttpResponse response = httpClient.execute(httpPost); | |||
//return EntityUtils.toString(response.getEntity()); | |||
try { | |||
int statusCode = response.getStatusLine().getStatusCode(); | |||
if (statusCode == 200) { | |||
HttpEntity rentity = response.getEntity(); | |||
if (null != rentity) { | |||
// 打印服务器的响应内容 | |||
InputStream instream = rentity.getContent(); | |||
InputStreamReader inputStreamReader = new InputStreamReader(instream); | |||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader); | |||
String result; | |||
while ((result = bufferedReader.readLine()) != null) { | |||
System.out.println("*******"+result); | |||
} | |||
System.out.println("*******&&&&&&&******close***************"); | |||
bufferedReader.close(); | |||
} | |||
} | |||
} catch(Exception e) { | |||
e.printStackTrace(); | |||
} | |||
// finally { | |||
// response.close(); | |||
// } | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
// finally { | |||
// try { | |||
// httpClient.close(); | |||
// } catch (IOException e) { | |||
// e.printStackTrace(); | |||
// } | |||
// } | |||
} | |||
} |
@@ -52,31 +52,6 @@ | |||
<artifactId>jsoup</artifactId> | |||
<version>1.10.2</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.iformall.haikang</groupId> | |||
<artifactId>jna</artifactId> | |||
<version>1.0.0</version> | |||
<!-- <scope>system</scope> | |||
<systemPath>${project.basedir}/lib/jna-1.0.0.jar</systemPath> --> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.iformall.haikang</groupId> | |||
<artifactId>jna_1</artifactId> | |||
<version>4.5.2</version> | |||
<!-- <scope>system</scope> | |||
<systemPath>${project.basedir}/lib/jna-4.5.2.jar</systemPath>--> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.iformall.haikang</groupId> | |||
<artifactId>examples</artifactId> | |||
<version>1.0.0</version> | |||
<!--<scope>system</scope> | |||
<systemPath>${project.basedir}/lib/examples-1.0.0.jar</systemPath>--> | |||
</dependency> | |||
</dependencies> | |||
</project> |
@@ -0,0 +1,50 @@ | |||
package com.iformall.haikang; | |||
import java.util.Map; | |||
import java.util.concurrent.ConcurrentHashMap; | |||
import org.apache.http.auth.AuthScope; | |||
import org.apache.http.auth.UsernamePasswordCredentials; | |||
import org.apache.http.client.CredentialsProvider; | |||
import org.apache.http.impl.client.BasicCredentialsProvider; | |||
import org.apache.http.impl.client.CloseableHttpClient; | |||
import org.apache.http.impl.client.HttpClients; | |||
import org.springframework.stereotype.Component; | |||
@Component | |||
public class HKHttpClientInstanceFactory { | |||
private Map<String,CloseableHttpClient> ipHttpClientMap; | |||
public CloseableHttpClient getIpHttpClient(String ip,String name,String password) { | |||
synchronized (ip) { | |||
if (null == ipHttpClientMap) { | |||
ipHttpClientMap = new ConcurrentHashMap<String,CloseableHttpClient>(); | |||
CloseableHttpClient httpClient = generateHttpClient(ip, name, password); | |||
ipHttpClientMap.put(ip, httpClient); | |||
return httpClient; | |||
}else { | |||
CloseableHttpClient httpClient = ipHttpClientMap.get(ip); | |||
if (null == httpClient) { | |||
httpClient = generateHttpClient(ip, name, password); | |||
ipHttpClientMap.put(ip, httpClient); | |||
} | |||
return httpClient; | |||
} | |||
} | |||
} | |||
private CloseableHttpClient generateHttpClient(String ip,String name,String password) { | |||
CredentialsProvider credsProvider = new BasicCredentialsProvider(); | |||
credsProvider.setCredentials( | |||
new AuthScope(ip, AuthScope.ANY_PORT), | |||
new UsernamePasswordCredentials(name, password)); | |||
// 创建一个使用认证凭据的CloseableHttpClient | |||
CloseableHttpClient httpClient = HttpClients.custom() | |||
.setDefaultCredentialsProvider(credsProvider) | |||
.build(); | |||
return httpClient; | |||
} | |||
} |
@@ -1,485 +0,0 @@ | |||
package com.iformall.haikang.alarm; | |||
import com.iformall.file.haikang.HaiKangNetSdkConfig; | |||
import com.iformall.haikang.alarm.common.HCNetSDK; | |||
import com.iformall.haikang.alarm.common.osSelect; | |||
import com.sun.jna.Native; | |||
import com.sun.jna.Pointer; | |||
import java.util.Scanner; | |||
import javax.annotation.PreDestroy; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@Service | |||
public class Alarm { | |||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
@Autowired | |||
HaiKangNetSdkConfig hkConfig; | |||
private HCNetSDK hCNetSDK = null; | |||
private int lUserID = -1;//用户句柄 实现对设备登录 | |||
private int lAlarmHandle =-1;//报警布防句柄 | |||
private int lListenHandle = -1;//监听句柄 | |||
@Autowired | |||
FMSGCallBack_V31 fMSFCallBack_V31; //报警布防回调函数 | |||
private FMSGCallBack fMSFCallBack=null; //报警监听回调函数 | |||
/** | |||
* 动态库加载 | |||
* | |||
* @return | |||
*/ | |||
private boolean createSDKInstance() { | |||
if (hCNetSDK == null) { | |||
synchronized (HCNetSDK.class) { | |||
String strDllPath = hkConfig.getLibdir(); | |||
try { | |||
if (osSelect.isWindows()) { | |||
//win系统加载库路径 | |||
//strDllPath = System.getProperty("user.dir") + "\\lib\\HCNetSDK.dll"; | |||
strDllPath = strDllPath + "\\lib\\HCNetSDK.dll"; | |||
}else if (osSelect.isLinux()) { | |||
//Linux系统加载库路径 | |||
//strDllPath = System.getProperty("user.dir") + "/lib/libhcnetsdk.so"; | |||
strDllPath = strDllPath + "/lib/libhcnetsdk.so"; | |||
} | |||
hCNetSDK = (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class); | |||
} catch (Exception ex) { | |||
logger.error("createSDKInstance loadLibrary: " + strDllPath + " Error: " + ex.getMessage(),ex); | |||
return false; | |||
} | |||
} | |||
} | |||
return true; | |||
} | |||
private void initSdk() { | |||
if (hCNetSDK == null) { | |||
if (!createSDKInstance()) { | |||
logger.error("Load SDK fail"); | |||
return; | |||
} | |||
//linux系统建议调用以下接口加载组件库 | |||
if (osSelect.isLinux()) { | |||
HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256); | |||
HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256); | |||
//这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限 | |||
String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1"; | |||
String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1"; | |||
System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length()); | |||
ptrByteArray1.write(); | |||
hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_LIBEAY_PATH, ptrByteArray1.getPointer()); | |||
System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length()); | |||
ptrByteArray2.write(); | |||
hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_SSLEAY_PATH, ptrByteArray2.getPointer()); | |||
String strPathCom = System.getProperty("user.dir") + "/lib/"; | |||
HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH(); | |||
System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length()); | |||
struComPath.write(); | |||
hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_SDK_PATH, struComPath.getPointer()); | |||
} | |||
/**初始化*/ | |||
hCNetSDK.NET_DVR_Init(); | |||
/**加载日志*/ | |||
hCNetSDK.NET_DVR_SetLogToFile(3, "./sdklog1", false); | |||
//设置报警回调函数 | |||
//if (fMSFCallBack_V31 == null) { | |||
// fMSFCallBack_V31 = new FMSGCallBack_V31(); | |||
Pointer pUser = null; | |||
if (!hCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(fMSFCallBack_V31, pUser)) { | |||
System.out.println("设置回调函数失败!"); | |||
return; | |||
} else { | |||
System.out.println("设置回调函数成功!"); | |||
} | |||
//} | |||
/** 设备上传的报警信息是COMM_VCA_ALARM(0x4993)类型, | |||
在SDK初始化之后增加调用NET_DVR_SetSDKLocalCfg(enumType为NET_DVR_LOCAL_CFG_TYPE_GENERAL)设置通用参数NET_DVR_LOCAL_GENERAL_CFG的byAlarmJsonPictureSeparate为1, | |||
将Json数据和图片数据分离上传,这样设置之后,报警布防回调函数里面接收到的报警信息类型为COMM_ISAPI_ALARM(0x6009), | |||
报警信息结构体为NET_DVR_ALARM_ISAPI_INFO(与设备无关,SDK封装的数据结构),更便于解析。*/ | |||
HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG struNET_DVR_LOCAL_GENERAL_CFG = new HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG(); | |||
struNET_DVR_LOCAL_GENERAL_CFG.byAlarmJsonPictureSeparate = 1; //设置JSON透传报警数据和图片分离 | |||
struNET_DVR_LOCAL_GENERAL_CFG.write(); | |||
Pointer pStrNET_DVR_LOCAL_GENERAL_CFG = struNET_DVR_LOCAL_GENERAL_CFG.getPointer(); | |||
hCNetSDK.NET_DVR_SetSDKLocalCfg(17, pStrNET_DVR_LOCAL_GENERAL_CFG); | |||
} | |||
} | |||
@PreDestroy | |||
public void onDestory() { | |||
//释放SDK | |||
if (hCNetSDK != null) { | |||
stopListen(); | |||
//设备注销 | |||
logoutDev(lUserID); | |||
//SDK | |||
hCNetSDK.NET_DVR_Cleanup(); | |||
} | |||
} | |||
/** | |||
* 开启监听 | |||
* @return | |||
*/ | |||
public void listen() { | |||
if (hCNetSDK == null) { | |||
initSdk(); | |||
} | |||
lUserID=loginDevice( hkConfig.getDeviceIp(), (short) 8000, hkConfig.getLoginUser(), hkConfig.getPassword()); //登录设备 | |||
lListenHandle = startListen(hkConfig.getListenIp(),(short) hkConfig.getListenPort()); | |||
} | |||
/** | |||
* 停止监听 | |||
* @param Handle 监听句柄 | |||
*/ | |||
public void stopListen() | |||
{ | |||
int Handle = lListenHandle; | |||
if (Handle <= -1) | |||
{ | |||
logger.info("监听未开启"); | |||
return; | |||
} | |||
if (!hCNetSDK.NET_DVR_StopListen_V30(Handle)) { | |||
logger.error("停止监听失败,err: "+hCNetSDK.NET_DVR_GetLastError()); | |||
return; | |||
} | |||
logger.info("停止监听成功"); | |||
return; | |||
} | |||
// /** | |||
// * @param args | |||
// */ | |||
// public static void main(String[] args) throws InterruptedException { | |||
// | |||
// if (hCNetSDK == null) { | |||
// if (!createSDKInstance()) { | |||
// System.out.println("Load SDK fail"); | |||
// return; | |||
// } | |||
// } | |||
// //linux系统建议调用以下接口加载组件库 | |||
// if (osSelect.isLinux()) { | |||
// HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256); | |||
// HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256); | |||
// //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限 | |||
// String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1"; | |||
// String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1"; | |||
// System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length()); | |||
// ptrByteArray1.write(); | |||
// hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_LIBEAY_PATH, ptrByteArray1.getPointer()); | |||
// System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length()); | |||
// ptrByteArray2.write(); | |||
// hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_SSLEAY_PATH, ptrByteArray2.getPointer()); | |||
// String strPathCom = System.getProperty("user.dir") + "/lib/"; | |||
// HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH(); | |||
// System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length()); | |||
// struComPath.write(); | |||
// hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_SDK_PATH, struComPath.getPointer()); | |||
// } | |||
// | |||
// /**初始化*/ | |||
// hCNetSDK.NET_DVR_Init(); | |||
// /**加载日志*/ | |||
// hCNetSDK.NET_DVR_SetLogToFile(3, "./sdklog1", false); | |||
// //设置报警回调函数 | |||
// if (fMSFCallBack_V31 == null) { | |||
// fMSFCallBack_V31 = new FMSGCallBack_V31(); | |||
// Pointer pUser = null; | |||
// if (!hCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(fMSFCallBack_V31, pUser)) { | |||
// System.out.println("设置回调函数失败!"); | |||
// return; | |||
// } else { | |||
// System.out.println("设置回调函数成功!"); | |||
// } | |||
// } | |||
// /** 设备上传的报警信息是COMM_VCA_ALARM(0x4993)类型, | |||
// 在SDK初始化之后增加调用NET_DVR_SetSDKLocalCfg(enumType为NET_DVR_LOCAL_CFG_TYPE_GENERAL)设置通用参数NET_DVR_LOCAL_GENERAL_CFG的byAlarmJsonPictureSeparate为1, | |||
// 将Json数据和图片数据分离上传,这样设置之后,报警布防回调函数里面接收到的报警信息类型为COMM_ISAPI_ALARM(0x6009), | |||
// 报警信息结构体为NET_DVR_ALARM_ISAPI_INFO(与设备无关,SDK封装的数据结构),更便于解析。*/ | |||
// | |||
// HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG struNET_DVR_LOCAL_GENERAL_CFG = new HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG(); | |||
// struNET_DVR_LOCAL_GENERAL_CFG.byAlarmJsonPictureSeparate = 1; //设置JSON透传报警数据和图片分离 | |||
// struNET_DVR_LOCAL_GENERAL_CFG.write(); | |||
// Pointer pStrNET_DVR_LOCAL_GENERAL_CFG = struNET_DVR_LOCAL_GENERAL_CFG.getPointer(); | |||
// hCNetSDK.NET_DVR_SetSDKLocalCfg(17, pStrNET_DVR_LOCAL_GENERAL_CFG); | |||
// | |||
// lUserID=Alarm.loginDevice( "192.168.2.200", (short) 8000, "admin", "wushikeji001"); //登录设备 | |||
// | |||
// for (boolean exit = false; !exit; ) { | |||
// System.out.println("请输入您想要执行的demo实例! (退出请输入yes)"); | |||
// Scanner input = new Scanner(System.in); | |||
// String str = input.next(); | |||
// // 转换为标准输入 | |||
// str = str.toLowerCase(); | |||
// if (str.equals("yes")) { | |||
// // 退出程序 | |||
// exit = true; | |||
// break; | |||
// } | |||
// switch (str) { | |||
// case "1": | |||
// { | |||
// System.out.println("\n[Module]报警布防示例代码"); | |||
// lAlarmHandle=Alarm.setAlarmChan(lUserID);//报警布防,和报警监听二选一即可 | |||
// break; | |||
// } | |||
// case "2": | |||
// { | |||
// System.out.println("\n[Module]报警撤防示例代码"); | |||
// Alarm.closedAlarmChan(lAlarmHandle); | |||
// break; | |||
// } | |||
// case "3": | |||
// { | |||
// //报警监听不需要登录设备,Alarm.loginDevice登录接口可以注释 | |||
// System.out.println("\n[Module]开启报警监听示例代码"); | |||
// lListenHandle = Alarm.startListen("192.168.2.103",(short) 7201); //传入监听PC本机的IP地址和端口 | |||
// break; | |||
// } | |||
// case "4": | |||
// { | |||
// System.out.println("\n[Module]停止监听示例代码"); | |||
// Alarm.stopListen(lListenHandle); | |||
// break; | |||
// } | |||
// default: | |||
// { | |||
// System.out.println("\n未知的指令操作!请重新输入!\n"); | |||
// } | |||
// } | |||
// } | |||
// //设备注销 | |||
// Alarm.logoutDev(lUserID); | |||
// //释放SDK | |||
// hCNetSDK.NET_DVR_Cleanup(); | |||
// return; | |||
// } | |||
/** | |||
* 登录设备,支持 V40 和 V30 版本,功能一致。 | |||
* | |||
* @param ip 设备IP地址 | |||
* @param port SDK端口,默认为设备的8000端口 | |||
* @param user 设备用户名 | |||
* @param psw 设备密码 | |||
* @return 登录成功返回用户ID,失败返回-1 | |||
*/ | |||
public int loginDevice(String ip, short port, String user, String psw) { | |||
// 创建设备登录信息和设备信息对象 | |||
HCNetSDK.NET_DVR_USER_LOGIN_INFO loginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO(); | |||
HCNetSDK.NET_DVR_DEVICEINFO_V40 deviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40(); | |||
// 设置设备IP地址 | |||
byte[] deviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN]; | |||
byte[] ipBytes = ip.getBytes(); | |||
System.arraycopy(ipBytes, 0, deviceAddress, 0, Math.min(ipBytes.length, deviceAddress.length)); | |||
loginInfo.sDeviceAddress = deviceAddress; | |||
// 设置用户名和密码 | |||
byte[] userName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN]; | |||
byte[] password = psw.getBytes(); | |||
System.arraycopy(user.getBytes(), 0, userName, 0, Math.min(user.length(), userName.length)); | |||
System.arraycopy(password, 0, loginInfo.sPassword, 0, Math.min(password.length, loginInfo.sPassword.length)); | |||
loginInfo.sUserName = userName; | |||
// 设置端口和登录模式 | |||
loginInfo.wPort = port; | |||
loginInfo.bUseAsynLogin = false; // 同步登录 | |||
loginInfo.byLoginMode = 0; // 使用SDK私有协议 | |||
// 执行登录操作 | |||
int userID = hCNetSDK.NET_DVR_Login_V40(loginInfo, deviceInfo); | |||
if (userID == -1) { | |||
System.err.println("登录失败,错误码为: " + hCNetSDK.NET_DVR_GetLastError()); | |||
} else { | |||
System.out.println(ip + " 设备登录成功!"); | |||
// 处理通道号逻辑 | |||
int startDChan = deviceInfo.struDeviceV30.byStartDChan; | |||
System.out.println("预览起始通道号: " + startDChan); | |||
} | |||
return userID; // 返回登录结果 | |||
} | |||
/** | |||
* 设备登录V30 | |||
* @param ip 设备IP | |||
* @param port SDK端口,默认设备的8000端口 | |||
* @param user 设备用户名 | |||
* @param psw 设备密码 | |||
*/ | |||
public void loginDeviceV30(String ip, short port, String user, String psw) { | |||
HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30(); | |||
lUserID = hCNetSDK.NET_DVR_Login_V30(ip, port, user, psw, m_strDeviceInfo); | |||
System.out.println("UsID:" + lUserID); | |||
if ((lUserID == -1) || (lUserID == 0xFFFFFFFF)) { | |||
System.out.println("登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError()); | |||
return; | |||
} else { | |||
System.out.println(ip + ":设备登录成功!"); | |||
return; | |||
} | |||
} | |||
/** | |||
* 报警布防 | |||
* @param userID 设备登录句柄ID | |||
* @return | |||
*/ | |||
public int setAlarmChan(int userID ) { | |||
if (userID == -1) { | |||
System.out.println("请先注册"); | |||
return -1; | |||
} | |||
if (lAlarmHandle < 0)//尚未布防,需要布防 | |||
{ | |||
//报警布防参数设置 | |||
HCNetSDK.NET_DVR_SETUPALARM_PARAM alarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM(); | |||
alarmInfo.dwSize = alarmInfo.size(); | |||
alarmInfo.byLevel = 0; //布防等级 | |||
alarmInfo.byAlarmInfoType = 1; // 智能交通报警信息上传类型:0- 老报警信息(NET_DVR_PLATE_RESULT),1- 新报警信息(NET_ITS_PLATE_RESULT) | |||
alarmInfo.byDeployType = 0; //布防类型:0-客户端布防,1-实时布防,客户端布防仅支持一路 | |||
alarmInfo.write(); | |||
lAlarmHandle= hCNetSDK.NET_DVR_SetupAlarmChan_V41(userID, alarmInfo); | |||
if (lAlarmHandle == -1) { | |||
System.err.println("布防失败,错误码为" + hCNetSDK.NET_DVR_GetLastError()); | |||
return -1 ; | |||
} else { | |||
System.out.println("布防成功"); | |||
return lAlarmHandle; | |||
} | |||
} else { | |||
System.out.println("设备已经布防,请先撤防!"); | |||
return lAlarmHandle ; | |||
} | |||
} | |||
/** | |||
* 设备撤防 | |||
* @param AlarmHandle 布防句柄 | |||
*/ | |||
public void closedAlarmChan(int AlarmHandle) | |||
{ | |||
if (AlarmHandle <= -1) | |||
{ | |||
System.out.println("设备未布防,请先布防!"); | |||
return ; | |||
} | |||
if (!hCNetSDK.NET_DVR_CloseAlarmChan(AlarmHandle)) { | |||
System.err.println("撤防失败,err "+hCNetSDK.NET_DVR_GetLastError()); | |||
return; | |||
} | |||
System.out.println("撤防成功"); | |||
return; | |||
} | |||
/** | |||
* 报警布防V50接口 | |||
* | |||
* @param | |||
*/ | |||
public int setAlarmChanV50(int userID) { | |||
if (userID == -1) { | |||
System.out.println("请先注册"); | |||
return -1; | |||
} | |||
if (lAlarmHandle < 0)//尚未布防,需要布防 | |||
{ | |||
//报警布防参数设置 | |||
HCNetSDK.NET_DVR_SETUPALARM_PARAM_V50 m_strAlarmInfoV50 = new HCNetSDK.NET_DVR_SETUPALARM_PARAM_V50(); | |||
m_strAlarmInfoV50.dwSize = m_strAlarmInfoV50.size(); | |||
m_strAlarmInfoV50.byLevel = 0; //布防等级 | |||
m_strAlarmInfoV50.byAlarmInfoType = 1; // 智能交通报警信息上传类型:0- 老报警信息(NET_DVR_PLATE_RESULT),1- 新报警信息(NET_ITS_PLATE_RESULT) | |||
m_strAlarmInfoV50.byRetAlarmTypeV40 =1; //0- 移动侦测、视频丢失、遮挡、IO信号量等报警信息以普通方式上传(报警类型:COMM_ALARM_V30,报警信息结构体:NET_DVR_ALARMINFO_V30), | |||
// 1- 报警信息以数据可变长方式上传(报警类型:COMM_ALARM_V40,报警信息结构体:NET_DVR_ALARMINFO_V40,设备若不支持则仍以普通方式上传) | |||
m_strAlarmInfoV50.byDeployType = 0; //布防类型:0-客户端布防,1-实时布防 | |||
m_strAlarmInfoV50.write(); | |||
lAlarmHandle= hCNetSDK.NET_DVR_SetupAlarmChan_V50(userID, m_strAlarmInfoV50,Pointer.NULL,0); | |||
if (lAlarmHandle == -1) { | |||
System.err.println("布防失败,错误码为" + hCNetSDK.NET_DVR_GetLastError()); | |||
return -1; | |||
} else { | |||
System.out.println("布防成功"); | |||
return lAlarmHandle; | |||
} | |||
} else { | |||
System.out.println("设备已经布防,请先撤防!"); | |||
return lAlarmHandle; | |||
} | |||
} | |||
/** | |||
* 开启监听 | |||
* | |||
* @param ip 监听IP | |||
* @param port 监听端口 | |||
*/ | |||
public int startListen(String ip, short port) { | |||
if (lListenHandle <= 0){ | |||
if (fMSFCallBack == null) { | |||
fMSFCallBack = new FMSGCallBack(); | |||
} | |||
lListenHandle = hCNetSDK.NET_DVR_StartListen_V30(ip, port,fMSFCallBack, null); | |||
if (lListenHandle == -1) { | |||
System.out.println("监听失败" + hCNetSDK.NET_DVR_GetLastError()); | |||
return -1; | |||
} else { | |||
System.out.println("监听成功"); | |||
return lListenHandle; | |||
} | |||
}else { | |||
System.out.println("监听已经开启,请先停止监听!"); | |||
return lListenHandle; | |||
} | |||
} | |||
/** | |||
* 设备注销 | |||
* @param | |||
*/ | |||
public void logoutDev(int userID) { | |||
if (userID>-1) | |||
{ | |||
if (hCNetSDK.NET_DVR_Logout(userID)) { | |||
System.out.println("注销成功"); | |||
return; | |||
} | |||
}else | |||
{ | |||
System.out.println("设备未注册,请先注册"); | |||
return; | |||
} | |||
return; | |||
} | |||
} |
@@ -1,17 +0,0 @@ | |||
package com.iformall.haikang.alarm; | |||
import com.iformall.haikang.alarm.common.HCNetSDK; | |||
import com.sun.jna.Pointer; | |||
/** | |||
* @author jiangxin | |||
* @create 2022-08-15-17:26 | |||
*/ | |||
public class FMSGCallBack implements HCNetSDK.FMSGCallBack { | |||
//报警信息回调函数 | |||
public void invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) { | |||
AlarmDataParse.alarmDataHandle(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser); | |||
return; | |||
} | |||
} |
@@ -1,32 +0,0 @@ | |||
package com.iformall.haikang.alarm; | |||
import com.iformall.haikang.alarm.common.HCNetSDK; | |||
import com.sun.jna.Pointer; | |||
import java.io.FileNotFoundException; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.UnsupportedEncodingException; | |||
import java.nio.ByteBuffer; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Date; | |||
import org.springframework.stereotype.Component; | |||
@Component | |||
public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 { | |||
//报警信息回调函数 | |||
public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) { | |||
AlarmDataParse.alarmDataHandle(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser); | |||
//AlarmDataParse.alarmDataHandle(HCNetSDK.COMM_ALARM_PDC, pAlarmer, pAlarmInfo, dwBufLen, pUser); | |||
return true; | |||
} | |||
} | |||
@@ -1,29 +0,0 @@ | |||
package com.iformall.haikang.alarm.common; | |||
/** | |||
* @author | |||
* @create 2022-03-22-11:13 | |||
*/ | |||
public class CommonUtil { | |||
//SDK时间解析 | |||
public static String parseTime(int time) | |||
{ | |||
int year=(time>>26)+2000; | |||
int month=(time>>22)&15; | |||
int day=(time>>17)&31; | |||
int hour=(time>>12)&31; | |||
int min=(time>>6)&63; | |||
int second=(time>>0)&63; | |||
String sTime=year+"-"+month+"-"+day+"-"+hour+":"+min+":"+second; | |||
// System.out.println(sTime); | |||
return sTime; | |||
} | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.iformall.haikang.alarm.common; | |||
/** | |||
* @author | |||
* @create 2022-01-19-16:40 | |||
*/ | |||
public class osSelect { | |||
public static boolean isLinux() { | |||
return System.getProperty("os.name").toLowerCase().contains("linux"); | |||
} | |||
public static boolean isWindows() { | |||
return System.getProperty("os.name").toLowerCase().contains("windows"); | |||
} | |||
} |
@@ -1,49 +0,0 @@ | |||
package com.iformall.haikang.face; | |||
/** | |||
* @Author: jiangxin14 | |||
* @Date: 2024-08-09 15:05 | |||
*/ | |||
public class FaceLibManage { | |||
/** | |||
* 获取所有人脸库信息 | |||
* @param userID | |||
*/ | |||
public static void getAllFaceLibInfo(int userID) | |||
{ | |||
String requestUrl = "GET /ISAPI/Intelligent/FDLib"; | |||
String strOutXML = ISAPI.sdk_isapi(userID, requestUrl, ""); | |||
System.out.println(strOutXML); | |||
return; | |||
} | |||
/** | |||
* 创建人脸库 | |||
* @param userID | |||
*/ | |||
public static void setOneFaceLib(int userID) | |||
{ | |||
/*创建一个人脸库,创建成功的返回结果里面包含FDID*/ | |||
String requestUrl = "POST /ISAPI/Intelligent/FDLib"; | |||
String strOutXML = ISAPI.sdk_isapi(userID, requestUrl, FacePicManage.fDCreate_XmlCreat("9", "sdkceshi")); | |||
System.out.println(strOutXML); | |||
return; | |||
} | |||
/**删除一个人脸库 | |||
/* DELETE /ISAPI/Intelligent/FDLib/<FDID>,FDID为人脸库ID | |||
* 通过getAllFaceLib里面代码可以查询设备当前所有人脸库信息可以获取人脸库ID | |||
*/ | |||
public static void deleteOneFaceLib(int userID,String FDID) | |||
{ | |||
String requestUrl = "DELETE /ISAPI/Intelligent/FDLib/" + FDID; | |||
String strOutXML = ISAPI.sdk_isapi(userID, requestUrl, ""); | |||
System.out.println(strOutXML); | |||
} | |||
} |
@@ -1,214 +0,0 @@ | |||
package com.iformall.haikang.face; | |||
import com.iformall.haikang.face.common.HCNetSDK; | |||
import com.iformall.haikang.face.common.osSelect; | |||
import com.sun.jna.Native; | |||
import org.dom4j.DocumentException; | |||
import java.io.IOException; | |||
import java.util.Scanner; | |||
public class FaceMain { | |||
static HCNetSDK hCNetSDK = null; | |||
static int lUserID = -1;//用户句柄 | |||
/** | |||
* 根据不同操作系统选择不同的库文件和库路径 | |||
* @return | |||
*/ | |||
private static boolean createSDKInstance() | |||
{ | |||
if(hCNetSDK == null) | |||
{ | |||
synchronized (HCNetSDK.class) | |||
{ | |||
String strDllPath = "C:\\project\\bjAirport\\bjairService\\lib\\kuwenjian"; | |||
try | |||
{ | |||
//System.setProperty("jna.debug_load", "true"); | |||
if(osSelect.isWindows()) | |||
//win系统加载库路径 | |||
strDllPath = System.getProperty("user.dir") + "\\lib\\HCNetSDK.dll"; | |||
else if(osSelect.isLinux()) | |||
//Linux系统加载库路径 | |||
strDllPath = System.getProperty("user.dir") + "/lib/libhcnetsdk.so"; | |||
hCNetSDK = (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class); | |||
}catch (Exception ex) { | |||
System.out.println("loadLibrary: " + strDllPath + " Error: " + ex.getMessage()); | |||
return false; | |||
} | |||
} | |||
} | |||
return true; | |||
} | |||
public static void main(String[] args) throws InterruptedException, IOException, DocumentException { | |||
if(hCNetSDK == null) | |||
{ | |||
if(!createSDKInstance()) | |||
{ | |||
System.out.println("Load SDK fail"); | |||
return; | |||
} | |||
} | |||
//linux系统建议调用以下接口加载组件库 | |||
if (osSelect.isLinux()) { | |||
HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256); | |||
HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256); | |||
//这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限 | |||
String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1"; | |||
String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1"; | |||
System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length()); | |||
ptrByteArray1.write(); | |||
hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_LIBEAY_PATH, ptrByteArray1.getPointer()); | |||
System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length()); | |||
ptrByteArray2.write(); | |||
hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_SSLEAY_PATH, ptrByteArray2.getPointer()); | |||
String strPathCom = System.getProperty("user.dir") + "/lib/"; | |||
HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH(); | |||
System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length()); | |||
struComPath.write(); | |||
hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_SDK_PATH, struComPath.getPointer()); | |||
} | |||
/*初始化*/ | |||
hCNetSDK.NET_DVR_Init(); | |||
/*加载日志*/ | |||
hCNetSDK.NET_DVR_SetLogToFile(3, "./sdklog", false); | |||
//设备登录 | |||
lUserID=loginDevice("192.168.2.200",(short) 8000,"admin","wushikeji001"); //登录设备 | |||
for (boolean exit = false; !exit; ) { | |||
System.out.println("请输入您想要执行的demo实例! (退出请输入yes)"); | |||
Scanner input = new Scanner(System.in); | |||
String str = input.next(); | |||
// 转换为标准输入 | |||
str = str.toLowerCase(); | |||
if (str.equals("yes")) { | |||
// 退出程序 | |||
exit = true; | |||
break; | |||
} | |||
switch (str) { | |||
case "1": | |||
{ | |||
System.out.println("\n[Module]获取所有人脸库示例代码"); | |||
FaceLibManage.getAllFaceLibInfo(lUserID); | |||
break; | |||
} | |||
case "2": | |||
{ | |||
System.out.println("\n[Module]创建人脸库示例代码"); | |||
FaceLibManage.setOneFaceLib(lUserID); | |||
break; | |||
} | |||
case "3": | |||
{ | |||
//FDID人脸库ID调用getAllFaceLibInfo获取 | |||
System.out.println("\n[Module]删除人脸库示例代码"); | |||
FaceLibManage.deleteOneFaceLib(lUserID,"EC30695E85D8445AA72EFA1E85D03E52"); | |||
break; | |||
} | |||
case "4": | |||
{ | |||
//上传人脸图片到指定人脸库 | |||
System.out.println("\n[Module]上传人脸图片至指定人脸库代码"); | |||
FacePicManage.uploadPic(lUserID,"0A1520C29E524490AE6100DB9E908099"); | |||
break; | |||
} | |||
case "5": | |||
{ | |||
//通过指定人脸库ID和人员姓名进行查询 | |||
System.out.println("\n[Module]查询指定人脸库中人脸信息代码"); | |||
FacePicManage.searchPicInfo(lUserID); | |||
break; | |||
} | |||
case "6": | |||
{ | |||
//人脸图片建模 | |||
System.out.println("\n[Module]上次本地人脸图进行建模代码"); | |||
FacePicManage.analysisImage(lUserID,".\\pic\\test.jpg"); | |||
break; | |||
} | |||
case "7": | |||
{ | |||
//特征值搜图 | |||
System.out.println("\n[Module]特征值搜图代码"); | |||
FacePicManage.modeDataSearch(lUserID,"0A1520C29E524490AE6100DB9E908099"); | |||
break; | |||
} | |||
case "8": | |||
{ | |||
//比对记录查询 | |||
System.out.println("\n[Module]比对记录查询代码"); | |||
FacePicManage.fcSearch(lUserID); | |||
break; | |||
} | |||
default: | |||
{ | |||
System.out.println("\n未知的指令操作!请重新输入!\n"); | |||
} | |||
} | |||
} | |||
/*注销登录,程序退出时调用;程序同时对接多台设备时,每一台设备分别调用一次接口,传入不同的登录句柄*/ | |||
if (lUserID>=0) | |||
{ | |||
hCNetSDK.NET_DVR_Logout(lUserID); | |||
} | |||
/*SDK反初始化,释放资源,程序退出时调用*/ | |||
hCNetSDK.NET_DVR_Cleanup(); | |||
} | |||
/** | |||
* 登录设备,支持 V40 和 V30 版本,功能一致。 | |||
* | |||
* @param ip 设备IP地址 | |||
* @param port SDK端口,默认为设备的8000端口 | |||
* @param user 设备用户名 | |||
* @param psw 设备密码 | |||
* @return 登录成功返回用户ID,失败返回-1 | |||
*/ | |||
public static int loginDevice(String ip, short port, String user, String psw) { | |||
// 创建设备登录信息和设备信息对象 | |||
HCNetSDK.NET_DVR_USER_LOGIN_INFO loginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO(); | |||
HCNetSDK.NET_DVR_DEVICEINFO_V40 deviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40(); | |||
// 设置设备IP地址 | |||
byte[] deviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN]; | |||
byte[] ipBytes = ip.getBytes(); | |||
System.arraycopy(ipBytes, 0, deviceAddress, 0, Math.min(ipBytes.length, deviceAddress.length)); | |||
loginInfo.sDeviceAddress = deviceAddress; | |||
// 设置用户名和密码 | |||
byte[] userName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN]; | |||
byte[] password = psw.getBytes(); | |||
System.arraycopy(user.getBytes(), 0, userName, 0, Math.min(user.length(), userName.length)); | |||
System.arraycopy(password, 0, loginInfo.sPassword, 0, Math.min(password.length, loginInfo.sPassword.length)); | |||
loginInfo.sUserName = userName; | |||
// 设置端口和登录模式 | |||
loginInfo.wPort = port; | |||
loginInfo.bUseAsynLogin = false; // 同步登录 | |||
loginInfo.byLoginMode = 0; // 使用SDK私有协议 | |||
// 执行登录操作 | |||
int userID = hCNetSDK.NET_DVR_Login_V40(loginInfo, deviceInfo); | |||
if (userID == -1) { | |||
System.err.println("登录失败,错误码为: " + hCNetSDK.NET_DVR_GetLastError()); | |||
} else { | |||
System.out.println(ip + " 设备登录成功!"); | |||
// 处理通道号逻辑 | |||
int startDChan = deviceInfo.struDeviceV30.byStartDChan; | |||
System.out.println("预览起始通道号: " + startDChan); | |||
} | |||
return userID; // 返回登录结果 | |||
} | |||
} |
@@ -1,371 +0,0 @@ | |||
package com.iformall.haikang.face; | |||
import com.iformall.haikang.face.common.CommonMethod; | |||
import com.iformall.haikang.face.common.HCNetSDK; | |||
import com.sun.jna.Pointer; | |||
import com.sun.jna.ptr.IntByReference; | |||
import org.dom4j.Document; | |||
import org.dom4j.DocumentException; | |||
import org.dom4j.DocumentHelper; | |||
import org.dom4j.Element; | |||
import java.io.*; | |||
import java.util.Iterator; | |||
import java.util.UUID; | |||
/** | |||
* 功能:人脸库图片上传 | |||
*/ | |||
public class FacePicManage { | |||
static String ModeData; //图片建模数据 | |||
//上传人脸图片 | |||
public static void uploadPic(int lUserID, String FDID) throws IOException { | |||
HCNetSDK.NET_DVR_FACELIB_COND struFaceLibCond = new HCNetSDK.NET_DVR_FACELIB_COND(); | |||
struFaceLibCond.read(); | |||
struFaceLibCond.dwSize = struFaceLibCond.size(); | |||
//人脸库ID | |||
for (int i = 0; i < HCNetSDK.NET_SDK_MAX_FDID_LEN; i++) | |||
{ | |||
struFaceLibCond.szFDID[i] = 0; | |||
} | |||
System.arraycopy(FDID.getBytes(), 0, struFaceLibCond.szFDID, 0, FDID.length()); | |||
struFaceLibCond.byConcurrent = 0; //设备并发处理:0- 不开启(设备自动会建模),1- 开始(设备不会自动进行建模) | |||
struFaceLibCond.byCover = 1; //是否覆盖式导入(人脸库存储满的情况下强制覆盖导入时间最久的图片数据):0- 否,1- 是 | |||
struFaceLibCond.byCustomFaceLibID = 0; | |||
struFaceLibCond.write(); | |||
Pointer pStruFaceLibCond = struFaceLibCond.getPointer(); | |||
int iUploadHandle = FaceMain.hCNetSDK.NET_DVR_UploadFile_V40(lUserID, HCNetSDK.IMPORT_DATA_TO_FACELIB, pStruFaceLibCond, | |||
struFaceLibCond.size(), null, Pointer.NULL, 0); | |||
if (iUploadHandle <= -1) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_UploadFile_V40失败,错误号" + iErr); | |||
return; | |||
} else { | |||
System.out.println("NET_DVR_UploadFile_V40成功"); | |||
} | |||
HCNetSDK.NET_DVR_SEND_PARAM_IN struSendParam = new HCNetSDK.NET_DVR_SEND_PARAM_IN(); | |||
struSendParam.read(); | |||
//本地jpg图片转成二进制byte数组 | |||
byte[] picbyte = CommonMethod.toByteArray("./pic/test.jpeg"); | |||
HCNetSDK.BYTE_ARRAY arraybyte = new HCNetSDK.BYTE_ARRAY(picbyte.length); | |||
arraybyte.read(); | |||
arraybyte.byValue = picbyte; | |||
arraybyte.write(); | |||
struSendParam.pSendData = arraybyte.getPointer(); | |||
struSendParam.dwSendDataLen = picbyte.length; | |||
struSendParam.byPicType = 1; //图片格式:1- jpg,2- bmp,3- png,4- SWF,5- GIF | |||
//图片的附加信息缓冲区 图片上添加的属性信息,性别、身份等 | |||
//1:xml文本导入方式 | |||
/* byte[] AppendData = toByteArray("E:\\2.Demo汇总\\JAVA_DEMO\\01-Windows_Demo\\超脑人脸比对\\Test\\pic\\test.xml"); | |||
HCNetSDK.BYTE_ARRAY byteArray = new HCNetSDK.BYTE_ARRAY(AppendData.length); | |||
byteArray.read(); | |||
byteArray.byValue = AppendData; | |||
byteArray.write();*/ | |||
//2:包含中文姓名的报文上传 | |||
/** | |||
<province>和<city>代表城市参数,城市代码参考:https://www.mca.gov.cn/mzsj/xzqh/2022/202201xzqh.html | |||
例如:浙江省杭州市 编码为: 330100 XML报文节点应为:<province>33</province><city>01</city> | |||
<certificateType> 证件号类型:[officerID#军官证,ID#身份证,passportID#护照,other#其他] | |||
*/ | |||
byte[] byFDLibName = "测试名称".getBytes("UTF-8"); | |||
String strInBuffer1 = new String("<FaceAppendData version=\"2.0\" xmlns=\"http://www.hikvision.com/ver20/XMLSchema\"><bornTime>2014-12-12T00:00:00Z</bornTime><name>"); | |||
String strInBuffer2 = new String("</name><sex>female</sex><province>11</province><city>01</city><certificateType>officerID</certificateType><certificateNumber>1123123123</certificateNumber><PersonInfoExtendList><PersonInfoExtend><id>1</id><enable>true</enable><name>test1</name><value>test2</value></PersonInfoExtend></PersonInfoExtendList></FaceAppendData>"); | |||
int iStringSize = byFDLibName.length + strInBuffer1.length() + strInBuffer2.length(); | |||
HCNetSDK.BYTE_ARRAY ptrByte = new HCNetSDK.BYTE_ARRAY(iStringSize); | |||
System.arraycopy(strInBuffer1.getBytes(), 0, ptrByte.byValue, 0, strInBuffer1.length()); | |||
System.arraycopy(byFDLibName, 0, ptrByte.byValue, strInBuffer1.length(), byFDLibName.length); | |||
System.arraycopy(strInBuffer2.getBytes(), 0, ptrByte.byValue, strInBuffer1.length() + byFDLibName.length, strInBuffer2.length()); | |||
ptrByte.write(); | |||
struSendParam.pSendAppendData = ptrByte.getPointer(); | |||
struSendParam.dwSendAppendDataLen = ptrByte.byValue.length; | |||
struSendParam.write(); | |||
int iSendData = FaceMain.hCNetSDK.NET_DVR_UploadSend(iUploadHandle, struSendParam, Pointer.NULL); | |||
if (iSendData <= -1) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_UploadSend失败,错误号" + iErr); | |||
return; | |||
} | |||
while (true) { | |||
IntByReference Pint = new IntByReference(0); | |||
int state = FaceMain.hCNetSDK.NET_DVR_GetUploadState(iUploadHandle, Pint.getPointer()); | |||
if (state == 1) { | |||
System.out.println("上传成功"); | |||
//获取图片ID | |||
HCNetSDK.NET_DVR_UPLOAD_FILE_RET struUploadRet = new HCNetSDK.NET_DVR_UPLOAD_FILE_RET(); | |||
boolean bUploadResult = FaceMain.hCNetSDK.NET_DVR_GetUploadResult(iUploadHandle, struUploadRet.getPointer(), struUploadRet.size()); | |||
if (!bUploadResult) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_GetUploadResult失败,错误号" + iErr); | |||
} else { | |||
struUploadRet.read(); | |||
System.out.println("图片ID:" + new String(struUploadRet.sUrl, "UTF-8").trim()); | |||
} | |||
break; | |||
} else if (state == 2) { | |||
System.out.println("进度:" + Pint.getValue()); | |||
continue; | |||
} | |||
System.err.println("返回值" + state); | |||
break; | |||
} | |||
//关闭图片上传连接 | |||
boolean b_Close = FaceMain.hCNetSDK.NET_DVR_UploadClose(iUploadHandle); | |||
if (!b_Close) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_UploadSend失败,错误号" + iErr); | |||
return; | |||
} | |||
} | |||
//上传人脸图片分析,获取建模数据 | |||
public static String analysisImage(int lUserID,String fileName) throws IOException, DocumentException { | |||
String sURL = "POST /ISAPI/Intelligent/analysisImage/face"; | |||
HCNetSDK.BYTE_ARRAY stringRequest = new HCNetSDK.BYTE_ARRAY(1024); | |||
stringRequest.read(); | |||
stringRequest.byValue = sURL.getBytes(); | |||
stringRequest.write(); | |||
//读取二进制文件 | |||
byte[] picbyte = CommonMethod.toByteArray(fileName); | |||
HCNetSDK.BYTE_ARRAY byte_array = new HCNetSDK.BYTE_ARRAY(picbyte.length); | |||
byte_array.read(); | |||
byte_array.byValue = picbyte; | |||
byte_array.write(); | |||
HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT(); | |||
struXMLInput.read(); | |||
struXMLInput.dwSize = struXMLInput.size(); | |||
struXMLInput.lpRequestUrl = stringRequest.getPointer(); | |||
struXMLInput.dwRequestUrlLen = sURL.length(); | |||
struXMLInput.lpInBuffer = byte_array.getPointer(); //图片二进制数据 | |||
struXMLInput.dwInBufferSize = byte_array.size(); | |||
struXMLInput.write(); | |||
HCNetSDK.BYTE_ARRAY stringXMLOut = new HCNetSDK.BYTE_ARRAY(8 * 1024); | |||
stringXMLOut.read(); | |||
HCNetSDK.BYTE_ARRAY struXMLStatus = new HCNetSDK.BYTE_ARRAY(1024); | |||
struXMLStatus.read(); | |||
HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT(); | |||
struXMLOutput.read(); | |||
struXMLOutput.dwSize = struXMLOutput.size(); | |||
struXMLOutput.lpOutBuffer = stringXMLOut.getPointer(); | |||
struXMLOutput.dwOutBufferSize = stringXMLOut.size(); | |||
struXMLOutput.lpStatusBuffer = struXMLStatus.getPointer(); | |||
struXMLOutput.dwStatusSize = struXMLStatus.size(); | |||
struXMLOutput.write(); | |||
if (!FaceMain.hCNetSDK.NET_DVR_STDXMLConfig(lUserID, struXMLInput, struXMLOutput)) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_STDXMLConfig失败,错误号" + iErr); | |||
return null; | |||
} else { | |||
stringXMLOut.read(); | |||
System.out.println("输出文本大小:" + struXMLOutput.dwReturnedXMLSize); | |||
//打印输出XML文本 | |||
String strOutXML = new String(stringXMLOut.byValue).trim(); | |||
System.out.println(strOutXML); | |||
Document doc = null; | |||
doc = DocumentHelper.parseText(strOutXML); // 将字符串转为XML | |||
Element rootElt = doc.getRootElement(); // 获取根节点 | |||
Iterator iter = rootElt.elementIterator("FaceContrastTarget"); // 获取根节点下的子节点FaceContrastTarget | |||
while (iter.hasNext()) { | |||
Element recordEle = (Element) iter.next(); | |||
ModeData = recordEle.elementTextTrim("modeData"); // 拿到FaceContrastTarget节点下的子节点modeData值 | |||
System.out.println("modeData:" + ModeData); | |||
} | |||
struXMLStatus.read(); | |||
String strStatus = new String(struXMLStatus.byValue).trim(); | |||
System.out.println(strStatus); | |||
return ModeData; | |||
} | |||
} | |||
/** | |||
* 查询人脸库中指定人员信息 | |||
* @param userID | |||
*/ | |||
public static void searchPicInfo(int userID) | |||
{ | |||
/*查询指定人脸库的人脸信息*/ | |||
String requestUrl = "POST /ISAPI/Intelligent/FDLib/FDSearch"; | |||
String HumanName = "测试人员"; //人员姓名 | |||
String FDID = "0A1520C29E524490AE6100DB9E908099"; | |||
String strOutXML = ISAPI.sdk_isapi(userID, requestUrl, FacePicManage.searchByName_XmlCreat(FDID, HumanName)); | |||
System.out.println(strOutXML); | |||
} | |||
/** | |||
*特征值搜图 | |||
* @param userID | |||
* @param FDID | |||
* @throws DocumentException | |||
* @throws IOException | |||
*/ | |||
public static void modeDataSearch(int userID,String FDID) throws DocumentException, IOException { | |||
/**按照图片搜索*/ | |||
String ModeData = FacePicManage.analysisImage(userID,".\\pic\\test.jpg");//上传图片分析,分析结果返回模型数据 | |||
//使用模型数据检索人脸库 | |||
String requestUrl = "POST /ISAPI/Intelligent/FDLib/FDSearch"; | |||
String strOutXML = ISAPI.sdk_isapi(userID, requestUrl, FacePicManage.fDModeDate_XmlCreat(FDID, ModeData)); | |||
System.out.println(strOutXML); | |||
} | |||
/** | |||
* 此接口可以实现比对记录查询,抓怕记录查询 | |||
* @param userID | |||
*/ | |||
public static void fcSearch(int userID){ | |||
/**查询设备中存储的人脸比对结果信息*/ | |||
String requestUrl = "POST /ISAPI/Intelligent/FDLib/FCSearch"; | |||
String strOutXML = ISAPI.sdk_isapi(userID, requestUrl, CommonMethod.fCSearch_XmlCreat("0A1520C29E524490AE6100DB9E908099")); | |||
System.out.println(strOutXML); | |||
} | |||
// 创建人脸库输入XML报文 | |||
public static String fDCreate_XmlCreat(String ID, String Name) { | |||
/*<CreateFDLibList version="2.0" xmlns="http://www.isapi.org/ver20/XMLSchema"> | |||
<!--req,创建人脸比对库输入参数--> | |||
<CreateFDLib> | |||
<id> | |||
<!--req, xs:integer,"表示list中子项个数,从"1"开始赋值,依次增加" --> | |||
</id> | |||
<name> | |||
<!--opt, xs:string,"人脸比对库名称"--> | |||
</name> | |||
<thresholdValue> | |||
<!--opt, xs:integer, "检测阈值,阈值越大检测准确率越低, 范围[0,100]"--> | |||
</thresholdValue> | |||
<customInfo> | |||
<!--opt, xs:string, 人脸库附加信息--> | |||
</customInfo> | |||
<customFaceLibID> | |||
<!--opt, xs:string, "自定义人脸库ID, 由上层下发给设备, 该ID由上层维护并确保唯一性, | |||
设备侧需将自定义人脸库ID与设备生成的FDID进行关联, 确保上层可通过下发人脸库ID来替代下发FDID进行后续操作"--> | |||
</customFaceLibID> | |||
</CreateFDLib> | |||
</CreateFDLibList>*/ | |||
Document document1; | |||
Element root = DocumentHelper.createElement("CreateFDLibList"); | |||
document1 = DocumentHelper.createDocument(root); | |||
Element CreateFDLib = root.addElement("CreateFDLib"); | |||
Element id = CreateFDLib.addElement("id"); | |||
id.setText(ID); | |||
Element name = CreateFDLib.addElement("name"); | |||
name.setText(Name); | |||
Element thresholdValue = CreateFDLib.addElement("thresholdValue"); | |||
thresholdValue.setText("70"); | |||
String requestXml = document1.asXML(); | |||
return requestXml; | |||
} | |||
//查询人脸比对库里的图片输入XML报文 | |||
public static String fDModeDate_XmlCreat(String sFDID, String sModeData) { | |||
Document document1; | |||
Element root = DocumentHelper.createElement("FDSearchDescription"); | |||
document1 = DocumentHelper.createDocument(root); | |||
Element searchID = root.addElement("searchID"); | |||
searchID.setText("C929433A-AD10-0001-CA62-1A701E0015F4"); | |||
Element searchResultPosition = root.addElement("searchResultPosition"); | |||
searchResultPosition.setText("0"); | |||
Element maxResults = root.addElement("maxResults"); | |||
maxResults.setText("50"); | |||
Element FDID = root.addElement("FDID"); | |||
FDID.setText(sFDID); | |||
Element FaceModeList = root.addElement("FaceModeList"); | |||
Element FaceMode = FaceModeList.addElement("FaceMode"); | |||
Element ModeInfo = FaceMode.addElement("ModeInfo"); | |||
Element similarity = ModeInfo.addElement("similarity"); | |||
similarity.setText("80"); | |||
Element modeData = ModeInfo.addElement("modeData"); | |||
modeData.setText(sModeData); | |||
String requestXml = document1.asXML(); | |||
System.out.println(requestXml); | |||
return requestXml; | |||
} | |||
//查询的人员输入报文 | |||
//ID:人脸库ID | |||
// Name: 人员姓名 | |||
public static String searchByName_XmlCreat(String ID, String Name) { | |||
/* <FDSearchDescription> | |||
<searchID>C929433A-AD10-0001-CA62-1A701E0015F2</searchID> | |||
<maxResults>50</maxResults> | |||
<searchResultPosition>0</searchResultPosition> | |||
<FDID>1135C03401404CC696F02B03F649ACFE</FDID> | |||
<name>test</name> | |||
<sex>male</sex> | |||
<province>21</province> | |||
<city>01</city> | |||
</FDSearchDescription>*/ | |||
Document document1; | |||
Element root = DocumentHelper.createElement("FDSearchDescription"); | |||
document1 = DocumentHelper.createDocument(root); | |||
Element searchID = root.addElement("searchID"); | |||
//每次查询条件不同,searchID保持不同 | |||
searchID.setText(String.valueOf(UUID.randomUUID())); | |||
Element maxResults = root.addElement("maxResults"); | |||
maxResults.setText("50"); | |||
Element searchResultPosition = root.addElement("searchResultPosition"); | |||
searchResultPosition.setText("0"); | |||
Element FDID = root.addElement("FDID"); | |||
FDID.setText(ID); | |||
//如果需要查询所有,查询报文取消name节点 | |||
Element name = root.addElement("name"); | |||
name.setText(Name); | |||
String requestXml = document1.asXML(); | |||
System.out.println(requestXml); | |||
return requestXml; | |||
} | |||
//添加人脸附加信息报文 | |||
public static String xmlFaceAppendData() throws UnsupportedEncodingException { | |||
/* <FDSearchDescription> | |||
<searchID>C929433A-AD10-0001-CA62-1A701E0015F2</searchID> | |||
<maxResults>50</maxResults> | |||
<searchResultPosition>0</searchResultPosition> | |||
<FDID>1135C03401404CC696F02B03F649ACFE</FDID> | |||
<name>test</name> | |||
<sex>male</sex> | |||
<province>21</province> | |||
<city>01</city> | |||
</FDSearchDescription>*/ | |||
Document document1; | |||
Element root = DocumentHelper.createElement("FaceAppendData"); | |||
document1 = DocumentHelper.createDocument(root); | |||
Element bornTime = root.addElement("bornTime"); | |||
bornTime.setText("2020-12-12T00:00:00Z"); | |||
Element name = root.addElement("name"); | |||
name.setText("test"); | |||
Element sex = root.addElement("sex"); | |||
sex.setText("male"); | |||
Element province = root.addElement("province"); | |||
province.setText("11"); | |||
Element city = root.addElement("city"); | |||
city.setText("01"); | |||
Element certificateType = root.addElement("certificateType"); | |||
certificateType.setText("officerID"); | |||
Element certificateNumber = root.addElement("certificateNumber"); | |||
certificateNumber.setText("1123123123"); | |||
Element PersonInfoExtendList = root.addElement("PersonInfoExtendList"); | |||
Element PersonInfoExtend = PersonInfoExtendList.addElement("PersonInfoExtend"); | |||
Element id = PersonInfoExtend.addElement("id"); | |||
id.setText("1"); | |||
Element enable = PersonInfoExtend.addElement("enable"); | |||
enable.setText("1"); | |||
Element name1 = PersonInfoExtend.addElement("name"); | |||
name1.setText("1"); | |||
Element value = PersonInfoExtend.addElement("value"); | |||
value.setText("1"); | |||
String requestXml = document1.asXML(); | |||
System.out.println(requestXml); | |||
return requestXml; | |||
} | |||
} |
@@ -1,182 +0,0 @@ | |||
package com.iformall.haikang.face; | |||
import com.iformall.haikang.face.common.CommonMethod; | |||
import com.iformall.haikang.face.common.HCNetSDK; | |||
import com.sun.jna.Pointer; | |||
import com.sun.jna.ptr.IntByReference; | |||
import java.io.IOException; | |||
import java.io.UnsupportedEncodingException; | |||
/** | |||
* 自定义人脸库和自定义人脸ID集成流程 | |||
* 自定义人脸图片所在的人脸库必须为私密库,人脸库增删时必须使用identityKey字段,不使用的话目前设备不支持增加,会导致无法检索和删除。 | |||
*/ | |||
public class FacePicManagebyCustom { | |||
/** | |||
* 自定义ID创建一个人脸库 | |||
* @param lUserID | |||
* @param identityKey 交互口令 | |||
* @param name 人脸库名称 | |||
* @param customlibid 人脸库自定义ID | |||
* @throws UnsupportedEncodingException | |||
* | |||
*/ | |||
public static void creatCustomFaceLib(int lUserID, String identityKey,String name, String customlibid ) throws UnsupportedEncodingException | |||
{ | |||
String result=ISAPI.sdk_isapi(lUserID,"POST /ISAPI/Intelligent/FDLib?FDType=custom&&identityKey="+identityKey,CommonMethod.xmlCreatCustomID("1",name,customlibid)); | |||
System.out.println("创建自定义人脸库结果:"+result); | |||
} | |||
/** | |||
* 查询自定义人脸库信息 | |||
* @param lUserID | |||
* @param identityKey | |||
* @param customlibid | |||
* @throws UnsupportedEncodingException | |||
*/ | |||
public static void getCustomFaceLib(int lUserID, String identityKey,String customlibid) throws UnsupportedEncodingException | |||
{ | |||
String result=ISAPI.sdk_isapi(lUserID,"GET /ISAPI/Intelligent/FDLib/"+customlibid+"?FDType=custom&&identityKey="+identityKey, ""); | |||
System.out.println("获取自定义人脸库结果:"+result); | |||
} | |||
public static void delCustomFaceLib(int lUserID,String identityKey,String customlibid) throws UnsupportedEncodingException | |||
{ | |||
String result =ISAPI.sdk_isapi(lUserID,"DELETE /ISAPI/Intelligent/FDLib/"+customlibid+"?FDType=custom&&identityKey="+identityKey, ""); | |||
System.out.println("删除自定义人脸库结果:"+result); | |||
} | |||
/** | |||
* 自定义人脸库中添加自定义人脸ID | |||
* @param lUserID | |||
* @param customFDID | |||
* @param IdentityKey | |||
* @throws IOException | |||
*/ | |||
public static void uploadPicbycustomID(int lUserID, String customFDID,String IdentityKey ) throws IOException { | |||
HCNetSDK.NET_DVR_FACELIB_COND struFaceLibCond = new HCNetSDK.NET_DVR_FACELIB_COND(); | |||
struFaceLibCond.read(); | |||
struFaceLibCond.dwSize = struFaceLibCond.size(); | |||
struFaceLibCond.szFDID = customFDID.getBytes(); //人脸库ID | |||
struFaceLibCond.byCustomFaceLibID=1; //人脸库ID是否是自定义:0- 不是,1- 是 | |||
struFaceLibCond.byIdentityKey= IdentityKey.getBytes(); //交互操作口令 和自定义添加人脸库的IdentityKey保持一致 | |||
struFaceLibCond.byConcurrent = 0; //设备并发处理:0- 不开启(设备自动会建模),1- 开始(设备不会自动进行建模) | |||
struFaceLibCond.byCover = 1; //是否覆盖式导入(人脸库存储满的情况下强制覆盖导入时间最久的图片数据):0- 否,1- 是 | |||
struFaceLibCond.write(); | |||
Pointer pStruFaceLibCond = struFaceLibCond.getPointer(); | |||
int iUploadHandle = FaceMain.hCNetSDK.NET_DVR_UploadFile_V40(lUserID, HCNetSDK.IMPORT_DATA_TO_FACELIB, pStruFaceLibCond, | |||
struFaceLibCond.size(), null, Pointer.NULL, 0); | |||
if (iUploadHandle <= -1) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_UploadFile_V40失败,错误号" + iErr); | |||
return; | |||
} else { | |||
System.out.println("NET_DVR_UploadFile_V40成功"); | |||
} | |||
HCNetSDK.NET_DVR_SEND_PARAM_IN struSendParam = new HCNetSDK.NET_DVR_SEND_PARAM_IN(); | |||
struSendParam.read(); | |||
//本地jpg图片转成二进制byte数组 | |||
byte[] picbyte = CommonMethod.toByteArray(".\\pic\\test1.jpg"); | |||
HCNetSDK.BYTE_ARRAY arraybyte = new HCNetSDK.BYTE_ARRAY(picbyte.length); | |||
arraybyte.read(); | |||
arraybyte.byValue = picbyte; | |||
arraybyte.write(); | |||
struSendParam.pSendData = arraybyte.getPointer(); | |||
struSendParam.dwSendDataLen = picbyte.length; | |||
struSendParam.byPicType = 1; //图片格式:1- jpg,2- bmp,3- png,4- SWF,5- GIF | |||
struSendParam.sPicName = "test01".getBytes(); //图片名称 | |||
//图片的附加信息缓冲区 图片上添加的属性信息,性别、身份等 | |||
//1:xml文本导入方式 | |||
/** byte[] AppendData = CommonMethod.toByteArray("..\\pic\\test.xml"); | |||
HCNetSDK.BYTE_ARRAY byteArray = new HCNetSDK.BYTE_ARRAY(AppendData.length); | |||
byteArray.read(); | |||
byteArray.byValue = AppendData; | |||
byteArray.write();*/ | |||
/**2:包含中文姓名的报文上传 | |||
<customHumanID>ID20220109</customHumanID> 表示自定义人脸ID*/ | |||
byte[] byFDLibName = "测试名称".getBytes("UTF-8"); | |||
String strInBuffer1 = new String("<FaceAppendData version=\"2.0\" xmlns=\"http://www.hikvision.com/ver20/XMLSchema\"><bornTime>2014-12-12T00:00:00Z</bornTime><name>"); | |||
String strInBuffer2 = new String("</name><sex>female</sex><province>11</province><city>01</city><certificateType>officerID</certificateType><certificateNumber>1123123123</certificateNumber><PersonInfoExtendList><PersonInfoExtend><id>1</id><enable>false</enable><name>test1</name><value>test2</value></PersonInfoExtend></PersonInfoExtendList><customHumanID>ID20220109</customHumanID></FaceAppendData>"); | |||
int iStringSize = byFDLibName.length + strInBuffer1.length() + strInBuffer2.length(); | |||
HCNetSDK.BYTE_ARRAY ptrByte = new HCNetSDK.BYTE_ARRAY(iStringSize); | |||
System.arraycopy(strInBuffer1.getBytes(), 0, ptrByte.byValue, 0, strInBuffer1.length()); | |||
System.arraycopy(byFDLibName, 0, ptrByte.byValue, strInBuffer1.length(), byFDLibName.length); | |||
System.arraycopy(strInBuffer2.getBytes(), 0, ptrByte.byValue, strInBuffer1.length() + byFDLibName.length, strInBuffer2.length()); | |||
ptrByte.write(); | |||
struSendParam.pSendAppendData = ptrByte.getPointer(); | |||
struSendParam.dwSendAppendDataLen = ptrByte.byValue.length; | |||
struSendParam.write(); | |||
int iSendData = FaceMain.hCNetSDK.NET_DVR_UploadSend( iUploadHandle, struSendParam, Pointer.NULL); | |||
if (iSendData <= -1) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_UploadSend失败,错误号" + iErr); | |||
return; | |||
} | |||
while (true) { | |||
IntByReference Pint = new IntByReference(0); | |||
int state = FaceMain.hCNetSDK.NET_DVR_GetUploadState(iUploadHandle, Pint.getPointer()); | |||
if (state == 1) { | |||
System.out.println("上传成功"); | |||
//获取图片ID | |||
HCNetSDK.NET_DVR_UPLOAD_FILE_RET struUploadRet = new HCNetSDK.NET_DVR_UPLOAD_FILE_RET(); | |||
boolean bUploadResult = FaceMain.hCNetSDK.NET_DVR_GetUploadResult(iUploadHandle, struUploadRet.getPointer(), struUploadRet.size()); | |||
if (!bUploadResult) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_GetUploadResult失败,错误号" + iErr); | |||
} else { | |||
struUploadRet.read(); | |||
System.out.println("图片ID:" + new String(struUploadRet.sUrl, "UTF-8")); | |||
} | |||
break; | |||
} else if (state == 2) { | |||
System.out.println("进度:" + Pint.getValue()); | |||
continue; | |||
} | |||
System.err.println("返回值" + state); | |||
break; | |||
} | |||
//关闭图片上传连接 | |||
boolean b_Close = FaceMain.hCNetSDK.NET_DVR_UploadClose(iUploadHandle); | |||
if (!b_Close) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_UploadSend失败,错误号" + iErr); | |||
return; | |||
} | |||
} | |||
/** | |||
* 根据自定义人脸ID查询人脸图片 | |||
* @param lUserID | |||
* @param customID 自定义人脸库ID | |||
* @param customHumanID 自定义人脸ID | |||
*@param identityKey 创建自定义人脸的交互口令 | |||
* @throws UnsupportedEncodingException | |||
*/ | |||
public static void getFacePicBycustomID(int lUserID, String customID, String customHumanID,String identityKey) throws UnsupportedEncodingException { | |||
String requestUrl = "GET /ISAPI/Intelligent/FDLib/" + customID + "/picture/" + customHumanID+"?FDType=custom&&identityKey="+identityKey; | |||
String result=ISAPI.sdk_isapi(lUserID, requestUrl, ""); | |||
System.out.println("查询自定义人脸图片结果:"+result); | |||
} | |||
public static void delFacePicBycustomID(int lUserID, String customID, String customHumanID,String identityKey) throws UnsupportedEncodingException | |||
{ | |||
String requestUrl = "DELETE /ISAPI/Intelligent/FDLib/" + customID + "/picture/" + customHumanID+"?FDType=custom&&identityKey="+identityKey; | |||
String result=ISAPI.sdk_isapi(lUserID, requestUrl, ""); | |||
System.out.println("删除自定义人脸图片结果:"+result); | |||
} | |||
} |
@@ -1,94 +0,0 @@ | |||
package com.iformall.haikang.face; | |||
import java.io.UnsupportedEncodingException; | |||
import com.iformall.haikang.face.common.HCNetSDK; | |||
/** | |||
* 功能:透传接口实现,透传ISAPI命令 | |||
*/ | |||
public class ISAPI { | |||
/** | |||
* SDK透传ISAPI协议报文接口 | |||
* @param lUserID | |||
* @param url | |||
* @param inputXml 输入报文 | |||
* @return | |||
* @throws UnsupportedEncodingException | |||
*/ | |||
public static String sdk_isapi(int lUserID, String url, String inputXml) { | |||
String strOutXML = ""; | |||
//输入参数 | |||
HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT(); | |||
struXMLInput.read(); | |||
struXMLInput.dwSize = struXMLInput.size(); | |||
HCNetSDK.BYTE_ARRAY stringRequest = new HCNetSDK.BYTE_ARRAY(1024); | |||
stringRequest.read(); | |||
//输入ISAPI协议命令 批量查询人脸库命令:GET /ISAPI/Intelligent/FDLib | |||
System.arraycopy(url.getBytes(), 0, stringRequest.byValue, 0, url.length()); | |||
stringRequest.write(); | |||
struXMLInput.lpRequestUrl = stringRequest.getPointer(); | |||
struXMLInput.dwRequestUrlLen = url.length(); | |||
//输入XML文本,GET命令不传输入文本 | |||
int inputDataLen = 0; | |||
try { | |||
inputDataLen = inputXml.getBytes("UTF-8").length; | |||
} catch (UnsupportedEncodingException e) { | |||
e.printStackTrace(); | |||
} | |||
if(inputDataLen > 0) | |||
{ | |||
HCNetSDK.BYTE_ARRAY stringInBuffer = new HCNetSDK.BYTE_ARRAY(inputDataLen); | |||
stringInBuffer.read(); | |||
try { | |||
System.arraycopy(inputXml.getBytes("UTF-8"), 0, stringInBuffer.byValue, 0, inputDataLen); | |||
} catch (UnsupportedEncodingException e) { | |||
e.printStackTrace(); | |||
} | |||
stringInBuffer.write(); | |||
struXMLInput.lpInBuffer = stringInBuffer.getPointer(); | |||
struXMLInput.dwInBufferSize = inputDataLen; | |||
} | |||
else | |||
{ | |||
struXMLInput.lpInBuffer = null; | |||
struXMLInput.dwInBufferSize = 0; | |||
} | |||
struXMLInput.write(); | |||
HCNetSDK.BYTE_ARRAY stringXMLOut = new HCNetSDK.BYTE_ARRAY(2*1024 * 1024); | |||
stringXMLOut.read(); | |||
HCNetSDK.BYTE_ARRAY struXMLStatus = new HCNetSDK.BYTE_ARRAY(1024); | |||
struXMLStatus.read(); | |||
HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT(); | |||
struXMLOutput.read(); | |||
struXMLOutput.dwSize = struXMLOutput.size(); | |||
struXMLOutput.lpOutBuffer = stringXMLOut.getPointer(); | |||
struXMLOutput.dwOutBufferSize = stringXMLOut.size(); | |||
struXMLOutput.lpStatusBuffer = struXMLStatus.getPointer(); | |||
struXMLOutput.dwStatusSize = struXMLStatus.size(); | |||
struXMLOutput.write(); | |||
if (!FaceMain.hCNetSDK.NET_DVR_STDXMLConfig(lUserID, struXMLInput, struXMLOutput)) { | |||
int iErr = FaceMain.hCNetSDK.NET_DVR_GetLastError(); | |||
System.err.println("NET_DVR_STDXMLConfig失败,错误号: " + iErr + ",URL: " + url); | |||
return null; | |||
} else { | |||
stringXMLOut.read(); | |||
System.out.println("输出文本大小:" + struXMLOutput.dwReturnedXMLSize); | |||
//打印输出XML文本 | |||
strOutXML = new String(stringXMLOut.byValue).trim(); | |||
//System.out.println(strOutXML); | |||
struXMLStatus.read(); | |||
String strStatus = new String(struXMLStatus.byValue).trim(); | |||
System.out.println(strStatus); | |||
return strOutXML; | |||
} | |||
} | |||
} |
@@ -1,123 +0,0 @@ | |||
package com.iformall.haikang.face.common; | |||
import org.dom4j.Document; | |||
import org.dom4j.DocumentHelper; | |||
import org.dom4j.Element; | |||
import java.io.*; | |||
import java.util.UUID; | |||
public class CommonMethod { | |||
/** | |||
* 读取本地文件到数组中 | |||
* | |||
* @param filename 本地文件 | |||
* @return 返回读取到的数据到 byte数组 | |||
* @throws IOException | |||
*/ | |||
public static byte[] toByteArray(String filename) throws IOException { | |||
File file = new File(filename); | |||
if (!file.exists()) { | |||
throw new FileNotFoundException(filename); | |||
} | |||
ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length()); | |||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); | |||
try { | |||
byte[] buffer = new byte[1024]; | |||
int len; | |||
while (-1 != (len = in.read(buffer, 0, buffer.length))) { | |||
bos.write(buffer, 0, len); | |||
} | |||
return bos.toByteArray(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
throw e; | |||
} finally { | |||
bos.close(); | |||
in.close(); | |||
} | |||
} | |||
//int 转化为字节数组 | |||
public static byte[] intTobyte2(int num) | |||
{ | |||
byte[] result=null; | |||
ByteArrayOutputStream bos=new ByteArrayOutputStream(); | |||
DataOutputStream dos=new DataOutputStream(bos); | |||
try { | |||
dos.writeInt(num); | |||
result=bos.toByteArray(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
return result; | |||
} | |||
// 创建人脸库输入XML报文 | |||
public static String xmlCreatCustomID(String ID, String Name,String customFaceLibID ) { | |||
/*<CreateFDLibList version="2.0" xmlns="http://www.isapi.org/ver20/XMLSchema"> | |||
<!--req,创建人脸比对库输入参数--> | |||
<CreateFDLib> | |||
<id> | |||
<!--req, xs:integer,"表示list中子项个数,从"1"开始赋值,依次增加" --> | |||
</id> | |||
<name> | |||
<!--opt, xs:string,"人脸比对库名称"--> | |||
</name> | |||
<thresholdValue> | |||
<!--opt, xs:integer, "检测阈值,阈值越大检测准确率越低, 范围[0,100]"--> | |||
</thresholdValue> | |||
<customInfo> | |||
<!--opt, xs:string, 人脸库附加信息--> | |||
</customInfo> | |||
<customFaceLibID> | |||
<!--opt, xs:string, "自定义人脸库ID, 由上层下发给设备, 该ID由上层维护并确保唯一性, | |||
设备侧需将自定义人脸库ID与设备生成的FDID进行关联, 确保上层可通过下发人脸库ID来替代下发FDID进行后续操作"--> | |||
</customFaceLibID> | |||
</CreateFDLib> | |||
</CreateFDLibList>*/ | |||
Document document1; | |||
Element root = DocumentHelper.createElement("CreateFDLibList"); | |||
document1 = DocumentHelper.createDocument(root); | |||
Element CreateFDLib = root.addElement("CreateFDLib"); | |||
Element id = CreateFDLib.addElement("id"); | |||
id.setText(ID); | |||
Element name = CreateFDLib.addElement("name"); | |||
name.setText(Name); | |||
Element thresholdValue = CreateFDLib.addElement("thresholdValue"); | |||
thresholdValue.setText("70"); | |||
Element CustomFaceLibID = CreateFDLib.addElement("customFaceLibID"); | |||
CustomFaceLibID.setText(customFaceLibID); | |||
String requestXml = document1.asXML(); | |||
return requestXml; | |||
} | |||
//查询人脸比对数据的输入XML报文 | |||
public static String fCSearch_XmlCreat(String fPID) { | |||
Document document1; | |||
Element root = DocumentHelper.createElement("FCSearchDescription"); | |||
document1 = DocumentHelper.createDocument(root); | |||
Element searchID = root.addElement("searchID"); | |||
searchID.setText(String.valueOf(UUID.randomUUID())); | |||
Element searchResultPosition = root.addElement("searchResultPosition"); | |||
searchResultPosition.setText("0"); | |||
Element maxResults = root.addElement("maxResults"); | |||
maxResults.setText("50"); | |||
Element FDID = root.addElement("FDID"); | |||
FDID.setText(fPID); | |||
Element snapStartTime = root.addElement("snapStartTime"); | |||
snapStartTime.setText("2024-08-01T17:00:00Z"); | |||
Element snapEndTime = root.addElement("snapEndTime"); | |||
snapEndTime.setText("2024-08-09T11:53:00Z"); | |||
Element faceMatchInfoEnable = root.addElement("faceMatchInfoEnable"); | |||
faceMatchInfoEnable.setText("true"); | |||
Element eventType = root.addElement("eventType"); | |||
eventType.setText("whiteFaceContrast"); | |||
Element sortord = root.addElement("sortord"); | |||
sortord.setText("time"); | |||
String requestXml = document1.asXML(); | |||
return requestXml; | |||
} | |||
} |
@@ -1,16 +0,0 @@ | |||
package com.iformall.haikang.face.common; | |||
/** | |||
* @author jiangxin | |||
* @create 2022-01-19-16:40 | |||
*/ | |||
public class osSelect { | |||
public static boolean isLinux() { | |||
return System.getProperty("os.name").toLowerCase().contains("linux"); | |||
} | |||
public static boolean isWindows() { | |||
return System.getProperty("os.name").toLowerCase().contains("windows"); | |||
} | |||
} |