From b5508ccb67bfcbfdb6131baf3f1abf2e6dac7c6c Mon Sep 17 00:00:00 2001 From: yangzongjia Date: Tue, 15 Aug 2023 16:59:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B5=B7=E5=BA=B7=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitor/biz/callpolice/CallRest.java | 13 +++++-- .../monitor/biz/scheduled/SyncService.java | 34 +++++++------------ .../src/main/resources/application-test.yml | 7 ++-- .../src/main/resources/application.yml | 4 +-- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/callpolice/CallRest.java b/yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/callpolice/CallRest.java index a7bd8ca..b2da2f9 100644 --- a/yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/callpolice/CallRest.java +++ b/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 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 param = new HashMap<>(); + Map param = new HashMap<>(); String result = HttpUtils.sendGet(url, "35ad3e80-1de4-4477-827e-0473320cf644"); return result; } diff --git a/yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/scheduled/SyncService.java b/yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/scheduled/SyncService.java index 524700d..ae76c20 100644 --- a/yxt-supervise-monitor-biz/src/main/java/com/yxt/supervise/monitor/biz/scheduled/SyncService.java +++ b/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 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(); } } - - } diff --git a/yxt-supervise-monitor-biz/src/main/resources/application-test.yml b/yxt-supervise-monitor-biz/src/main/resources/application-test.yml index 9abc3a0..1925e21 100644 --- a/yxt-supervise-monitor-biz/src/main/resources/application-test.yml +++ b/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: diff --git a/yxt-supervise-monitor-biz/src/main/resources/application.yml b/yxt-supervise-monitor-biz/src/main/resources/application.yml index 96da28a..3b6ecea 100644 --- a/yxt-supervise-monitor-biz/src/main/resources/application.yml +++ b/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