Commit 9d73b7f8968df92487b58ef2d4786a6bc1884376
1 parent
130441e4
添加1078视频
Showing
9 changed files
with
1243 additions
and
0 deletions
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.JSONArray; | |
| 5 | +import com.alibaba.fastjson2.JSONException; | |
| 6 | +import com.genersoft.iot.vmp.conf.MediaConfig; | |
| 7 | +import com.genersoft.iot.vmp.conf.UserSetting; | |
| 8 | +import com.genersoft.iot.vmp.conf.security.SecurityUtils; | |
| 9 | +import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | |
| 10 | +import com.genersoft.iot.vmp.service.IStreamPushService; | |
| 11 | +import com.genersoft.iot.vmp.vmanager.bean.StreamContent; | |
| 12 | +import com.genersoft.iot.vmp.vmanager.jt1078.platform.ben.HttpClientPostEntity; | |
| 13 | +import com.genersoft.iot.vmp.vmanager.jt1078.platform.ben.TestEntity; | |
| 14 | +import com.genersoft.iot.vmp.vmanager.jt1078.platform.config.Jt1078ConfigBean; | |
| 15 | +import com.genersoft.iot.vmp.vmanager.jt1078.platform.config.RtspConfigBean; | |
| 16 | +import com.genersoft.iot.vmp.vmanager.jt1078.platform.config.TuohuaConfigBean; | |
| 17 | +import com.genersoft.iot.vmp.vmanager.jt1078.platform.handler.HttpClientUtil; | |
| 18 | + | |
| 19 | +import com.genersoft.iot.vmp.vmanager.streamPush.StreamPushController; | |
| 20 | +import com.sun.jna.platform.win32.Rasapi32Util; | |
| 21 | +import com.xiaoleilu.hutool.crypto.SecureUtil; | |
| 22 | +import com.xiaoleilu.hutool.crypto.asymmetric.KeyType; | |
| 23 | +import com.xiaoleilu.hutool.crypto.asymmetric.RSA; | |
| 24 | +import org.apache.commons.collections4.CollectionUtils; | |
| 25 | +import org.apache.commons.lang3.RandomStringUtils; | |
| 26 | +import org.apache.commons.lang3.StringUtils; | |
| 27 | + | |
| 28 | +import org.apache.http.client.CookieStore; | |
| 29 | + | |
| 30 | +import org.apache.http.cookie.Cookie; | |
| 31 | +import org.apache.logging.log4j.util.Base64Util; | |
| 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.stream.Collectors; | |
| 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 | + | |
| 79 | + // @Value("${tuohua.bsth.login.JSESSIONID}") | |
| 80 | + private String jsessionid = null; | |
| 81 | + | |
| 82 | + | |
| 83 | + private static final long TIME_COUNT = 300000L; | |
| 84 | + | |
| 85 | + private static final String CHARS = "ABCDEFGHIJKLMPQRSTUVWXYZabcdefghijkmpqrstuvwxyz123456789"; | |
| 86 | + | |
| 87 | + | |
| 88 | + private Date tokenDate; | |
| 89 | + | |
| 90 | + | |
| 91 | + @GetMapping("/company/tree") | |
| 92 | + public Map<String, Object> requestTreeOfCompany() { | |
| 93 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 94 | + try { | |
| 95 | + if (cookieTimeOut()) { | |
| 96 | + requestToken(); | |
| 97 | + } | |
| 98 | + | |
| 99 | + HttpClientPostEntity clientPostEntity = httpClientUtil.doGet(tuohuaConfigBean.getCompanyURL(), jsessionid); | |
| 100 | + if (Objects.isNull(clientPostEntity)) { | |
| 101 | + resultMap.put("code", "-1"); | |
| 102 | + resultMap.put("message", "请求错误,请联系管理员"); | |
| 103 | + return resultMap; | |
| 104 | + } | |
| 105 | + resultMap.put("code", "1"); | |
| 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异常,[{}]", jsessionid, e); | |
| 110 | + resultMap.put("code", "-100"); | |
| 111 | + resultMap.put("message", "请求错误,请联系管理员"); | |
| 112 | + } | |
| 113 | + | |
| 114 | + return resultMap; | |
| 115 | + } | |
| 116 | + | |
| 117 | + @GetMapping("/car/tree/{companyId}") | |
| 118 | + public Map<String, Object> requestTreeOfCarByCompanyId(@PathVariable String companyId) { | |
| 119 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 120 | + try { | |
| 121 | + if (cookieTimeOut()) { | |
| 122 | + requestToken(); | |
| 123 | + } | |
| 124 | + | |
| 125 | + String url = MessageFormat.format(tuohuaConfigBean.getCompanyOfCarURL(), companyId); | |
| 126 | + | |
| 127 | + HttpClientPostEntity clientPostEntity = httpClientUtil.doGet(url, jsessionid); | |
| 128 | + if (Objects.isNull(clientPostEntity)) { | |
| 129 | + resultMap.put("code", "-1"); | |
| 130 | + resultMap.put("message", "请求错误,请联系管理员"); | |
| 131 | + return resultMap; | |
| 132 | + } | |
| 133 | + | |
| 134 | + // HashMap<String,Object> hashMap = JSON.parseObject(clientPostEntity.getResultStr(),HashMap.class); | |
| 135 | + resultMap.put("code", "1"); | |
| 136 | + //resultMap.put("result", hashMap.get("data")); | |
| 137 | + resultMap.put("result", JSON.parseArray(clientPostEntity.getResultStr(), HashMap.class)); | |
| 138 | + } catch (URISyntaxException | IOException | JSONException e) { | |
| 139 | + log.error("请求token异常", e); | |
| 140 | + resultMap.put("code", "-100"); | |
| 141 | + resultMap.put("message", "请求错误,请联系管理员"); | |
| 142 | + } | |
| 143 | + | |
| 144 | + return resultMap; | |
| 145 | + } | |
| 146 | + | |
| 147 | + @GetMapping("/car/sim/{zbh}") | |
| 148 | + public Map<String, Object> requestSimple(@PathVariable String zbh) { | |
| 149 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 150 | + try { | |
| 151 | + if (cookieTimeOut()) { | |
| 152 | + requestToken(); | |
| 153 | + } | |
| 154 | + String url = MessageFormat.format(tuohuaConfigBean.getSimURL(), zbh); | |
| 155 | + HttpClientPostEntity clientPostEntity = httpClientUtil.doGet(url, jsessionid); | |
| 156 | + | |
| 157 | + if (Objects.isNull(clientPostEntity)) { | |
| 158 | + resultMap.put("code", "-1"); | |
| 159 | + resultMap.put("message", "请求错误,请联系管理员"); | |
| 160 | + return resultMap; | |
| 161 | + } | |
| 162 | + | |
| 163 | + HashMap<String, Object> hashMap = JSON.parseObject(clientPostEntity.getResultStr(), HashMap.class); | |
| 164 | + resultMap.put("code", "1"); | |
| 165 | + resultMap.put("result", hashMap.get("sim")); | |
| 166 | +// resultMap.put("result", JSON.parseArray(clientPostEntity.getResultStr(),HashMap.class)); | |
| 167 | + return resultMap; | |
| 168 | + } catch (URISyntaxException | IOException | JSONException e) { | |
| 169 | + log.error("请求token异常", e); | |
| 170 | + resultMap.put("code", "-100"); | |
| 171 | + resultMap.put("message", "请求错误,请联系管理员"); | |
| 172 | + } | |
| 173 | + return resultMap; | |
| 174 | + } | |
| 175 | + | |
| 176 | +// @GetMapping("/car/gps/{zbh}") | |
| 177 | +// public Map<String, Object> getCarGPS(@PathVariable String zbh) { | |
| 178 | +// Map<String, Object> resultMap = new HashMap<>(); | |
| 179 | +// | |
| 180 | +// try { | |
| 181 | +// | |
| 182 | +// if (StringUtils.isBlank(zbh)) { | |
| 183 | +// resultMap.put("code", "-100"); | |
| 184 | +// resultMap.put("message", "车辆自编号 不能为空"); | |
| 185 | +// | |
| 186 | +// return resultMap; | |
| 187 | +// } | |
| 188 | +// | |
| 189 | +// HttpClientPostEntity entity = queryGPS(); | |
| 190 | +// if (Objects.isNull(entity) || StringUtils.isBlank(entity.getResultStr())) { | |
| 191 | +// resultMap.put("code", "-200"); | |
| 192 | +// resultMap.put("message", "请求GPS错误,请联系管理员"); | |
| 193 | +// return resultMap; | |
| 194 | +// } | |
| 195 | +// | |
| 196 | +// List<HashMap> gpsList = JSON.parseArray(entity.getResultStr(), HashMap.class); | |
| 197 | +// if (CollectionUtils.isEmpty(gpsList)) { | |
| 198 | +// resultMap.put("code", "-201"); | |
| 199 | +// resultMap.put("message", "请求GPS错误,请联系管理员"); | |
| 200 | +// } | |
| 201 | +// | |
| 202 | +// gpsList = gpsList.stream().filter(h -> Objects.equals(h.get("lineId"), zbh)).collect(Collectors.toList()); | |
| 203 | +// resultMap.put("code", "1"); | |
| 204 | +// resultMap.put("result", gpsList); | |
| 205 | +// | |
| 206 | +// return resultMap; | |
| 207 | +// } catch (URISyntaxException | IOException e) { | |
| 208 | +// log.error("请求GPS数据异常", e); | |
| 209 | +// resultMap.put("code", "-100"); | |
| 210 | +// resultMap.put("message", "请求GPS错误,请联系管理员"); | |
| 211 | +// return resultMap; | |
| 212 | +// } | |
| 213 | +// } | |
| 214 | + | |
| 215 | +// @GetMapping("/car/gps/all") | |
| 216 | +// public Map<String, Object> getGPSAll(){ | |
| 217 | +// Map<String, Object> resultMap = new HashMap<>(); | |
| 218 | +// try { | |
| 219 | +// HttpClientPostEntity entity = queryGPS(); | |
| 220 | +// if (Objects.isNull(entity) || StringUtils.isBlank(entity.getResultStr())) { | |
| 221 | +// resultMap.put("code", "-200"); | |
| 222 | +// resultMap.put("message", "请求GPS错误,请联系管理员"); | |
| 223 | +// return resultMap; | |
| 224 | +// } | |
| 225 | +// | |
| 226 | +// List<HashMap> gpsList = JSON.parseArray(entity.getResultStr(), HashMap.class); | |
| 227 | +// if (CollectionUtils.isEmpty(gpsList)) { | |
| 228 | +// resultMap.put("code", "-201"); | |
| 229 | +// resultMap.put("message", "请求GPS错误,请联系管理员"); | |
| 230 | +// } | |
| 231 | +// | |
| 232 | +// resultMap.put("code", "1"); | |
| 233 | +// resultMap.put("result", gpsList); | |
| 234 | +// | |
| 235 | +// return resultMap; | |
| 236 | +// } catch (URISyntaxException | IOException e) { | |
| 237 | +// log.error("请求GPS数据异常", e); | |
| 238 | +// resultMap.put("code", "-100"); | |
| 239 | +// resultMap.put("message", "请求GPS错误,请联系管理员"); | |
| 240 | +// return resultMap; | |
| 241 | +// } | |
| 242 | +// } | |
| 243 | + | |
| 244 | + @GetMapping("/send/request/io/{sim}/{channel}") | |
| 245 | + public Map<String, Object> sendIORequest(@PathVariable String sim, @PathVariable String channel) { | |
| 246 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 247 | + if (StringUtils.isBlank(sim)) { | |
| 248 | + resultMap.put("code", "-100"); | |
| 249 | + resultMap.put("message", "sim 不能为空"); | |
| 250 | + | |
| 251 | + return resultMap; | |
| 252 | + } | |
| 253 | + | |
| 254 | + if (StringUtils.isBlank(channel)) { | |
| 255 | + resultMap.put("code", "-100"); | |
| 256 | + resultMap.put("message", "channel 不能为空"); | |
| 257 | + | |
| 258 | + return resultMap; | |
| 259 | + } | |
| 260 | + String msg = jt1078ConfigBean.formatMessageId(sim, channel, rtspConfigBean); | |
| 261 | + | |
| 262 | + String url = StringUtils.replace(jt1078ConfigBean.getJt1078Url(), "{0}", jt1078ConfigBean.getJt1078SendPort()); | |
| 263 | + try { | |
| 264 | + List<StreamPushItem> streamPushItems = streamPushService.getPushList(StringUtils.join(sim, "-", channel)); | |
| 265 | + int count = CollectionUtils.size(streamPushItems); | |
| 266 | + if (count == 0) { | |
| 267 | + HttpClientPostEntity entity = httpClientUtil.doPost(url, msg, null); | |
| 268 | + Map<String, Object> sendMap = switchSendDataResult(entity); | |
| 269 | + if (Objects.nonNull(sendMap)) { | |
| 270 | + return sendMap; | |
| 271 | + } | |
| 272 | + } | |
| 273 | + | |
| 274 | + log.info("StreamPushItem count :[{}]", count); | |
| 275 | + | |
| 276 | + resultMap.put("code", "1"); | |
| 277 | + resultMap.put("message", "OK"); | |
| 278 | + | |
| 279 | + StreamContent streamContent = streamPushController.getPlayUrl("schedule", StringUtils.join(sim, "-", channel), mediaConfig.getId()); | |
| 280 | + log.info("StreamContent:[{}]", streamContent); | |
| 281 | + resultMap.put("data", streamContent); | |
| 282 | + | |
| 283 | + return resultMap; | |
| 284 | + } catch (URISyntaxException | IOException | InterruptedException e) { | |
| 285 | + log.error("发送推流指令异常;[{}],[{}]", url, msg, e); | |
| 286 | + | |
| 287 | + resultMap.put("code", "-20"); | |
| 288 | + resultMap.put("message", "发送推流指令异常"); | |
| 289 | + | |
| 290 | + return resultMap; | |
| 291 | + } | |
| 292 | + } | |
| 293 | + | |
| 294 | + | |
| 295 | + @GetMapping("/send/stop/io/{sim}/{channel}") | |
| 296 | + public Map<String, Object> sendIORequestStop(@PathVariable String sim, @PathVariable String channel) { | |
| 297 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 298 | + if (StringUtils.isBlank(sim)) { | |
| 299 | + resultMap.put("code", "-100"); | |
| 300 | + resultMap.put("message", "sim 不能为空"); | |
| 301 | + | |
| 302 | + return resultMap; | |
| 303 | + } | |
| 304 | + | |
| 305 | + if (StringUtils.isBlank(channel)) { | |
| 306 | + resultMap.put("code", "-100"); | |
| 307 | + resultMap.put("message", "channel 不能为空"); | |
| 308 | + | |
| 309 | + return resultMap; | |
| 310 | + } | |
| 311 | + | |
| 312 | + log.info("stop channel:[{}],[{}]", sim, channel); | |
| 313 | + | |
| 314 | + String msg = jt1078ConfigBean.formatMessageStop(sim, channel); | |
| 315 | + | |
| 316 | + | |
| 317 | + String url = StringUtils.replace(jt1078ConfigBean.getJt1078Url(), "{0}", jt1078ConfigBean.getStopSendPort()); | |
| 318 | + try { | |
| 319 | + HttpClientPostEntity entity = httpClientUtil.doPost(url, msg, null); | |
| 320 | + | |
| 321 | + List<StreamPushItem> streamPushItems = streamPushService.getPushList(StringUtils.join(sim, "-", channel)); | |
| 322 | + int count = CollectionUtils.size(streamPushItems); | |
| 323 | + for (int i = 0; i < count; i++) { | |
| 324 | + StreamPushItem item = streamPushItems.get(i); | |
| 325 | + try { | |
| 326 | + streamPushService.stop(item.getApp(), item.getStream()); | |
| 327 | + } catch (Exception e) { | |
| 328 | + log.error("推流停止失败,[{}]", item, e); | |
| 329 | + } | |
| 330 | + | |
| 331 | + } | |
| 332 | + | |
| 333 | + Map<String, Object> sendMap = switchSendDataResult(entity); | |
| 334 | + if (Objects.nonNull(sendMap)) { | |
| 335 | + return sendMap; | |
| 336 | + } | |
| 337 | + | |
| 338 | + resultMap.put("code", "1"); | |
| 339 | + resultMap.put("message", "OK"); | |
| 340 | + | |
| 341 | + return resultMap; | |
| 342 | + } catch (URISyntaxException | IOException | InterruptedException e) { | |
| 343 | + log.error("发送停止推流指令异常;[{}],[{}]", url, msg, e); | |
| 344 | + | |
| 345 | + resultMap.put("code", "-20"); | |
| 346 | + resultMap.put("message", "发送停止推流指令异常"); | |
| 347 | + return resultMap; | |
| 348 | + } | |
| 349 | + } | |
| 350 | + | |
| 351 | + @GetMapping("/history/list/{sim}/{channel}/{startTime}/{endTime}") | |
| 352 | + public Map<String, Object> historyListOfSim(@PathVariable String sim, @PathVariable String channel, @PathVariable String startTime, @PathVariable String endTime) { | |
| 353 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 354 | + if (StringUtils.isBlank(sim)) { | |
| 355 | + resultMap.put("code", "-100"); | |
| 356 | + resultMap.put("message", "sim 不能为空"); | |
| 357 | + | |
| 358 | + return resultMap; | |
| 359 | + } | |
| 360 | + | |
| 361 | + if (StringUtils.isBlank(channel)) { | |
| 362 | + resultMap.put("code", "-100"); | |
| 363 | + resultMap.put("message", "channel 不能为空"); | |
| 364 | + | |
| 365 | + return resultMap; | |
| 366 | + } | |
| 367 | + | |
| 368 | + if (StringUtils.isBlank(startTime)) { | |
| 369 | + resultMap.put("code", "-100"); | |
| 370 | + resultMap.put("message", "开始时间不能为空"); | |
| 371 | + | |
| 372 | + return resultMap; | |
| 373 | + } | |
| 374 | + | |
| 375 | + if (StringUtils.isBlank(endTime)) { | |
| 376 | + resultMap.put("code", "-100"); | |
| 377 | + resultMap.put("message", "结束时间不能为空"); | |
| 378 | + | |
| 379 | + return resultMap; | |
| 380 | + } | |
| 381 | + | |
| 382 | + startTime = jt1078ConfigBean.formatDateStr(startTime); | |
| 383 | + endTime = jt1078ConfigBean.formatDateStr(endTime); | |
| 384 | + | |
| 385 | + String url = StringUtils.replace(jt1078ConfigBean.getJt1078Url(), "{0}", jt1078ConfigBean.getHistoryListPort()); | |
| 386 | + String msg = jt1078ConfigBean.formatMessageHistoryListRTSP(sim, channel, startTime, endTime); | |
| 387 | + | |
| 388 | + try { | |
| 389 | + HttpClientPostEntity entity = httpClientUtil.doPost(url, msg, null); | |
| 390 | + | |
| 391 | + Map<String, Object> sendMap = switchSendDataResult(entity); | |
| 392 | + if (Objects.nonNull(sendMap)) { | |
| 393 | + return sendMap; | |
| 394 | + } | |
| 395 | + | |
| 396 | + HashMap<String, Object> hashMap = JSON.parseObject(entity.getResultStr(), HashMap.class); | |
| 397 | + resultMap.put("code", "1"); | |
| 398 | + resultMap.put("obj", hashMap); | |
| 399 | + | |
| 400 | + | |
| 401 | + return resultMap; | |
| 402 | + } catch (URISyntaxException e) { | |
| 403 | + log.error("发送获取历史视频指令异常;[{}],[{}]", url, msg, e); | |
| 404 | + | |
| 405 | + resultMap.put("code", "-20"); | |
| 406 | + resultMap.put("message", "发送获取历史视频指令异常"); | |
| 407 | + return resultMap; | |
| 408 | + } catch (IOException | InterruptedException e) { | |
| 409 | + log.error("发送获取历史视频指令异常;[{}],[{}]", url, msg, e); | |
| 410 | + | |
| 411 | + resultMap.put("code", "-20"); | |
| 412 | + resultMap.put("message", "发送获取历史视频指令异常"); | |
| 413 | + | |
| 414 | + return resultMap; | |
| 415 | + } | |
| 416 | + } | |
| 417 | + | |
| 418 | + | |
| 419 | + @GetMapping("/send/request/io/history/{sim}/{channel}/{startTime}/{endTime}") | |
| 420 | + public Map<String, Object> sendIORequestOfHistory(@PathVariable String sim, @PathVariable String channel, @PathVariable String startTime, @PathVariable String endTime) { | |
| 421 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 422 | + if (StringUtils.isBlank(sim)) { | |
| 423 | + resultMap.put("code", "-100"); | |
| 424 | + resultMap.put("message", "sim 不能为空"); | |
| 425 | + | |
| 426 | + return resultMap; | |
| 427 | + } | |
| 428 | + | |
| 429 | + if (StringUtils.isBlank(channel)) { | |
| 430 | + resultMap.put("code", "-100"); | |
| 431 | + resultMap.put("message", "channel 不能为空"); | |
| 432 | + | |
| 433 | + return resultMap; | |
| 434 | + } | |
| 435 | + | |
| 436 | + if (StringUtils.isBlank(startTime)) { | |
| 437 | + resultMap.put("code", "-100"); | |
| 438 | + resultMap.put("message", "开始时间不能为空"); | |
| 439 | + | |
| 440 | + return resultMap; | |
| 441 | + } | |
| 442 | + | |
| 443 | + if (StringUtils.isBlank(endTime)) { | |
| 444 | + resultMap.put("code", "-100"); | |
| 445 | + resultMap.put("message", "结束时间不能为空"); | |
| 446 | + | |
| 447 | + return resultMap; | |
| 448 | + } | |
| 449 | + startTime = jt1078ConfigBean.formatDateStr(startTime); | |
| 450 | + endTime = jt1078ConfigBean.formatDateStr(endTime); | |
| 451 | + | |
| 452 | + String msg = jt1078ConfigBean.formatMessageHistoryPlayRTSP(sim, channel, startTime, endTime, rtspConfigBean); | |
| 453 | + | |
| 454 | + String url = StringUtils.replace(jt1078ConfigBean.getJt1078Url(), "{0}", jt1078ConfigBean.getHistoryPlayPort()); | |
| 455 | + try { | |
| 456 | + List<StreamPushItem> streamPushItems = streamPushService.getPushList(StringUtils.join(sim, "-", channel)); | |
| 457 | + int count = CollectionUtils.size(streamPushItems); | |
| 458 | + if (count == 0) { | |
| 459 | + HttpClientPostEntity entity = httpClientUtil.doPost(url, msg, null); | |
| 460 | + Map<String, Object> sendMap = switchSendDataResult(entity); | |
| 461 | + if (Objects.nonNull(sendMap)) { | |
| 462 | + return sendMap; | |
| 463 | + } | |
| 464 | + } | |
| 465 | + | |
| 466 | + resultMap.put("code", "1"); | |
| 467 | + resultMap.put("message", "OK"); | |
| 468 | + | |
| 469 | + StreamContent streamContent = streamPushController.getPlayUrl("schedule", StringUtils.join(sim, "-", channel), mediaConfig.getId()); | |
| 470 | + log.info("StreamContent:[{}]", streamContent); | |
| 471 | + resultMap.put("data", streamContent); | |
| 472 | + | |
| 473 | + return resultMap; | |
| 474 | + } catch (URISyntaxException | IOException | InterruptedException e) { | |
| 475 | + log.error("发送推流指令异常;[{}],[{}]", url, msg, e); | |
| 476 | + | |
| 477 | + resultMap.put("code", "-20"); | |
| 478 | + resultMap.put("message", "发送推流指令异常"); | |
| 479 | + | |
| 480 | + return resultMap; | |
| 481 | + } | |
| 482 | + } | |
| 483 | + | |
| 484 | + | |
| 485 | + @GetMapping("/jsessionid") | |
| 486 | + public String test1(HttpServletRequest request) throws URISyntaxException, IOException { | |
| 487 | + jsessionid = StringUtils.join("JSESSIONID=", request.getParameter("jsessionid")); | |
| 488 | + return "OK"; | |
| 489 | + } | |
| 490 | + | |
| 491 | + private Map<String, Object> switchSendDataResult(HttpClientPostEntity entity) throws InterruptedException { | |
| 492 | + Thread.sleep(6000); | |
| 493 | + if (Objects.isNull(entity) || StringUtils.isBlank(entity.getResultStr())) { | |
| 494 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 495 | + resultMap.put("code", "-300"); | |
| 496 | + resultMap.put("message", "操作推流错误,请稍后再试"); | |
| 497 | + return resultMap; | |
| 498 | + } | |
| 499 | + log.info("send data result:[{}]", entity.getResultStr()); | |
| 500 | + | |
| 501 | + HashMap<String, Object> hashMap = JSON.parseObject(entity.getResultStr(), HashMap.class); | |
| 502 | + | |
| 503 | + if (Objects.equals(200, hashMap.get("code")) || StringUtils.equals("200", String.valueOf(hashMap.get("code")))) { | |
| 504 | + return null; | |
| 505 | + } | |
| 506 | + | |
| 507 | + String msg = String.valueOf(hashMap.get("msg")); | |
| 508 | + | |
| 509 | + if (Objects.isNull(hashMap.get("msg")) || StringUtils.isBlank(msg)) { | |
| 510 | + msg = "操作推流错误,请稍后再试"; | |
| 511 | + } | |
| 512 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 513 | + resultMap.put("code", "-301"); | |
| 514 | + resultMap.put("message", msg); | |
| 515 | + return resultMap; | |
| 516 | + } | |
| 517 | + | |
| 518 | +// private HttpClientPostEntity queryGPS() throws URISyntaxException, IOException { | |
| 519 | +// String time = String.valueOf((new Date()).getTime()); | |
| 520 | +//// String nonce = RandomStringUtils.random(6, 144, 172, false, false); | |
| 521 | +// String nonce = RandomStringUtils.random(6,CHARS); | |
| 522 | +// | |
| 523 | +// Map<String, String> map = new HashMap<String, String>(); | |
| 524 | +// map.put("timestamp", time);//时间戳 | |
| 525 | +// map.put("nonce", nonce);//随机字符串 | |
| 526 | +// map.put("password", tuohuaConfigBean.getGpsPassword());//密码 | |
| 527 | +// String sign = tuohuaConfigBean.getSHA1(map); | |
| 528 | +// String url = tuohuaConfigBean.formatGPSURL(null, time, nonce, tuohuaConfigBean.getGpsPassword(), sign); | |
| 529 | +// | |
| 530 | +// | |
| 531 | +// return httpClientUtil.doGet(url, null); | |
| 532 | +// | |
| 533 | +// | |
| 534 | +// } | |
| 535 | + | |
| 536 | + private void requestToken() throws URISyntaxException, IOException { | |
| 537 | + | |
| 538 | + | |
| 539 | + HttpClientPostEntity entity = httpClientUtil.doGet(tuohuaConfigBean.getPageURL(), null); | |
| 540 | + if (Objects.isNull(entity)) { | |
| 541 | + return; | |
| 542 | + } | |
| 543 | + if (Objects.isNull(entity) || Objects.isNull(entity.getResultStr())) { | |
| 544 | + return; | |
| 545 | + } | |
| 546 | + | |
| 547 | +// String key = new String(Base64Utils.decode(entity.getResultStr().getBytes())); | |
| 548 | + | |
| 549 | + HashMap<String, String> resultMap = JSON.parseObject(entity.getResultStr(), HashMap.class); | |
| 550 | + log.info("获取key:[{}]", resultMap.get("publickey")); | |
| 551 | + | |
| 552 | + Map<String, String> params = new HashMap<>(); | |
| 553 | + params.put("userName", encryptByPublicKey(tuohuaConfigBean.getUserName(), resultMap.get("publickey"))); | |
| 554 | + params.put("password", encryptByPublicKey(tuohuaConfigBean.getPassword(), resultMap.get("publickey"))); | |
| 555 | + | |
| 556 | + HttpClientPostEntity postEntity = httpClientUtil.doPost(tuohuaConfigBean.getLoginURL(), params, null); | |
| 557 | + if (Objects.nonNull(postEntity)) { | |
| 558 | + CookieStore tokenCookieStore = null; | |
| 559 | + tokenCookieStore = postEntity.getCookieStore(); | |
| 560 | + if (Objects.nonNull(tokenCookieStore)) { | |
| 561 | + List<Cookie> cookies = tokenCookieStore.getCookies(); | |
| 562 | + if (CollectionUtils.isNotEmpty(cookies)) { | |
| 563 | + for (Cookie cookie : cookies) { | |
| 564 | + if (StringUtils.equalsIgnoreCase("jsessionid", cookie.getName()) && StringUtils.isNotBlank(cookie.getValue())) { | |
| 565 | + jsessionid = StringUtils.join("JSESSIONID=", cookie.getValue()); | |
| 566 | + break; | |
| 567 | + } | |
| 568 | + } | |
| 569 | + | |
| 570 | + } | |
| 571 | + } | |
| 572 | + tokenDate = new Date(); | |
| 573 | + log.info("获取token:[{}]", jsessionid); | |
| 574 | + } | |
| 575 | + } | |
| 576 | + | |
| 577 | + | |
| 578 | + /** */ | |
| 579 | + /** | |
| 580 | + * <p> | |
| 581 | + * 公钥加密 | |
| 582 | + * </p> | |
| 583 | + * | |
| 584 | + * @param data 源数据 | |
| 585 | + * @param publicKey 公钥(BASE64编码) | |
| 586 | + * @return | |
| 587 | + * @throws Exception | |
| 588 | + */ | |
| 589 | + public static String encryptByPublicKey(String data, String publicKey) { | |
| 590 | + try { | |
| 591 | + String KEY_ALGORITHM = "RSA"; | |
| 592 | + int MAX_ENCRYPT_BLOCK = 117; | |
| 593 | + | |
| 594 | + byte[] keyBytes = Base64Utils.decode(publicKey.getBytes()); | |
| 595 | + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); | |
| 596 | + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); | |
| 597 | + Key publicK = keyFactory.generatePublic(x509KeySpec); | |
| 598 | + // 对数据加密 | |
| 599 | + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); | |
| 600 | + cipher.init(Cipher.ENCRYPT_MODE, publicK); | |
| 601 | + int inputLen = data.getBytes().length; | |
| 602 | + ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
| 603 | + int offSet = 0; | |
| 604 | + byte[] cache; | |
| 605 | + int i = 0; | |
| 606 | + // 对数据分段加密 | |
| 607 | + while (inputLen - offSet > 0) { | |
| 608 | + if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { | |
| 609 | + cache = cipher.doFinal(data.getBytes(), offSet, MAX_ENCRYPT_BLOCK); | |
| 610 | + } else { | |
| 611 | + cache = cipher.doFinal(data.getBytes(), offSet, inputLen - offSet); | |
| 612 | + } | |
| 613 | + out.write(cache, 0, cache.length); | |
| 614 | + i++; | |
| 615 | + offSet = i * MAX_ENCRYPT_BLOCK; | |
| 616 | + } | |
| 617 | + byte[] encryptedData = out.toByteArray(); | |
| 618 | + out.close(); | |
| 619 | + return new String(org.springframework.util.Base64Utils.encode(encryptedData)); | |
| 620 | + } catch (Exception e) { | |
| 621 | + | |
| 622 | + } finally { | |
| 623 | + | |
| 624 | + } | |
| 625 | + return null; | |
| 626 | + | |
| 627 | + } | |
| 628 | + | |
| 629 | + private boolean cookieTimeOut() { | |
| 630 | + if (StringUtils.isEmpty(jsessionid) || Objects.isNull(tokenDate)) { | |
| 631 | + return true; | |
| 632 | + } | |
| 633 | + | |
| 634 | + Date now = new Date(); | |
| 635 | + return now.getTime() - tokenDate.getTime() > TIME_COUNT; | |
| 636 | + | |
| 637 | + } | |
| 638 | +} | ... | ... |
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.historyPlayPort}") | |
| 22 | + private String historyPlayPort; | |
| 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\":\"{clientId}\",\"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.getRtspTcpPort()); | |
| 56 | + msg = StringUtils.replace(msg, "{udpPort}", configBean.getRtspUdpPort()); | |
| 57 | + return StringUtils.replace(msg, "{ip}", configBean.getRtspIp()); | |
| 58 | + } | |
| 59 | + | |
| 60 | + public String formatDateStr(String dateStr){ | |
| 61 | + dateStr = StringUtils.replace(dateStr,"-",""); | |
| 62 | + dateStr = StringUtils.replace(dateStr,":",""); | |
| 63 | + return StringUtils.replace(dateStr," ",""); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public String getJt1078Url() { | |
| 67 | + return jt1078Url; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public String getJt1078SendPort() { | |
| 71 | + return jt1078SendPort; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public String getStopSendPort() { | |
| 75 | + return stopSendPort; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public String getHistoryListPort() { | |
| 79 | + return historyListPort; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public String getHistoryPlayPort() { | |
| 83 | + return historyPlayPort; | |
| 84 | + } | |
| 85 | +} | ... | ... |
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 | + | |
| 21 | + | |
| 22 | + public String getRtspTcpPort() { | |
| 23 | + return rtspTcpPort; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public String getRtspUdpPort() { | |
| 27 | + return rtspUdpPort; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public String getRtspIp() { | |
| 31 | + return rtspIp; | |
| 32 | + } | |
| 33 | + | |
| 34 | +} | ... | ... |
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.apache.commons.lang3.ArrayUtils; | |
| 4 | +import org.apache.commons.lang3.StringUtils; | |
| 5 | +import org.springframework.beans.factory.annotation.Value; | |
| 6 | +import org.springframework.stereotype.Component; | |
| 7 | + | |
| 8 | +import java.security.MessageDigest; | |
| 9 | +import java.util.Arrays; | |
| 10 | +import java.util.Map; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * @author liujun | |
| 14 | + * @date 2024年10月23日 13:34 | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class TuohuaConfigBean { | |
| 18 | + | |
| 19 | + @Value("${tuohua.bsth.login.userName}") | |
| 20 | + private String userName; | |
| 21 | + | |
| 22 | + @Value("${tuohua.bsth.login.password}") | |
| 23 | + private String password; | |
| 24 | + | |
| 25 | + @Value("${tuohua.bsth.login.url}") | |
| 26 | + private String loginURL; | |
| 27 | + @Value("${tuohua.bsth.login.pageURL}") | |
| 28 | + private String pageURL; | |
| 29 | + | |
| 30 | + @Value("${tuohua.bsth.tree.url.company}") | |
| 31 | + private String companyURL; | |
| 32 | + | |
| 33 | + @Value("${tuohua.bsth.tree.url.car}") | |
| 34 | + private String companyOfCarURL; | |
| 35 | + @Value("${tuohua.bsth.tree.url.sim}") | |
| 36 | + private String simURL; | |
| 37 | + | |
| 38 | +// @Value("${tuohua.bsth.login.gpsPassword}") | |
| 39 | +// private String gpsPassword; | |
| 40 | +// | |
| 41 | +// @Value("${tuohua.bsth.login.gpsURL}") | |
| 42 | +// private String gpsURL; | |
| 43 | + | |
| 44 | + | |
| 45 | + public String getUserName() { | |
| 46 | + return userName; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public String getPassword() { | |
| 50 | + return password; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public String getLoginURL() { | |
| 54 | + return loginURL; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public String getPageURL() { | |
| 58 | + return pageURL; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public String getCompanyURL() { | |
| 62 | + return companyURL; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public String getCompanyOfCarURL() { | |
| 66 | + return companyOfCarURL; | |
| 67 | + } | |
| 68 | + | |
| 69 | + public String getSimURL() { | |
| 70 | + return simURL; | |
| 71 | + } | |
| 72 | + | |
| 73 | +// public String getGpsPassword() { | |
| 74 | +// return gpsPassword; | |
| 75 | +// } | |
| 76 | +// | |
| 77 | +// public String getGpsURL() { | |
| 78 | +// return gpsURL; | |
| 79 | +// } | |
| 80 | + | |
| 81 | +// public String formatGPSURL(String deviceId, String timestamp, String nonce, String password, String sign) { | |
| 82 | +// String[] searchStrings = {"{deviceId}", "{time}", "{nonce}", "{password}", "{sign}"}; | |
| 83 | +// String[] replacements = {null, timestamp, nonce, password,sign}; | |
| 84 | +// return replaceValues(getGpsURL(), searchStrings, replacements); | |
| 85 | +// } | |
| 86 | + | |
| 87 | + private String replaceValues(String str, String[] searchStrings, String[] replacements) { | |
| 88 | + if (StringUtils.isBlank(str)) { | |
| 89 | + return str; | |
| 90 | + } | |
| 91 | + int searchLen = ArrayUtils.getLength(searchStrings); | |
| 92 | + int replaceLen = ArrayUtils.getLength(replacements); | |
| 93 | + if (searchLen != replaceLen) { | |
| 94 | + throw new RuntimeException("searchLen no equest replaceLen"); | |
| 95 | + } | |
| 96 | + for (int i = 0; i < searchLen; i++) { | |
| 97 | + str = StringUtils.replace(str, searchStrings[i], replacements[i]); | |
| 98 | + } | |
| 99 | + return str; | |
| 100 | + } | |
| 101 | + | |
| 102 | + public String getSHA1(Map<String, String> map) { | |
| 103 | + try { | |
| 104 | + String[] array = new String[map.size()]; | |
| 105 | + map.values().toArray(array); | |
| 106 | + StringBuffer sb = new StringBuffer(); | |
| 107 | + // 字符串排序 | |
| 108 | + Arrays.sort(array); | |
| 109 | + for (int i = 0; i < array.length; i++) { | |
| 110 | + sb.append(array[i]); | |
| 111 | + } | |
| 112 | + String str = sb.toString(); | |
| 113 | + // SHA1签名生成 | |
| 114 | + MessageDigest md = MessageDigest.getInstance("SHA-1"); | |
| 115 | + md.update(str.getBytes()); | |
| 116 | + byte[] digest = md.digest(); | |
| 117 | + StringBuffer hexstr = new StringBuffer(); | |
| 118 | + String shaHex = ""; | |
| 119 | + for (int i = 0; i < digest.length; i++) { | |
| 120 | + shaHex = Integer.toHexString(digest[i] & 0xFF); | |
| 121 | + if (shaHex.length() < 2) { | |
| 122 | + hexstr.append(0); | |
| 123 | + } | |
| 124 | + hexstr.append(shaHex); | |
| 125 | + } | |
| 126 | + return hexstr.toString(); | |
| 127 | + } catch (Exception e) { | |
| 128 | + throw new RuntimeException(e); | |
| 129 | + } | |
| 130 | + } | |
| 131 | +} | ... | ... |
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.params.BasicHttpParams; | |
| 19 | +import org.apache.http.params.HttpConnectionParams; | |
| 20 | +import org.apache.http.util.EntityUtils; | |
| 21 | +import org.jetbrains.annotations.NotNull; | |
| 22 | +import org.slf4j.Logger; | |
| 23 | +import org.slf4j.LoggerFactory; | |
| 24 | +import org.springframework.stereotype.Component; | |
| 25 | + | |
| 26 | +import java.io.IOException; | |
| 27 | +import java.net.URI; | |
| 28 | +import java.net.URISyntaxException; | |
| 29 | +import java.util.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * @author liujun | |
| 33 | + * @date 2024年10月23日 13:25 | |
| 34 | + */ | |
| 35 | +@Component | |
| 36 | +public class HttpClientUtil { | |
| 37 | + private static final Logger log = LoggerFactory.getLogger(HttpClientUtil.class); | |
| 38 | + | |
| 39 | + public HttpClientPostEntity doPost(String url, Map<String, String> params, String jsessionid) throws URISyntaxException, IOException { | |
| 40 | + // 创建Httpclient对象 | |
| 41 | + DefaultHttpClient httpclient = createDefaultHttpClient(); | |
| 42 | + // 定义请求的参数 | |
| 43 | + CookieStore cookieStore1 = combationCookie(jsessionid); | |
| 44 | + httpclient.setCookieStore(cookieStore1); | |
| 45 | + URIBuilder uriBuilder = new URIBuilder(url); | |
| 46 | + URI uri = uriBuilder.build(); | |
| 47 | + | |
| 48 | + // 创建http GET请求 | |
| 49 | + HttpPost httpPost = new HttpPost(uri); | |
| 50 | + List<NameValuePair> paramList = new ArrayList<>(); | |
| 51 | + if (params != null && params.size() > 0) { | |
| 52 | + Set<String> keySet = params.keySet(); | |
| 53 | + for (String key : keySet) { | |
| 54 | + paramList.add(new BasicNameValuePair(key, params.get(key))); | |
| 55 | + } | |
| 56 | + httpPost.setEntity(new UrlEncodedFormEntity(paramList)); | |
| 57 | + } | |
| 58 | + | |
| 59 | + //response 对象 | |
| 60 | + CloseableHttpResponse response = null; | |
| 61 | + try { | |
| 62 | + // 执行http get请求 | |
| 63 | + response = httpclient.execute(httpPost); | |
| 64 | + // 判断返回状态是否为200 | |
| 65 | + if (response.getStatusLine().getStatusCode() == 200) { | |
| 66 | + return combationReturnObj(response, httpclient); | |
| 67 | + } | |
| 68 | + } finally { | |
| 69 | + if (response != null) { | |
| 70 | + response.close(); | |
| 71 | + } | |
| 72 | + httpclient.close(); | |
| 73 | + } | |
| 74 | + return null; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public HttpClientPostEntity doPost(String url, String requestBody, String jsessionid) throws URISyntaxException, IOException { | |
| 78 | + | |
| 79 | + // 创建Httpclient对象 | |
| 80 | + DefaultHttpClient httpclient = createDefaultHttpClient(); | |
| 81 | + // 定义请求的参数 | |
| 82 | + CookieStore cookieStore1 = combationCookie( jsessionid); | |
| 83 | + | |
| 84 | + httpclient.setCookieStore(cookieStore1); | |
| 85 | + | |
| 86 | + URIBuilder uriBuilder = new URIBuilder(url); | |
| 87 | + URI uri = uriBuilder.build(); | |
| 88 | + | |
| 89 | + // 创建http GET请求 | |
| 90 | + HttpPost httpPost = new HttpPost(uri); | |
| 91 | + StringEntity stringEntity = new StringEntity(requestBody, "UTF-8"); | |
| 92 | + stringEntity.setContentType("application/json"); | |
| 93 | + httpPost.setEntity(stringEntity); | |
| 94 | + | |
| 95 | + //response 对象 | |
| 96 | + CloseableHttpResponse response = null; | |
| 97 | + try { | |
| 98 | + // 执行http get请求 | |
| 99 | + response = httpclient.execute(httpPost); | |
| 100 | + // 判断返回状态是否为200 | |
| 101 | + if (response.getStatusLine().getStatusCode() == 200) { | |
| 102 | + return combationReturnObj(response, httpclient); | |
| 103 | + } | |
| 104 | + } catch (Exception e) { | |
| 105 | + log.error("请求数据异常", e); | |
| 106 | + } finally { | |
| 107 | + if (response != null) { | |
| 108 | + response.close(); | |
| 109 | + } | |
| 110 | + httpclient.close(); | |
| 111 | + } | |
| 112 | + return null; | |
| 113 | + } | |
| 114 | + | |
| 115 | + | |
| 116 | + public CookieStore combationCookie(String jsessionid) { | |
| 117 | + CookieStore cookieStore1 = new BasicCookieStore(); | |
| 118 | + // cookieStore1.addCookie(new BasicClientCookie("SECKEY_ABVK", seckeyAbvk)); | |
| 119 | + // cookieStore1.addCookie(new BasicClientCookie("BMAP_SECKEY", bmapSeckey)); | |
| 120 | + cookieStore1.addCookie(new BasicClientCookie("JSESSIONID", jsessionid)); | |
| 121 | + | |
| 122 | + CookieStore cookieStore = new BasicCookieStore(); | |
| 123 | + | |
| 124 | + int size = CollectionUtils.size(cookieStore.getCookies()); | |
| 125 | + for (int i = 0; i < size; i++) { | |
| 126 | + cookieStore1.addCookie(cookieStore.getCookies().get(i)); | |
| 127 | + | |
| 128 | + } | |
| 129 | + return cookieStore1; | |
| 130 | + } | |
| 131 | + | |
| 132 | + public HttpClientPostEntity doGet(String url, String jsessionid) throws URISyntaxException, IOException { | |
| 133 | + // 创建Httpclient对象 | |
| 134 | + DefaultHttpClient httpclient = createDefaultHttpClient(); | |
| 135 | + // 定义请求的参数 | |
| 136 | + CookieStore cookieStore1 = combationCookie(jsessionid); | |
| 137 | +// | |
| 138 | +// httpclient.setCookieStore(cookieStore1); | |
| 139 | + | |
| 140 | + URIBuilder uriBuilder = new URIBuilder(url); | |
| 141 | + URI uri = uriBuilder.build(); | |
| 142 | + | |
| 143 | + // 创建http GET请求 | |
| 144 | + HttpGet httpGet = new HttpGet(uri); | |
| 145 | + httpGet.addHeader("Cookie", jsessionid); | |
| 146 | + | |
| 147 | + //response 对象 | |
| 148 | + CloseableHttpResponse response = null; | |
| 149 | + try { | |
| 150 | + // 执行http get请求 | |
| 151 | + response = httpclient.execute(httpGet); | |
| 152 | + // 判断返回状态是否为200 | |
| 153 | + if (response.getStatusLine().getStatusCode() == 200) { | |
| 154 | + return combationReturnObj(response, httpclient); | |
| 155 | + } | |
| 156 | + } finally { | |
| 157 | + if (response != null) { | |
| 158 | + response.close(); | |
| 159 | + } | |
| 160 | + httpclient.close(); | |
| 161 | + } | |
| 162 | + return null; | |
| 163 | + } | |
| 164 | + | |
| 165 | + | |
| 166 | + @NotNull | |
| 167 | + private static HttpClientPostEntity combationReturnObj(CloseableHttpResponse response, DefaultHttpClient httpclient) throws IOException { | |
| 168 | + HttpEntity httpEntity = response.getEntity(); | |
| 169 | + | |
| 170 | + CookieStore cookieStore = httpclient.getCookieStore(); | |
| 171 | + String result = EntityUtils.toString(httpEntity, "UTF-8"); | |
| 172 | + | |
| 173 | + HttpClientPostEntity postEntity = new HttpClientPostEntity(); | |
| 174 | + postEntity.setCookieStore(cookieStore); | |
| 175 | + postEntity.setResultStr(result); | |
| 176 | + return postEntity; | |
| 177 | + } | |
| 178 | + | |
| 179 | + private static DefaultHttpClient createDefaultHttpClient(){ | |
| 180 | + BasicHttpParams httpParams = new BasicHttpParams(); | |
| 181 | + HttpConnectionParams.setConnectionTimeout(httpParams, 9000); | |
| 182 | + HttpConnectionParams.setSoTimeout(httpParams, 59000); | |
| 183 | + | |
| 184 | + return new DefaultHttpClient(httpParams); | |
| 185 | + } | |
| 186 | +} | ... | ... |
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 | +} | ... | ... |