|
@@ -2,6 +2,7 @@ package com.ruoyi.zhdd.service.impl;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
@@ -38,6 +39,8 @@ public class DhServiceImpl implements IDhService {
|
|
|
private String keepaliveUrl;
|
|
|
@Value("${third.dhDeviceTree}")
|
|
|
private String dhDeviceTreeUrl;
|
|
|
+ @Value("${third.dhVideoUserName}")
|
|
|
+ private String dhVideoUserName;
|
|
|
@Autowired
|
|
|
private ISysConfigService sysConfigService;
|
|
|
|
|
@@ -186,6 +189,79 @@ public class DhServiceImpl implements IDhService {
|
|
|
return getJson.getJSONArray("results");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getVideoToken(String account) {
|
|
|
+ Map<String, Object> token = RedisUtils.getCacheMap(Constants.CACHE_DH_VIDEO_TOKEN);
|
|
|
+ if (token.isEmpty()) {
|
|
|
+ token = new HashMap<>();
|
|
|
+ // 从大华接口获取token
|
|
|
+ if (StrUtil.isBlank(account)) {
|
|
|
+ account = dhVideoUserName;
|
|
|
+ }
|
|
|
+ JSONObject jsonOne = new JSONObject();
|
|
|
+ jsonOne.set("userName", account);
|
|
|
+ jsonOne.set("clientType", "winpc");
|
|
|
+ String postOne = "";
|
|
|
+ try {
|
|
|
+ postOne = HttpUtil.post(dhAuthorizeUrl, jsonOne.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【视频】大华接口请求异常,账号:{}:{}", account, e.getMessage());
|
|
|
+ throw new ServiceException("【视频】大华融合通信平台无法连接,请联系大华融合通信平台维护人员检查!");
|
|
|
+ }
|
|
|
+ JSONObject postOneJson = JSONUtil.parseObj(postOne);
|
|
|
+ log.info("【视频】大华创建会话,,账号:{}的返回结果:{}", account, postOneJson);
|
|
|
+ if (postOneJson.containsKey("realm")) {
|
|
|
+ String randomKey = postOneJson.getStr("randomKey");
|
|
|
+ String realm = postOneJson.getStr("realm");
|
|
|
+ String encryptType = postOneJson.getStr("encryptType");
|
|
|
+ // 第二次交互
|
|
|
+ String password = "huashe123";
|
|
|
+ String signature = SecureUtil.md5(
|
|
|
+ SecureUtil.md5(account + ":" + realm + ":" +
|
|
|
+ SecureUtil.md5(
|
|
|
+ SecureUtil.md5(
|
|
|
+ account +
|
|
|
+ SecureUtil.md5(password)))) + ":" + randomKey);
|
|
|
+ jsonOne.set("signature", signature);
|
|
|
+ jsonOne.set("randomKey", randomKey);
|
|
|
+ jsonOne.set("encryptType", encryptType);
|
|
|
+ jsonOne.set("pid", 2548);
|
|
|
+ jsonOne.set("expiredTime", 86400);
|
|
|
+ String postTwo = HttpUtil.post(dhAuthorizeUrl, jsonOne.toString());
|
|
|
+ JSONObject postTwoJson = JSONUtil.parseObj(postTwo);
|
|
|
+ if (postTwoJson.containsKey("token")) {
|
|
|
+ String tokenStr = postTwoJson.getStr("token");
|
|
|
+ int duration = postTwoJson.getInt("duration");
|
|
|
+ String userId = postTwoJson.getStr("userId");
|
|
|
+ token.put("userId", userId);
|
|
|
+ token.put("token", tokenStr);
|
|
|
+ token.put("userName", postTwoJson.getStr("userName"));
|
|
|
+ log.info("【视频】大华创建会话,账号:{}的过期时间:{}", account, duration);
|
|
|
+ log.info("【视频】大华创建会话,账号:{}的Token:{}", account, token);
|
|
|
+ if (ObjectUtil.isEmpty(duration)) {
|
|
|
+ duration = 120;
|
|
|
+ }
|
|
|
+ // 存入redis缓存
|
|
|
+ RedisUtils.setCacheMap(Constants.CACHE_DH_VIDEO_TOKEN, token);
|
|
|
+ RedisUtils.expire(Constants.CACHE_DH_VIDEO_TOKEN, Convert.toInt(duration), TimeUnit.SECONDS);
|
|
|
+ } else {
|
|
|
+ log.error("【视频】大华,账号:{}第二次创建会话失败:{}", account, postTwoJson);
|
|
|
+ if ("user is repeated landing".equals(postTwoJson.getStr("message"))) {
|
|
|
+ // 说明已经登录过,那么退出,重新获取
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("【视频】大华,账号:{}第一次创建会话失败:{}", account, postOneJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void offlineVideoToken() {
|
|
|
+ RedisUtils.deleteObject(Constants.CACHE_DH_VIDEO_TOKEN);
|
|
|
+ }
|
|
|
+
|
|
|
private JSONArray getList(Map<String, Object> param) {
|
|
|
param.put("nodeType", 1);
|
|
|
param.put("typeCode", "01;0;ALL;ALL");
|