bug修复
This commit is contained in:
parent
3b52744fef
commit
78c3e53e21
@ -3,6 +3,7 @@ package com.zhgd.xmgl.call;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@ -29,6 +30,7 @@ import com.zhgd.xmgl.modules.worker.service.IWorkerAttendanceService;
|
||||
import com.zhgd.xmgl.util.Base64Util;
|
||||
import com.zhgd.xmgl.util.HikvisionUtil;
|
||||
import com.zhgd.xmgl.util.PathUtil;
|
||||
import com.zhgd.xmgl.util.X509TrustManagerUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -40,6 +42,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@ -74,19 +77,6 @@ public class HikvisionCall {
|
||||
@Lazy
|
||||
private CarInfoMapper carInfoMapper;
|
||||
|
||||
/**
|
||||
* 海康请求失败重试定 时
|
||||
*/
|
||||
@Scheduled(cron = "4 0 0 * * ?")
|
||||
@PostMapping(value = "/failRetry")
|
||||
public void failRetry() {
|
||||
List<HikvisionRequestRetry> hikvisionRequestRetries = hikvisionRequestRetryMapper.selectList(new LambdaQueryWrapper<HikvisionRequestRetry>()
|
||||
.lt(HikvisionRequestRetry::getRequestNum, 4));
|
||||
for (HikvisionRequestRetry retry : hikvisionRequestRetries) {
|
||||
HikvisionUtil.doPost(retry.getHost(), retry.getPath(), retry.getBody(), null, retry.getAppKey(), retry.getAppSecret(), retry.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "海康事件回调", notes = "海康事件回调", httpMethod = "POST")
|
||||
@PostMapping(value = "/eventCallback")
|
||||
public Result eventCallback(@ApiIgnore @RequestBody JSONObject jsonObject) {
|
||||
@ -138,7 +128,7 @@ public class HikvisionCall {
|
||||
HikvisionEventsPictureRq rq = new HikvisionEventsPictureRq();
|
||||
rq.setPicUri(extEventPictureURL);
|
||||
rq.setSvrIndexCode(svrIndexCode);
|
||||
map.put("faceUrl", getHikvisionEventsPicture(rq, project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
|
||||
map.put("faceUrl", saveToLocal(getHikvisionEventsPicture(rq, project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret())));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -172,6 +162,10 @@ public class HikvisionCall {
|
||||
if (eventType == 771760134 || eventType == 771760131) {
|
||||
//出入场放行
|
||||
CarPassRecord carPassRecord = carPassRecordMapper.getNewestlineBreakingEvent(plateNo, time);
|
||||
if (carPassRecord == null) {
|
||||
log.info("海康回调出入场放行的压线不存在:plateNo:{}", plateNo);
|
||||
return Result.error("");
|
||||
}
|
||||
carPassRecord.setIsOpen(1);
|
||||
carPassRecordMapper.updateById(carPassRecord);
|
||||
} else if (eventType == 771760130 || eventType == 771760133) {
|
||||
@ -187,8 +181,8 @@ public class HikvisionCall {
|
||||
String svrIndex = dataJo.getString("svrIndex");
|
||||
String vehiclePicUrl = picUrlJo.getString("vehiclePicUrl");
|
||||
String platePicUrl = picUrlJo.getString("platePicUrl");
|
||||
entity.setImageUrl(getHikvisionEventsPicture(new HikvisionEventsPictureRq(svrIndex, platePicUrl), project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
|
||||
entity.setPanoramaUrl(getHikvisionEventsPicture(new HikvisionEventsPictureRq(svrIndex, vehiclePicUrl), project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
|
||||
entity.setImageUrl(saveToLocal(getHikvisionEventsPicture(new HikvisionEventsPictureRq(svrIndex, platePicUrl), project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret())));
|
||||
entity.setPanoramaUrl(saveToLocal(getHikvisionEventsPicture(new HikvisionEventsPictureRq(svrIndex, vehiclePicUrl), project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret())));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -208,6 +202,94 @@ public class HikvisionCall {
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 海康请求失败重试定时
|
||||
*/
|
||||
@Scheduled(cron = "4 0 0 * * ?")
|
||||
@PostMapping(value = "/failRetry")
|
||||
public void failRetry() {
|
||||
List<HikvisionRequestRetry> hikvisionRequestRetries = hikvisionRequestRetryMapper.selectList(new LambdaQueryWrapper<HikvisionRequestRetry>()
|
||||
.lt(HikvisionRequestRetry::getRequestNum, 4));
|
||||
for (HikvisionRequestRetry retry : hikvisionRequestRetries) {
|
||||
HikvisionUtil.doPost(retry.getHost(), retry.getPath(), retry.getBody(), null, retry.getAppKey(), retry.getAppSecret(), retry.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "按事件类型订阅事件", notes = "按事件类型订阅事件", httpMethod = "POST")
|
||||
@PostMapping(value = "/subscribeEvent")
|
||||
public Result subscribeEvent(@ApiIgnore @RequestBody SubscribeEventQo qo) {
|
||||
final String ARTEMIS_PATH = "/artemis";
|
||||
final String path = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
|
||||
String host = "https://" + qo.getArtemisConfigHost();
|
||||
String rs = HikvisionUtil.doPost(host, path, JSON.toJSONString(qo), null, qo.getArtemisConfigAppKey(), qo.getArtemisConfigAppSecret());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试查询组织
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getOrg")
|
||||
public Result getOrg() {
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, "B717CB992D054A878FDAFB4A5C169947"));
|
||||
getOrg(project);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试查询停车场
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getPark")
|
||||
public Result getParkList() {
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, "B717CB992D054A878FDAFB4A5C169947"));
|
||||
JSONArray parkList = getParkList(project);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询车辆列表v2
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getCarList")
|
||||
public Result getCarList() {
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, "B717CB992D054A878FDAFB4A5C169947"));
|
||||
getCarList(project);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取图片
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getPic")
|
||||
public Result getPic() {
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, "B717CB992D054A878FDAFB4A5C169947"));
|
||||
String svrIndex = null;
|
||||
String platePicUrl = null;
|
||||
getHikvisionEventsPicture(new HikvisionEventsPictureRq(svrIndex, platePicUrl), project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取人员详情
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getWorkInfo")
|
||||
public Result getWorkInfo() {
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, "B717CB992D054A878FDAFB4A5C169947"));
|
||||
String svrIndex = null;
|
||||
String platePicUrl = null;
|
||||
WorkerInfo workerInfo = workerInfoMapper.selectById(1765673550491725825L);
|
||||
getWorkerInfo(workerInfo, project);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车辆颜色
|
||||
*
|
||||
@ -298,52 +380,6 @@ public class HikvisionCall {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "按事件类型订阅事件", notes = "按事件类型订阅事件", httpMethod = "POST")
|
||||
@PostMapping(value = "/subscribeEvent")
|
||||
public Result subscribeEvent(@ApiIgnore @RequestBody SubscribeEventQo qo) {
|
||||
final String ARTEMIS_PATH = "/artemis";
|
||||
final String path = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
|
||||
String host = "https://" + qo.getArtemisConfigHost();
|
||||
String rs = HikvisionUtil.doPost(host, path, JSON.toJSONString(qo), null, qo.getArtemisConfigAppKey(), qo.getArtemisConfigAppSecret());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试查询组织
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getOrg")
|
||||
public Result getOrg() {
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, "B717CB992D054A878FDAFB4A5C169947"));
|
||||
getOrg(project);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试查询停车场
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getPark")
|
||||
public Result getParkList() {
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, "B717CB992D054A878FDAFB4A5C169947"));
|
||||
JSONArray parkList = getParkList(project);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询车辆列表v2
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getCarList")
|
||||
public Result getCarList() {
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, "B717CB992D054A878FDAFB4A5C169947"));
|
||||
getCarList(project);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加人员
|
||||
@ -1155,4 +1191,16 @@ public class HikvisionCall {
|
||||
HikvisionUtil.doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||||
}
|
||||
|
||||
|
||||
public String saveToLocal(String url) {
|
||||
String fileName = IdUtil.simpleUUID() + ".png";
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
X509TrustManagerUtil.downLoadFromUrlHttps(url, fileName, basePath);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,6 +115,9 @@
|
||||
remark = #{remark,jdbcType=VARCHAR},
|
||||
begin_warning = #{beginWarning},
|
||||
end_warning = #{endWarning},
|
||||
danger_point_identification = #{dangerPointIdentification},
|
||||
risk_control_measure = #{riskControlMeasure},
|
||||
construction_key_point = #{constructionKeyPoint},
|
||||
status = #{status},
|
||||
level = #{level,jdbcType=INTEGER},
|
||||
</set>
|
||||
|
||||
174
src/main/java/com/zhgd/xmgl/util/X509TrustManagerUtil.java
Normal file
174
src/main/java/com/zhgd/xmgl/util/X509TrustManagerUtil.java
Normal file
@ -0,0 +1,174 @@
|
||||
package com.zhgd.xmgl.util;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
/**
|
||||
* 处理https的图片
|
||||
*/
|
||||
public class X509TrustManagerUtil implements X509TrustManager {
|
||||
/**
|
||||
* 从网络的url图片保存在本地
|
||||
*
|
||||
* @param urlStr
|
||||
* @param fileName
|
||||
* @param savePath
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void downLoadFromUrlHttps(String urlStr, String fileName,
|
||||
String savePath) throws Exception {
|
||||
// 创建SSLContext
|
||||
SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||
TrustManager[] tm = {new X509TrustManagerUtil()};
|
||||
// 初始化
|
||||
sslContext.init(null, tm, new java.security.SecureRandom());
|
||||
// 获取SSLSocketFactory对象
|
||||
SSLSocketFactory ssf = sslContext.getSocketFactory();
|
||||
// url对象
|
||||
URL url = new URL(urlStr);
|
||||
// 打开连接
|
||||
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
|
||||
/**
|
||||
* 这一步的原因: 当访问HTTPS的网址。您可能已经安装了服务器证书到您的JRE的keystore
|
||||
* 但是服务器的名称与证书实际域名不相等。这通常发生在你使用的是非标准网上签发的证书。
|
||||
*
|
||||
* 解决方法:让JRE相信所有的证书和对系统的域名和证书域名。
|
||||
*
|
||||
* 如果少了这一步会报错:java.io.IOException: HTTPS hostname wrong: should be <localhost>
|
||||
*/
|
||||
conn.setHostnameVerifier(new X509TrustManagerUtil().new TrustAnyHostnameVerifier());
|
||||
// 设置一些参数
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
conn.setUseCaches(false);
|
||||
// 设置当前实例使用的SSLSoctetFactory
|
||||
conn.setSSLSocketFactory(ssf);
|
||||
conn.connect();
|
||||
|
||||
|
||||
// 得到输入流
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
byte[] getData = readInputStream(inputStream);
|
||||
// 文件保存位置
|
||||
File saveDir = new File(savePath);
|
||||
if (!saveDir.exists()) {
|
||||
saveDir.mkdirs();
|
||||
}
|
||||
//输出流
|
||||
File file = new File(saveDir + File.separator + fileName);
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(getData);
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从网络http类型Url中下载文件
|
||||
*
|
||||
* @param urlStr
|
||||
* @param fileName
|
||||
* @param savePath
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void downLoadFromUrlHttp(String urlStr, String fileName,
|
||||
String savePath) throws IOException {
|
||||
URL url = new URL(urlStr);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
// 设置超时间为3秒
|
||||
conn.setConnectTimeout(3 * 1000);
|
||||
// 防止屏蔽程序抓取而返回403错误
|
||||
conn.setRequestProperty("User-Agent",
|
||||
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
||||
conn.connect();
|
||||
|
||||
// 得到输入流
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
byte[] getData = readInputStream(inputStream);
|
||||
// 文件保存位置
|
||||
File saveDir = new File(savePath);
|
||||
if (!saveDir.exists()) {
|
||||
saveDir.mkdirs();
|
||||
}
|
||||
// 输出流
|
||||
File file = new File(saveDir + File.separator + fileName);
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(getData);
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从输入流中获取字节数组
|
||||
*
|
||||
* @param inputStream
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] readInputStream(InputStream inputStream)
|
||||
throws IOException {
|
||||
byte[] b = new byte[1024];
|
||||
int len = 0;
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
while ((len = inputStream.read(b)) != -1) {
|
||||
bos.write(b, 0, len);
|
||||
}
|
||||
bos.close();
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 校验https网址是否安全
|
||||
*
|
||||
* @author solexit06
|
||||
*
|
||||
*/
|
||||
public class TrustAnyHostnameVerifier implements HostnameVerifier {
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
// 直接返回true:默认所有https请求都是安全的
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 里面的方法都是空的,当方法为空是默认为所有的链接都为安全,也就是所有的链接都能够访问到 当然这样有一定的安全风险,可以根据实际需要写入内容
|
||||
*/
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
||||
throws CertificateException {
|
||||
}
|
||||
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType)
|
||||
throws CertificateException {
|
||||
}
|
||||
|
||||
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String name = "C:/Users/solexit06/Desktop/test/";
|
||||
String urls = "https://116.205.128.251:6113/pic?7db681653a5do-5el*31-25976b8-98c2cabbf**b11===sp**812=9t0470280244=7l0*4010=6ob*521e-7pi114o=2dcb2=15a&AccessKeyId=FOZAuZC0Dc84QjvL&Expires=1709893202&Signature=lJnNS138ZVoPwOar6T4QROyg590=";
|
||||
try {
|
||||
downLoadFromUrlHttps(urls, "1.png", name);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user