Commit 84155f7336c54acf10022c6cfccb3338a80c1b16

Authored by liujun001
1 parent 4fbdd51d

添加配置 用于调度系统

src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/Jt1078OfCarController.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.jt1078.platform;
  2 +
  3 +import com.alibaba.fastjson2.JSON;
  4 +import com.alibaba.fastjson2.JSONException;
  5 +import com.genersoft.iot.vmp.conf.MediaConfig;
  6 +import com.genersoft.iot.vmp.conf.UserSetting;
  7 +import com.genersoft.iot.vmp.conf.security.SecurityUtils;
  8 +import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
  9 +import com.genersoft.iot.vmp.service.IStreamPushService;
  10 +import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
  11 +import com.genersoft.iot.vmp.vmanager.jt1078.platform.ben.HttpClientPostEntity;
  12 +import com.genersoft.iot.vmp.vmanager.jt1078.platform.ben.TestEntity;
  13 +import com.genersoft.iot.vmp.vmanager.jt1078.platform.config.Jt1078ConfigBean;
  14 +import com.genersoft.iot.vmp.vmanager.jt1078.platform.config.RtspConfigBean;
  15 +import com.genersoft.iot.vmp.vmanager.jt1078.platform.config.TuohuaConfigBean;
  16 +import com.genersoft.iot.vmp.vmanager.jt1078.platform.handler.HttpClientUtil;
  17 +
  18 +import com.genersoft.iot.vmp.vmanager.streamPush.StreamPushController;
  19 +import com.sun.jna.platform.win32.Rasapi32Util;
  20 +import com.xiaoleilu.hutool.crypto.SecureUtil;
  21 +import com.xiaoleilu.hutool.crypto.asymmetric.KeyType;
  22 +import com.xiaoleilu.hutool.crypto.asymmetric.RSA;
  23 +import org.apache.commons.collections4.CollectionUtils;
  24 +import org.apache.commons.lang3.RandomUtils;
  25 +import org.apache.commons.lang3.StringUtils;
  26 +
  27 +import org.apache.http.client.CookieStore;
  28 +
  29 +import org.apache.http.cookie.Cookie;
  30 +import org.apache.logging.log4j.util.Base64Util;
  31 +import org.jetbrains.annotations.Nullable;
  32 +import org.slf4j.Logger;
  33 +import org.slf4j.LoggerFactory;
  34 +import org.springframework.beans.factory.annotation.Autowired;
  35 +import org.springframework.data.redis.core.RedisTemplate;
  36 +import org.springframework.util.Base64Utils;
  37 +import org.springframework.web.bind.annotation.*;
  38 +
  39 +import javax.crypto.Cipher;
  40 +import javax.servlet.http.HttpServletRequest;
  41 +import javax.xml.bind.DatatypeConverter;
  42 +import java.io.ByteArrayOutputStream;
  43 +import java.io.IOException;
  44 +import java.net.URISyntaxException;
  45 +import java.security.*;
  46 +import java.security.spec.InvalidKeySpecException;
  47 +import java.security.spec.X509EncodedKeySpec;
  48 +import java.text.MessageFormat;
  49 +import java.util.*;
  50 +import java.util.concurrent.TimeUnit;
  51 +
  52 +/**
  53 + * @author liujun
  54 + * @date 2024年10月21日 14:12
  55 + */
  56 +@RestController
  57 +@RequestMapping("/api/jt1078/query")
  58 +public class Jt1078OfCarController {
  59 + private static final Logger log = LoggerFactory.getLogger(Jt1078OfCarController.class);
  60 +
  61 +
  62 + @Autowired
  63 + private HttpClientUtil httpClientUtil;
  64 + @Autowired
  65 + private TuohuaConfigBean tuohuaConfigBean;
  66 + @Autowired
  67 + private RtspConfigBean rtspConfigBean;
  68 + @Autowired
  69 + private Jt1078ConfigBean jt1078ConfigBean;
  70 + @Autowired
  71 + private MediaConfig mediaConfig;
  72 + @Autowired
  73 + private StreamPushController streamPushController;
  74 +
  75 + @Autowired
  76 + private IStreamPushService streamPushService;
  77 +
  78 + private String jsessionid = null;
  79 +
  80 + @Autowired
  81 + private RedisTemplate<Object, Object> redisTemplate;
  82 +
  83 +
  84 + private static final long TIME_COUNT = 300000L;
  85 +
  86 +
  87 + private Date tokenDate;
  88 +
  89 +
  90 + @GetMapping("/company/tree")
  91 + public Map<String, Object> requestTreeOfCompany() {
  92 + Map<String, Object> resultMap = new HashMap<>();
  93 + try {
  94 + if (cookieTimeOut()) {
  95 + requestToken();
  96 + }
  97 +
  98 + HttpClientPostEntity clientPostEntity = httpClientUtil.doGet(tuohuaConfigBean.getCompanyURL(), jsessionid);
  99 + if (Objects.isNull(clientPostEntity)) {
  100 + resultMap.put("code", "-1");
  101 + resultMap.put("message", "请求错误,请联系管理员");
  102 + return resultMap;
  103 + }
  104 + resultMap.put("code", "1");
  105 + log.info(jsessionid + ";" + clientPostEntity.getResultStr());
  106 + HashMap<String, Object> hashMap = JSON.parseObject(clientPostEntity.getResultStr(), HashMap.class);
  107 + resultMap.put("result", hashMap.get("data"));
  108 + } catch (URISyntaxException | IOException | JSONException e) {
  109 + log.error("请求token异常", e);
  110 + resultMap.put("code", "-100");
  111 + resultMap.put("message", "请求错误,请联系管理员");
  112 + jsessionid = null;
  113 + }
  114 +
  115 + return resultMap;
  116 + }
  117 +
  118 + @GetMapping("/car/tree/{companyId}")
  119 + public Map<String, Object> requestTreeOfCarByCompanyId(@PathVariable String companyId) {
  120 + Map<String, Object> resultMap = new HashMap<>();
  121 + try {
  122 + if (cookieTimeOut()) {
  123 + requestToken();
  124 + }
  125 +
  126 + String url = MessageFormat.format(tuohuaConfigBean.getCompanyOfCarURL(), companyId);
  127 +
  128 + HttpClientPostEntity clientPostEntity = httpClientUtil.doGet(url, jsessionid);
  129 + if (Objects.isNull(clientPostEntity)) {
  130 + resultMap.put("code", "-1");
  131 + resultMap.put("message", "请求错误,请联系管理员");
  132 + return resultMap;
  133 + }
  134 +
  135 + // HashMap<String,Object> hashMap = JSON.parseObject(clientPostEntity.getResultStr(),HashMap.class);
  136 + resultMap.put("code", "1");
  137 + //resultMap.put("result", hashMap.get("data"));
  138 + resultMap.put("result", JSON.parseArray(clientPostEntity.getResultStr(), HashMap.class));
  139 + } catch (URISyntaxException | IOException | JSONException e) {
  140 + log.error("请求token异常", e);
  141 + resultMap.put("code", "-100");
  142 + resultMap.put("message", "请求错误,请联系管理员");
  143 + jsessionid = null;
  144 + }
  145 +
  146 + return resultMap;
  147 + }
  148 +
  149 + @GetMapping("/car/sim/{zbh}")
  150 + public Map<String, Object> requestSimple(@PathVariable String zbh) {
  151 + Map<String, Object> resultMap = new HashMap<>();
  152 + try {
  153 + if (cookieTimeOut()) {
  154 + requestToken();
  155 + }
  156 + String url = MessageFormat.format(tuohuaConfigBean.getSimURL(), zbh);
  157 + HttpClientPostEntity clientPostEntity = httpClientUtil.doGet(url, jsessionid);
  158 + if (Objects.isNull(clientPostEntity)) {
  159 + resultMap.put("code", "-1");
  160 + resultMap.put("message", "请求错误,请联系管理员");
  161 + return resultMap;
  162 + }
  163 +
  164 + HashMap<String, Object> hashMap = JSON.parseObject(clientPostEntity.getResultStr(), HashMap.class);
  165 + resultMap.put("code", "1");
  166 + resultMap.put("result", hashMap.get("sim"));
  167 +// resultMap.put("result", JSON.parseArray(clientPostEntity.getResultStr(),HashMap.class));
  168 + return resultMap;
  169 + } catch (URISyntaxException | IOException | JSONException e) {
  170 + log.error("请求token异常", e);
  171 + resultMap.put("code", "-100");
  172 + resultMap.put("message", "请求错误,请联系管理员");
  173 + jsessionid = null;
  174 + }
  175 + return resultMap;
  176 + }
  177 +
  178 + @GetMapping("/send/request/io/{sim}/{channel}")
  179 + public Map<String, Object> sendIORequest(@PathVariable String sim, @PathVariable String channel) {
  180 + Map<String, Object> resultMap = new HashMap<>();
  181 + if (StringUtils.isBlank(sim)) {
  182 + resultMap.put("code", "-100");
  183 + resultMap.put("message", "sim 不能为空");
  184 +
  185 + return resultMap;
  186 + }
  187 +
  188 + if (StringUtils.isBlank(channel)) {
  189 + resultMap.put("code", "-100");
  190 + resultMap.put("message", "channel 不能为空");
  191 +
  192 + return resultMap;
  193 + }
  194 + String msg = jt1078ConfigBean.formatMessageId(sim, channel, rtspConfigBean);
  195 +
  196 + String url = StringUtils.replace(jt1078ConfigBean.getJt1078Url(), "{0}", jt1078ConfigBean.getJt1078SendPort());
  197 + try {
  198 + //List<StreamPushItem> streamPushItems = streamPushService.getPushList(StringUtils.join(sim, "-", channel));
  199 + // int count = CollectionUtils.size(streamPushItems);
  200 + // if (count == 0) {
  201 + HttpClientPostEntity entity = httpClientUtil.doPost(url, msg, null);
  202 + log.info(entity.getResultStr());
  203 + //}
  204 +
  205 + resultMap.put("code", "1");
  206 + resultMap.put("message", "OK");
  207 +
  208 +
  209 + StreamContent streamContent = getStreamContent(StringUtils.join(sim, "-", channel));
  210 + resultMap.put("data", streamContent);
  211 +
  212 + return resultMap;
  213 + } catch (URISyntaxException | IOException | InterruptedException e) {
  214 + log.error("发送推流指令异常;[{}],[{}]", url, msg, e);
  215 +
  216 + resultMap.put("code", "-20");
  217 + resultMap.put("message", "发送推流指令异常");
  218 +
  219 + return resultMap;
  220 + }
  221 + }
  222 +
  223 +
  224 +
  225 +
  226 + @GetMapping("/send/stop/io/{sim}/{channel}")
  227 + public Map<String, Object> sendIORequestStop(@PathVariable String sim, @PathVariable String channel) {
  228 + Map<String, Object> resultMap = new HashMap<>();
  229 + if (StringUtils.isBlank(sim)) {
  230 + resultMap.put("code", "-100");
  231 + resultMap.put("message", "sim 不能为空");
  232 +
  233 + return resultMap;
  234 + }
  235 +
  236 + if (StringUtils.isBlank(channel)) {
  237 + resultMap.put("code", "-100");
  238 + resultMap.put("message", "channel 不能为空");
  239 +
  240 + return resultMap;
  241 + }
  242 +
  243 + String msg = jt1078ConfigBean.formatMessageStop(sim, channel);
  244 +
  245 +
  246 + String url = StringUtils.replace(jt1078ConfigBean.getJt1078Url(), "{0}", jt1078ConfigBean.getStopSendPort());
  247 + try {
  248 + List<StreamPushItem> streamPushItems = streamPushService.getPushList(StringUtils.join(sim, "-", channel));
  249 + int count = CollectionUtils.size(streamPushItems);
  250 + for (int i = 0; i < count; i++) {
  251 + StreamPushItem item = streamPushItems.get(i);
  252 + try {
  253 + streamPushService.stop(item.getApp(), item.getStream());
  254 + } catch (Exception e) {
  255 + log.error("推流停止失败,[{}]", item, e);
  256 + }
  257 +
  258 + }
  259 +
  260 + HttpClientPostEntity entity = httpClientUtil.doPost(url, msg, null);
  261 + if (Objects.isNull(entity)) {
  262 + log.info("HttpClientPostEntity is null");
  263 + } else {
  264 + log.info(entity.getResultStr());
  265 + }
  266 +
  267 +
  268 + resultMap.put("code", "1");
  269 + resultMap.put("message", "OK");
  270 +
  271 + return resultMap;
  272 + } catch (URISyntaxException | IOException e) {
  273 + log.error("发送停止推流指令异常;[{}],[{}]", url, msg, e);
  274 +
  275 + resultMap.put("code", "-20");
  276 + resultMap.put("message", "发送停止推流指令异常");
  277 + return resultMap;
  278 + }
  279 + }
  280 +
  281 + @GetMapping("/history/list/{sim}/{channel}/{startTime}/{endTime}")
  282 + public Map<String, Object> historyListOfSim(@PathVariable String sim, @PathVariable String channel, @PathVariable String startTime, @PathVariable String endTime) {
  283 + Map<String, Object> resultMap = new HashMap<>();
  284 + if (StringUtils.isBlank(sim)) {
  285 + resultMap.put("code", "-100");
  286 + resultMap.put("message", "sim 不能为空");
  287 +
  288 + return resultMap;
  289 + }
  290 +
  291 + if (StringUtils.isBlank(channel)) {
  292 + resultMap.put("code", "-100");
  293 + resultMap.put("message", "channel 不能为空");
  294 +
  295 + return resultMap;
  296 + }
  297 +
  298 + if (StringUtils.isBlank(startTime)) {
  299 + resultMap.put("code", "-100");
  300 + resultMap.put("message", "开始时间不能为空");
  301 +
  302 + return resultMap;
  303 + }
  304 +
  305 + if (StringUtils.isBlank(endTime)) {
  306 + resultMap.put("code", "-100");
  307 + resultMap.put("message", "结束时间不能为空");
  308 +
  309 + return resultMap;
  310 + }
  311 +
  312 + String url = StringUtils.replace(jt1078ConfigBean.getJt1078Url(), "{0}", jt1078ConfigBean.getHistoryListPort());
  313 + startTime = formatTime(startTime);
  314 + endTime = formatTime(endTime);
  315 +
  316 + String msg = jt1078ConfigBean.formatMessageHistoryListRTSP(sim, channel, startTime, endTime);
  317 +
  318 + try {
  319 + HttpClientPostEntity entity = httpClientUtil.doPost(url, msg, null);
  320 +
  321 + if (Objects.isNull(entity)) {
  322 + resultMap.put("code", "-1");
  323 + resultMap.put("message", "请求历史视频列表错误,请联系管理员");
  324 + return resultMap;
  325 + }
  326 +
  327 + HashMap<String, Object> hashMap = JSON.parseObject(entity.getResultStr(), HashMap.class);
  328 + resultMap.put("code", "1");
  329 + resultMap.put("obj", hashMap);
  330 +
  331 + return resultMap;
  332 + } catch (URISyntaxException e) {
  333 + log.error("发送获取历史视频指令异常;[{}],[{}]", url, msg, e);
  334 +
  335 + resultMap.put("code", "-20");
  336 + resultMap.put("message", "发送获取历史视频指令异常");
  337 + return resultMap;
  338 + } catch (IOException e) {
  339 + log.error("发送获取历史视频指令异常;[{}],[{}]", url, msg, e);
  340 +
  341 + resultMap.put("code", "-20");
  342 + resultMap.put("message", "发送获取历史视频指令异常");
  343 +
  344 + return resultMap;
  345 + }
  346 + }
  347 +
  348 +
  349 + @GetMapping("/send/request/io/history/{sim}/{channel}/{startTime}/{endTime}")
  350 + public Map<String, Object> sendIORequestOfHistory(@PathVariable String sim, @PathVariable String channel, @PathVariable String startTime, @PathVariable String endTime) {
  351 + Map<String, Object> resultMap = new HashMap<>();
  352 + if (StringUtils.isBlank(sim)) {
  353 + resultMap.put("code", "-100");
  354 + resultMap.put("message", "sim 不能为空");
  355 +
  356 + return resultMap;
  357 + }
  358 +
  359 + if (StringUtils.isBlank(channel)) {
  360 + resultMap.put("code", "-100");
  361 + resultMap.put("message", "channel 不能为空");
  362 +
  363 + return resultMap;
  364 + }
  365 +
  366 + if (StringUtils.isBlank(startTime)) {
  367 + resultMap.put("code", "-100");
  368 + resultMap.put("message", "开始时间不能为空");
  369 +
  370 + return resultMap;
  371 + }
  372 +
  373 + if (StringUtils.isBlank(endTime)) {
  374 + resultMap.put("code", "-100");
  375 + resultMap.put("message", "结束时间不能为空");
  376 +
  377 + return resultMap;
  378 + }
  379 + startTime = formatTime(startTime);
  380 + endTime = formatTime(endTime);
  381 +
  382 + String channelMapping = StringUtils.join(sim, "-", String.valueOf(System.currentTimeMillis()), "-", String.valueOf(RandomUtils.nextInt(1, 1000)));
  383 + String key = StringUtils.join(sim, "-", channel);
  384 + redisTemplate.opsForValue().set(key, channelMapping, 1, TimeUnit.HOURS);
  385 +
  386 + String msg = jt1078ConfigBean.formatMessageHistoryPlayRTSP(sim, channel, startTime, endTime, rtspConfigBean);
  387 +
  388 + log.info("msg:{}", msg);
  389 + String url = StringUtils.replace(jt1078ConfigBean.getJt1078Url(), "{0}", jt1078ConfigBean.getPlayHistoryPort());
  390 + try {
  391 + boolean flag = false;
  392 + HttpClientPostEntity entity = null;
  393 + key = key + "-lock";
  394 + int index = 0;
  395 + do {
  396 + index++;
  397 +
  398 + flag = redisTemplate.opsForValue().setIfAbsent(key, key, 100, TimeUnit.SECONDS);
  399 + if (flag) {
  400 + log.info("获取推流");
  401 + entity = httpClientUtil.doPost(url, msg, null);
  402 + }
  403 + Thread.sleep(1000);
  404 + if (index > 100) {
  405 + break;
  406 + }
  407 + } while (!flag);
  408 +
  409 + if (!flag) {
  410 + resultMap.put("code", "-20");
  411 + resultMap.put("message", "发送推流指令错误,请稍后再试");
  412 + return resultMap;
  413 + }
  414 + log.info(entity.getResultStr());
  415 +
  416 +
  417 + resultMap.put("code", "1");
  418 + resultMap.put("message", "OK");
  419 +
  420 + Thread.sleep(10000);
  421 +
  422 + StreamContent streamContent = getStreamContent("\"" + channelMapping + "\"");
  423 +
  424 + log.info("StreamContent:[{}]", streamContent);
  425 + resultMap.put("data", streamContent);
  426 +
  427 + return resultMap;
  428 + } catch (URISyntaxException | IOException e) {
  429 + log.error("发送推流指令异常;[{}],[{}]", url, msg, e);
  430 +
  431 + resultMap.put("code", "-20");
  432 + resultMap.put("message", "发送推流指令异常");
  433 +
  434 + return resultMap;
  435 + } catch (InterruptedException e) {
  436 + throw new RuntimeException(e);
  437 + }
  438 + }
  439 +
  440 +
  441 + @PostMapping("/test")
  442 + public String test(@RequestBody TestEntity test) {
  443 +
  444 + return "OK";
  445 + }
  446 +
  447 + @GetMapping("/test1")
  448 + public String test1(HttpServletRequest request) throws URISyntaxException, IOException {
  449 + jsessionid = StringUtils.join("JSESSIONID=", request.getParameter("jsessionid"));
  450 + return "OK";
  451 + }
  452 +
  453 + @Nullable
  454 + private StreamContent getStreamContent(String stream) throws InterruptedException {
  455 + StreamContent streamContent = null;
  456 + int index = 0;
  457 + do {
  458 + index++;
  459 + try {
  460 + streamContent = streamPushController.getPlayUrl("schedule", stream, mediaConfig.getId());
  461 + } catch (com.genersoft.iot.vmp.conf.exception.ControllerException e) {
  462 + log.info("获取播放地址失败:[{}],[{}]",stream,mediaConfig.getId());
  463 + }
  464 + if (Objects.nonNull(streamContent) && StringUtils.isNotEmpty(streamContent.getWs_flv())) {
  465 + break;
  466 + }
  467 + Thread.sleep(100);
  468 + } while (index < 1000);
  469 +
  470 + log.info("StreamContent:[{}]", streamContent);
  471 + return streamContent;
  472 + }
  473 +
  474 + private void requestToken() throws URISyntaxException, IOException {
  475 + HttpClientPostEntity entity = this.httpClientUtil.doGet(this.tuohuaConfigBean.getPageURL(), (String) null);
  476 + if (!Objects.isNull(entity)) {
  477 + if (!Objects.isNull(entity) && !Objects.isNull(entity.getResultStr())) {
  478 + HashMap<String, String> resultMap = (HashMap) JSON.parseObject(entity.getResultStr(), HashMap.class);
  479 + log.info("获取key:[{}]", resultMap.get("publickey"));
  480 + Map<String, String> params = new HashMap();
  481 + params.put("userName", encryptByPublicKey(this.tuohuaConfigBean.getUserName(), resultMap.get("publickey")));
  482 + params.put("password", encryptByPublicKey(this.tuohuaConfigBean.getPassword(), resultMap.get("publickey")));
  483 + HttpClientPostEntity postEntity = this.httpClientUtil.doPost(this.tuohuaConfigBean.getLoginURL(), params, (String) null);
  484 + if (Objects.nonNull(postEntity)) {
  485 + CookieStore tokenCookieStore = null;
  486 + tokenCookieStore = postEntity.getCookieStore();
  487 + if (Objects.nonNull(tokenCookieStore)) {
  488 + List<Cookie> cookies = tokenCookieStore.getCookies();
  489 + if (CollectionUtils.isNotEmpty(cookies)) {
  490 + Iterator var7 = cookies.iterator();
  491 +
  492 + while (var7.hasNext()) {
  493 + Cookie cookie = (Cookie) var7.next();
  494 + if (StringUtils.equalsIgnoreCase("jsessionid", cookie.getName()) && StringUtils.isNotBlank(cookie.getValue())) {
  495 + this.jsessionid = StringUtils.join(new String[]{"JSESSIONID=", cookie.getValue()});
  496 + break;
  497 + }
  498 + }
  499 + }
  500 + }
  501 +
  502 + this.tokenDate = new Date();
  503 + log.info("获取token:[{}]", this.jsessionid);
  504 + }
  505 +
  506 + }
  507 + }
  508 + }
  509 +
  510 + public static String encryptByPublicKey(String data, String publicKey) {
  511 + try {
  512 + String KEY_ALGORITHM = "RSA";
  513 + int MAX_ENCRYPT_BLOCK = 117;
  514 + byte[] keyBytes = Base64Utils.decode(publicKey.getBytes());
  515 + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
  516 + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
  517 + Key publicK = keyFactory.generatePublic(x509KeySpec);
  518 + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
  519 + cipher.init(1, publicK);
  520 + int inputLen = data.getBytes().length;
  521 + ByteArrayOutputStream out = new ByteArrayOutputStream();
  522 + int offSet = 0;
  523 +
  524 + for (int i = 0; inputLen - offSet > 0; offSet = i * MAX_ENCRYPT_BLOCK) {
  525 + byte[] cache;
  526 + if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
  527 + cache = cipher.doFinal(data.getBytes(), offSet, MAX_ENCRYPT_BLOCK);
  528 + } else {
  529 + cache = cipher.doFinal(data.getBytes(), offSet, inputLen - offSet);
  530 + }
  531 +
  532 + out.write(cache, 0, cache.length);
  533 + ++i;
  534 + }
  535 +
  536 + byte[] encryptedData = out.toByteArray();
  537 + out.close();
  538 + String var15 = new String(Base64Utils.encode(encryptedData));
  539 + return var15;
  540 + } catch (Exception var19) {
  541 + log.error("RSA 异常", var19);
  542 + } finally {
  543 +
  544 + }
  545 + return null;
  546 + }
  547 +
  548 + private boolean cookieTimeOut() {
  549 + if (!StringUtils.isEmpty(this.jsessionid) && !Objects.isNull(this.tokenDate)) {
  550 + Date now = new Date();
  551 + return now.getTime() - this.tokenDate.getTime() > 300000L;
  552 + } else {
  553 + return true;
  554 + }
  555 + }
  556 +
  557 + private String formatTime(String time) {
  558 + time = StringUtils.replace(time, "-", "");
  559 + time = StringUtils.replace(time, " ", "");
  560 + return StringUtils.replace(time, ":", "");
  561 + }
  562 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/ben/HttpClientPostEntity.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.jt1078.platform.ben;
  2 +
  3 +
  4 +import org.apache.http.client.CookieStore;
  5 +
  6 +import java.util.Map;
  7 +
  8 +/**
  9 + * @author liujun
  10 + * @date 2024年10月21日 15:20
  11 + */
  12 +
  13 +public class HttpClientPostEntity {
  14 + private String resultStr;
  15 + private Map<String, String> headers;
  16 + private CookieStore cookieStore;
  17 +
  18 + public String getResultStr() {
  19 + return resultStr;
  20 + }
  21 +
  22 + public void setResultStr(String resultStr) {
  23 + this.resultStr = resultStr;
  24 + }
  25 +
  26 + public Map<String, String> getHeaders() {
  27 + return headers;
  28 + }
  29 +
  30 + public void setHeaders(Map<String, String> headers) {
  31 + this.headers = headers;
  32 + }
  33 +
  34 + public CookieStore getCookieStore() {
  35 + return cookieStore;
  36 + }
  37 +
  38 + public void setCookieStore(CookieStore cookieStore) {
  39 + this.cookieStore = cookieStore;
  40 + }
  41 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/ben/TestEntity.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.jt1078.platform.ben;
  2 +
  3 +/**
  4 + * @author liujun
  5 + * @date 2024年10月23日 11:13
  6 + */
  7 +public class TestEntity {
  8 + private String messageId;
  9 + private String properties;
  10 + private String clientId;
  11 + private String serialNo;
  12 + private String ip;
  13 + private String tcpPort;
  14 + private String udpPort;
  15 + private String channelNo;
  16 + private String mediaType;
  17 + private String streamType;
  18 +
  19 + public String getMessageId() {
  20 + return messageId;
  21 + }
  22 +
  23 + public void setMessageId(String messageId) {
  24 + this.messageId = messageId;
  25 + }
  26 +
  27 + public String getProperties() {
  28 + return properties;
  29 + }
  30 +
  31 + public void setProperties(String properties) {
  32 + this.properties = properties;
  33 + }
  34 +
  35 + public String getClientId() {
  36 + return clientId;
  37 + }
  38 +
  39 + public void setClientId(String clientId) {
  40 + this.clientId = clientId;
  41 + }
  42 +
  43 + public String getSerialNo() {
  44 + return serialNo;
  45 + }
  46 +
  47 + public void setSerialNo(String serialNo) {
  48 + this.serialNo = serialNo;
  49 + }
  50 +
  51 + public String getIp() {
  52 + return ip;
  53 + }
  54 +
  55 + public void setIp(String ip) {
  56 + this.ip = ip;
  57 + }
  58 +
  59 + public String getTcpPort() {
  60 + return tcpPort;
  61 + }
  62 +
  63 + public void setTcpPort(String tcpPort) {
  64 + this.tcpPort = tcpPort;
  65 + }
  66 +
  67 + public String getUdpPort() {
  68 + return udpPort;
  69 + }
  70 +
  71 + public void setUdpPort(String udpPort) {
  72 + this.udpPort = udpPort;
  73 + }
  74 +
  75 + public String getChannelNo() {
  76 + return channelNo;
  77 + }
  78 +
  79 + public void setChannelNo(String channelNo) {
  80 + this.channelNo = channelNo;
  81 + }
  82 +
  83 + public String getMediaType() {
  84 + return mediaType;
  85 + }
  86 +
  87 + public void setMediaType(String mediaType) {
  88 + this.mediaType = mediaType;
  89 + }
  90 +
  91 + public String getStreamType() {
  92 + return streamType;
  93 + }
  94 +
  95 + public void setStreamType(String streamType) {
  96 + this.streamType = streamType;
  97 + }
  98 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/config/HttpConfigBean.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.jt1078.platform.config;
  2 +
  3 +import org.springframework.stereotype.Component;
  4 +
  5 +/**
  6 + * @author liujun
  7 + * @date 2024年10月23日 15:04
  8 + */
  9 +@Component
  10 +public class HttpConfigBean {
  11 +
  12 + private String mediaIp;
  13 + private String mediaPort;
  14 + private String sdpIp;
  15 + private String sdpPort;
  16 +
  17 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/config/Jt1078ConfigBean.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.jt1078.platform.config;
  2 +
  3 +import org.apache.commons.lang3.StringUtils;
  4 +import org.springframework.beans.factory.annotation.Value;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +/**
  8 + * @author liujun
  9 + * @date 2024年10月23日 13:38
  10 + */
  11 +@Component
  12 +public class Jt1078ConfigBean {
  13 + @Value("${tuohua.bsth.jt1078.url}")
  14 + private String jt1078Url;
  15 + @Value("${tuohua.bsth.jt1078.sendPort}")
  16 + private String jt1078SendPort;
  17 + @Value("${tuohua.bsth.jt1078.stopSendPort}")
  18 + private String stopSendPort;
  19 + @Value("${tuohua.bsth.jt1078.historyListPort}")
  20 + private String historyListPort;
  21 + @Value("${tuohua.bsth.jt1078.playHistoryPort}")
  22 + private String playHistoryPort;
  23 +
  24 +
  25 + private static final String SEND_IO_MESSAGE_RTSP = "{ \"messageId\": 37121, \"properties\": 0, \"clientId\": \"{clientId}\", \"serialNo\": \"1\", \"ip\": \"{ip}\", \"tcpPort\": \"{tcpPort}\", \"udpPort\": \"{udpPort}\", \"channelNo\": \"{channelNo}\", \"mediaType\": \"1\", \"streamType\": \"1\"}";
  26 + private static final String SEND_IO_MESSAGE_RTSP_STOP = "{\"messageId\": 37122,\"properties\": 0,\"clientId\": \"{clientId}\",\"serialNo\": \"1\",\"channelNo\": \"{channelNo}\",\"command\": \"0\",\"closeType\": \"0\",\"streamType\": \"1\"}";
  27 + private static final String SEND_IO_HISTORY_RTSP = "{\"msgid\":37381,\"clientId\":\"{clientId}\",\"startTime\":\"{startTime}\",\"endTime\":\"{endTime}\",\"mediaType\":0,\"streamType\":0,\"storageType\":0,\"channelId\":{channelNo}}";
  28 + private static final String SEND_IO_PLAY_RTSP = "{\"ip\":\"{ip}\",\"tcpPort\":{tcpPort},\"udpPort\":{udpPort},\"channelNo\":\"{channelNo}\",\"mediaType\":0,\"streamType\":0,\"storageType\":0,\"playbackType\":0,\"playbackSpeed\":1,\"startTime\":\"{startTime}\",\"endTime\":\"{endTime}\",\"clientId\":\"{sim}\",\"messageId\":37377}";
  29 +
  30 + public String formatMessageId(String sim, String channel, RtspConfigBean configBean) {
  31 + String msg = StringUtils.replace(SEND_IO_MESSAGE_RTSP, "{clientId}", sim);
  32 + msg = StringUtils.replace(msg, "{tcpPort}", configBean.getRtspTcpPort());
  33 + msg = StringUtils.replace(msg, "{udpPort}", configBean.getRtspUdpPort());
  34 + msg = StringUtils.replace(msg, "{channelNo}", channel);
  35 + return StringUtils.replace(msg, "{ip}", configBean.getRtspIp());
  36 + }
  37 +
  38 + public String formatMessageStop(String sim, String channel) {
  39 + String msg = StringUtils.replace(SEND_IO_MESSAGE_RTSP_STOP, "{clientId}", sim);
  40 + return StringUtils.replace(msg, "{channelNo}", channel);
  41 + }
  42 +
  43 + public String formatMessageHistoryListRTSP(String sim, String channel, String startTime, String endTime) {
  44 + String msg = StringUtils.replace(SEND_IO_HISTORY_RTSP, "{clientId}", sim);
  45 + msg = StringUtils.replace(msg, "{startTime}", startTime);
  46 + msg = StringUtils.replace(msg, "{endTime}", endTime);
  47 + return StringUtils.replace(msg, "{channelNo}", channel);
  48 + }
  49 +
  50 + public String formatMessageHistoryPlayRTSP(String sim, String channel, String startTime, String endTime, RtspConfigBean configBean) {
  51 + String msg = StringUtils.replace(SEND_IO_PLAY_RTSP, "{clientId}", sim);
  52 + msg = StringUtils.replace(msg, "{startTime}", startTime);
  53 + msg = StringUtils.replace(msg, "{endTime}", endTime);
  54 + msg = StringUtils.replace(msg, "{channelNo}", channel);
  55 + msg = StringUtils.replace(msg, "{tcpPort}", configBean.getHistoryTcpPort());
  56 + msg = StringUtils.replace(msg, "{udpPort}", configBean.getHistoryUdpPort());
  57 + msg = StringUtils.replace(msg, "{sim}", sim);
  58 + return StringUtils.replace(msg, "{ip}", configBean.getRtspIp());
  59 + }
  60 +
  61 + public String getJt1078Url() {
  62 + return jt1078Url;
  63 + }
  64 +
  65 + public String getJt1078SendPort() {
  66 + return jt1078SendPort;
  67 + }
  68 +
  69 + public String getStopSendPort() {
  70 + return stopSendPort;
  71 + }
  72 +
  73 + public String getHistoryListPort() {
  74 + return historyListPort;
  75 + }
  76 +
  77 + public String getPlayHistoryPort() {
  78 + return playHistoryPort;
  79 + }
  80 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/config/RtspConfigBean.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.jt1078.platform.config;
  2 +
  3 +import org.springframework.beans.factory.annotation.Value;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +/**
  7 + * @author liujun
  8 + * @date 2024年10月23日 13:36
  9 + */
  10 +@Component
  11 +public class RtspConfigBean {
  12 +
  13 + @Value("${tuohua.bsth.wvp28181.rtsp.tcpPort}")
  14 + private String rtspTcpPort;
  15 + @Value("${tuohua.bsth.wvp28181.rtsp.udpPort}")
  16 + private String rtspUdpPort;
  17 + @Value("${tuohua.bsth.wvp28181.rtsp.ip}")
  18 + private String rtspIp;
  19 +
  20 + @Value("${tuohua.bsth.wvp28181.rtsp.historyTcpPort}")
  21 + private String historyTcpPort;
  22 + @Value("${tuohua.bsth.wvp28181.rtsp.historyUdpPort}")
  23 + private String historyUdpPort;
  24 +
  25 +
  26 +
  27 + public String getRtspTcpPort() {
  28 + return rtspTcpPort;
  29 + }
  30 +
  31 + public String getRtspUdpPort() {
  32 + return rtspUdpPort;
  33 + }
  34 +
  35 + public String getRtspIp() {
  36 + return rtspIp;
  37 + }
  38 +
  39 + public String getHistoryTcpPort() {
  40 + return historyTcpPort;
  41 + }
  42 +
  43 + public String getHistoryUdpPort() {
  44 + return historyUdpPort;
  45 + }
  46 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/config/TuohuaConfigBean.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.jt1078.platform.config;
  2 +
  3 +import org.springframework.beans.factory.annotation.Value;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +/**
  7 + * @author liujun
  8 + * @date 2024年10月23日 13:34
  9 + */
  10 +@Component
  11 +public class TuohuaConfigBean {
  12 +
  13 + @Value("${tuohua.bsth.login.userName}")
  14 + private String userName;
  15 +
  16 + @Value("${tuohua.bsth.login.password}")
  17 + private String password;
  18 +
  19 + @Value("${tuohua.bsth.login.url}")
  20 + private String loginURL;
  21 + @Value("${tuohua.bsth.login.pageURL}")
  22 + private String pageURL;
  23 +
  24 + @Value("${tuohua.bsth.tree.url.company}")
  25 + private String companyURL;
  26 +
  27 + @Value("${tuohua.bsth.tree.url.car}")
  28 + private String companyOfCarURL;
  29 + @Value("${tuohua.bsth.tree.url.sim}")
  30 + private String simURL;
  31 +
  32 +
  33 + public String getUserName() {
  34 + return userName;
  35 + }
  36 +
  37 + public String getPassword() {
  38 + return password;
  39 + }
  40 +
  41 + public String getLoginURL() {
  42 + return loginURL;
  43 + }
  44 +
  45 + public String getPageURL() {
  46 + return pageURL;
  47 + }
  48 +
  49 + public String getCompanyURL() {
  50 + return companyURL;
  51 + }
  52 +
  53 + public String getCompanyOfCarURL() {
  54 + return companyOfCarURL;
  55 + }
  56 +
  57 + public String getSimURL() {
  58 + return simURL;
  59 + }
  60 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/handler/HttpClientUtil.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.jt1078.platform.handler;
  2 +
  3 +import com.genersoft.iot.vmp.vmanager.jt1078.platform.ben.HttpClientPostEntity;
  4 +import org.apache.commons.collections4.CollectionUtils;
  5 +import org.apache.http.HttpEntity;
  6 +import org.apache.http.NameValuePair;
  7 +import org.apache.http.client.CookieStore;
  8 +import org.apache.http.client.entity.UrlEncodedFormEntity;
  9 +import org.apache.http.client.methods.CloseableHttpResponse;
  10 +import org.apache.http.client.methods.HttpGet;
  11 +import org.apache.http.client.methods.HttpPost;
  12 +import org.apache.http.client.utils.URIBuilder;
  13 +import org.apache.http.entity.StringEntity;
  14 +import org.apache.http.impl.client.BasicCookieStore;
  15 +import org.apache.http.impl.client.DefaultHttpClient;
  16 +import org.apache.http.impl.cookie.BasicClientCookie;
  17 +import org.apache.http.message.BasicNameValuePair;
  18 +import org.apache.http.util.EntityUtils;
  19 +import org.jetbrains.annotations.NotNull;
  20 +import org.slf4j.Logger;
  21 +import org.slf4j.LoggerFactory;
  22 +import org.springframework.stereotype.Component;
  23 +
  24 +import java.io.IOException;
  25 +import java.net.URI;
  26 +import java.net.URISyntaxException;
  27 +import java.util.*;
  28 +
  29 +/**
  30 + * @author liujun
  31 + * @date 2024年10月23日 13:25
  32 + */
  33 +@Component
  34 +public class HttpClientUtil {
  35 + private static final Logger log = LoggerFactory.getLogger(HttpClientUtil.class);
  36 +
  37 + public HttpClientPostEntity doPost(String url, Map<String, String> params, String jsessionid) throws URISyntaxException, IOException {
  38 + // 创建Httpclient对象
  39 + DefaultHttpClient httpclient = new DefaultHttpClient();
  40 + // 定义请求的参数
  41 + CookieStore cookieStore1 = combationCookie(jsessionid);
  42 + httpclient.setCookieStore(cookieStore1);
  43 + URIBuilder uriBuilder = new URIBuilder(url);
  44 + URI uri = uriBuilder.build();
  45 +
  46 + // 创建http GET请求
  47 + HttpPost httpPost = new HttpPost(uri);
  48 + List<NameValuePair> paramList = new ArrayList<>();
  49 + if (params != null && params.size() > 0) {
  50 + Set<String> keySet = params.keySet();
  51 + for (String key : keySet) {
  52 + paramList.add(new BasicNameValuePair(key, params.get(key)));
  53 + }
  54 + httpPost.setEntity(new UrlEncodedFormEntity(paramList));
  55 + }
  56 +
  57 + //response 对象
  58 + CloseableHttpResponse response = null;
  59 + try {
  60 + // 执行http get请求
  61 + response = httpclient.execute(httpPost);
  62 + // 判断返回状态是否为200
  63 + if (response.getStatusLine().getStatusCode() == 200) {
  64 + return combationReturnObj(response, httpclient);
  65 + }
  66 + } finally {
  67 + if (response != null) {
  68 + response.close();
  69 + }
  70 + httpclient.close();
  71 + }
  72 + return null;
  73 + }
  74 +
  75 + public HttpClientPostEntity doPost(String url, String requestBody, String jsessionid) throws URISyntaxException, IOException {
  76 + // 创建Httpclient对象
  77 + DefaultHttpClient httpclient = new DefaultHttpClient();
  78 + // 定义请求的参数
  79 + CookieStore cookieStore1 = combationCookie( jsessionid);
  80 +
  81 + httpclient.setCookieStore(cookieStore1);
  82 +
  83 + URIBuilder uriBuilder = new URIBuilder(url);
  84 + URI uri = uriBuilder.build();
  85 +
  86 + // 创建http GET请求
  87 + HttpPost httpPost = new HttpPost(uri);
  88 + StringEntity stringEntity = new StringEntity(requestBody, "UTF-8");
  89 + stringEntity.setContentType("application/json");
  90 + httpPost.setEntity(stringEntity);
  91 +
  92 + //response 对象
  93 + CloseableHttpResponse response = null;
  94 + try {
  95 + // 执行http get请求
  96 + response = httpclient.execute(httpPost);
  97 + // 判断返回状态是否为200
  98 + if (response.getStatusLine().getStatusCode() == 200) {
  99 + return combationReturnObj(response, httpclient);
  100 + }
  101 + } catch (Exception e) {
  102 + log.error("请求数据异常", e);
  103 + } finally {
  104 + if (response != null) {
  105 + response.close();
  106 + }
  107 + httpclient.close();
  108 + }
  109 + return null;
  110 + }
  111 +
  112 +
  113 + public CookieStore combationCookie(String jsessionid) {
  114 + CookieStore cookieStore1 = new BasicCookieStore();
  115 + // cookieStore1.addCookie(new BasicClientCookie("SECKEY_ABVK", seckeyAbvk));
  116 + // cookieStore1.addCookie(new BasicClientCookie("BMAP_SECKEY", bmapSeckey));
  117 + cookieStore1.addCookie(new BasicClientCookie("JSESSIONID", jsessionid));
  118 +
  119 + CookieStore cookieStore = new BasicCookieStore();
  120 +
  121 + int size = CollectionUtils.size(cookieStore.getCookies());
  122 + for (int i = 0; i < size; i++) {
  123 + cookieStore1.addCookie(cookieStore.getCookies().get(i));
  124 +
  125 + }
  126 + return cookieStore1;
  127 + }
  128 +
  129 + public HttpClientPostEntity doGet(String url, String jsessionid) throws URISyntaxException, IOException {
  130 + // 创建Httpclient对象
  131 + DefaultHttpClient httpclient = new DefaultHttpClient();
  132 + // 定义请求的参数
  133 + CookieStore cookieStore1 = combationCookie(jsessionid);
  134 +//
  135 +// httpclient.setCookieStore(cookieStore1);
  136 +
  137 + URIBuilder uriBuilder = new URIBuilder(url);
  138 + URI uri = uriBuilder.build();
  139 +
  140 + // 创建http GET请求
  141 + HttpGet httpGet = new HttpGet(uri);
  142 + httpGet.addHeader("Cookie", jsessionid);
  143 +
  144 + //response 对象
  145 + CloseableHttpResponse response = null;
  146 + try {
  147 + // 执行http get请求
  148 + response = httpclient.execute(httpGet);
  149 + // 判断返回状态是否为200
  150 + if (response.getStatusLine().getStatusCode() == 200) {
  151 + return combationReturnObj(response, httpclient);
  152 + }
  153 + } finally {
  154 + if (response != null) {
  155 + response.close();
  156 + }
  157 + httpclient.close();
  158 + }
  159 + return null;
  160 + }
  161 +
  162 +
  163 + @NotNull
  164 + private static HttpClientPostEntity combationReturnObj(CloseableHttpResponse response, DefaultHttpClient httpclient) throws IOException {
  165 + HttpEntity httpEntity = response.getEntity();
  166 +
  167 + CookieStore cookieStore = httpclient.getCookieStore();
  168 + String result = EntityUtils.toString(httpEntity, "UTF-8");
  169 +
  170 + HttpClientPostEntity postEntity = new HttpClientPostEntity();
  171 + postEntity.setCookieStore(cookieStore);
  172 + postEntity.setResultStr(result);
  173 + log.info("response data:{}",result);
  174 + return postEntity;
  175 + }
  176 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/handler/RtspHandler.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.jt1078.platform.handler;
  2 +
  3 +import org.springframework.beans.factory.annotation.Value;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +/**
  7 + * @author liujun
  8 + * @date 2024年10月23日 13:24
  9 + */
  10 +@Component
  11 +public class RtspHandler {
  12 +
  13 +}
... ...