Browse Source

更新海康接口

master
yangzongjia 2 years ago
parent
commit
b5508ccb67
  1. 13
      yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/callpolice/CallRest.java
  2. 34
      yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/scheduled/SyncService.java
  3. 7
      yxt-supervise-monitor-biz/src/main/resources/application-test.yml
  4. 4
      yxt-supervise-monitor-biz/src/main/resources/application.yml

13
yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/callpolice/CallRest.java

@ -9,6 +9,7 @@ import com.yxt.supervise.monitor.biz.util.HttpUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -32,13 +33,19 @@ public class CallRest {
@Autowired
private SimpMessagingTemplate messagingTemplate;
@Value("${haiKangConsumer.clientId}")
private String clientId;
@Value("${haiKangConsumer.clientSecret}")
private String clientSecret;
@ApiOperation("获取token")
@GetMapping("/getCallToken")
public String getCallToken() throws Exception {
String url = "https://api2.hik-cloud.com/oauth/token";
Map<String, Object> param = new HashMap<>();
param.put("client_id", "e8e655dfcb154be6962f270fe375edc1"); // 客户端ID String
param.put("client_secret", "3ca20239398c4b86b27c6a080d8345e1"); //访问密钥 String
param.put("client_id", clientId); // 客户端ID String
param.put("client_secret", clientSecret); //访问密钥 String
param.put("grant_type", "client_credentials"); //认证模式 String 目前仅支持client_credentials
String result = HttpUtils.sendPostMap(url, param, "");
return result;
@ -175,7 +182,7 @@ public class CallRest {
public String callTempFunc() throws NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException {
//Q16362484
String url = "https://api2.hik-cloud.com/api/v1/open/basic/channels/list?deviceSerial=Q16362484&pageNo=1&pageSize=50";
Map<String,Object> param = new HashMap<>();
Map<String, Object> param = new HashMap<>();
String result = HttpUtils.sendGet(url, "35ad3e80-1de4-4477-827e-0473320cf644");
return result;
}

34
yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/scheduled/SyncService.java

@ -1,29 +1,17 @@
package com.yxt.supervise.monitor.biz.scheduled;
import com.alibaba.fastjson.JSONObject;
import com.yxt.common.core.result.ResultBean;
import com.yxt.supervise.monitor.biz.callpolice.YCallPoliceService;
import com.yxt.supervise.monitor.biz.messageInfo.YMessageInfoService;
import com.yxt.supervise.monitor.biz.task.YTaskService;
import com.yxt.supervise.monitor.biz.util.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
@ -38,9 +26,13 @@ public class SyncService {
@Autowired
YTaskService yTaskService;
@Value("${haiKangConsumer.clientId}")
private String clientId;
@Value("${haiKangConsumer.clientSecret}")
private String clientSecret;
public static String haiKangToken = "";
// public static final String imagePath = "/root/supervise/images/";
// public static final String imagePath = "D:\\resources\\download\\";
public static String haiKangMessageConsumer = "";
@PostConstruct
@ -48,8 +40,8 @@ public class SyncService {
// 先登录
String loginUrl = "https://api2.hik-cloud.com/oauth/token";
Map<String, Object> tokenParam = new HashMap<>();
tokenParam.put("client_id", "e8e655dfcb154be6962f270fe375edc1"); // 客户端ID String
tokenParam.put("client_secret", "3ca20239398c4b86b27c6a080d8345e1"); //访问密钥 String
tokenParam.put("client_id", clientId); // 客户端ID String
tokenParam.put("client_secret", clientSecret); //访问密钥 String
tokenParam.put("grant_type", "client_credentials"); //认证模式 String 目前仅支持client_credentials
String tokenResult = HttpUtils.sendPostMap(loginUrl, tokenParam, "");
JSONObject tokenObject = JSONObject.parseObject(tokenResult);
@ -67,10 +59,10 @@ public class SyncService {
System.out.println("Get MessageConsumer Success");
log.info("Get MessageConsumer Success");
} else {
System.out.println("Get MessageConsumer Error");
log.error("Get MessageConsumer Error");
String message = consumerObject.get("message").toString();
System.out.println(message);
log.error(message);
}
}
@ -93,6 +85,4 @@ public class SyncService {
ex.printStackTrace();
}
}
}

7
yxt-supervise-monitor-biz/src/main/resources/application-test.yml

@ -30,8 +30,11 @@ image:
scheduleTime:
cron: 0 59 * * * ?
# folder: D:\resources\download
folder: /root/huirong/monitor-java/imagesDownload
folder: D:\resources\download
haiKangConsumer:
clientId: c815549e939d45f7bea9b08255b936c8
clientSecret: dcab0bc5a43d44289349edf21dd4b800
# folder: /root/huirong/monitor-java/imagesDownload
websocket:
port: 19800
boss:

4
yxt-supervise-monitor-biz/src/main/resources/application.yml

@ -3,8 +3,8 @@ spring:
name: yxt-supervise-monitor
profiles:
# active: devv
# active: test
active: pro
active: test
# active: pro
messages:
# 国际化资源文件路径
basename: i18n/messages

Loading…
Cancel
Save