|
@@ -2,7 +2,6 @@ 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;
|
|
@@ -44,76 +43,68 @@ public class DhServiceImpl implements IDhService {
|
|
|
@Autowired
|
|
|
private ISysConfigService sysConfigService;
|
|
|
|
|
|
- @Override
|
|
|
-
|
|
|
- public String getToken() {
|
|
|
- String token = RedisUtils.getCacheObject(Constants.CACHE_DH_TOKEN);
|
|
|
- if (token == null) {
|
|
|
- token = authorize();
|
|
|
- }
|
|
|
- return token;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 创建会话
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public String authorize() {
|
|
|
- // 从大华接口获取token
|
|
|
- String token = "";
|
|
|
- String userName = "jtj01";
|
|
|
- JSONObject jsonOne = new JSONObject();
|
|
|
- jsonOne.set("userName", userName);
|
|
|
- jsonOne.set("clientType", "other");
|
|
|
- String postOne = "";
|
|
|
- try {
|
|
|
- postOne = HttpUtil.post(dhAuthorizeUrl, jsonOne.toString());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("大华接口请求异常:{}", e.getMessage());
|
|
|
- throw new ServiceException("大华融合通信平台无法连接,请联系大华融合通信平台维护人员检查!");
|
|
|
- }
|
|
|
- JSONObject postOneJson = JSONUtil.parseObj(postOne);
|
|
|
- log.info("大华创建会话的返回结果:{}", postOneJson);
|
|
|
- if (postOneJson.containsKey("realm")) {
|
|
|
- String randomKey = postOneJson.getStr("randomKey");
|
|
|
- String realm = postOneJson.getStr("realm");
|
|
|
- String encryptType = postOneJson.getStr("encryptType");
|
|
|
- // 第二次交互
|
|
|
- String password = "Dahua@4002";
|
|
|
- String signature = SecureUtil.md5(
|
|
|
- SecureUtil.md5(userName + ":" + realm + ":" +
|
|
|
- SecureUtil.md5(
|
|
|
+ public Map<String, String> authorize(String userName, String password, String clientType, String cacheKey) {
|
|
|
+ Map<String, String> tokenMap = RedisUtils.getCacheMap(cacheKey);
|
|
|
+ if (tokenMap.isEmpty()) {
|
|
|
+ tokenMap = new HashMap<>();
|
|
|
+ JSONObject jsonOne = new JSONObject();
|
|
|
+ jsonOne.set("userName", userName);
|
|
|
+ jsonOne.set("clientType", clientType);
|
|
|
+ String postOne = "";
|
|
|
+ try {
|
|
|
+ postOne = HttpUtil.post(dhAuthorizeUrl, jsonOne.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("大华接口请求异常:{}\n账号:{}\n密码:{}", e.getMessage(), userName, password);
|
|
|
+ throw new ServiceException("【" + userName + "】大华融合通信平台无法连接,请联系大华融合通信平台维护人员检查!");
|
|
|
+ }
|
|
|
+ JSONObject postOneJson = JSONUtil.parseObj(postOne);
|
|
|
+ if (postOneJson.containsKey("realm")) {
|
|
|
+ String randomKey = postOneJson.getStr("randomKey");
|
|
|
+ String realm = postOneJson.getStr("realm");
|
|
|
+ String encryptType = postOneJson.getStr("encryptType");
|
|
|
+ // 第二次交互
|
|
|
+ String signature = SecureUtil.md5(
|
|
|
+ SecureUtil.md5(userName + ":" + realm + ":" +
|
|
|
SecureUtil.md5(
|
|
|
- userName +
|
|
|
- SecureUtil.md5(password)))) + ":" + randomKey);
|
|
|
- jsonOne.set("signature", signature);
|
|
|
- jsonOne.set("randomKey", randomKey);
|
|
|
- jsonOne.set("encryptType", encryptType);
|
|
|
- jsonOne.set("expiredTime", 86400);
|
|
|
- String postTwo = HttpUtil.post(dhAuthorizeUrl, jsonOne.toString());
|
|
|
- JSONObject postTwoJson = JSONUtil.parseObj(postTwo);
|
|
|
- if (postTwoJson.containsKey("token")) {
|
|
|
- token = postTwoJson.getStr("token");
|
|
|
- int duration = postTwoJson.getInt("duration");
|
|
|
- log.info("大华创建会话的过期时间:{}", duration);
|
|
|
- if (ObjectUtil.isEmpty(duration)) {
|
|
|
- duration = 120;
|
|
|
+ SecureUtil.md5(
|
|
|
+ userName +
|
|
|
+ SecureUtil.md5(password)))) + ":" + randomKey);
|
|
|
+ jsonOne.set("signature", signature);
|
|
|
+ jsonOne.set("randomKey", randomKey);
|
|
|
+ jsonOne.set("encryptType", encryptType);
|
|
|
+ jsonOne.set("expiredTime", 120);
|
|
|
+ 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");
|
|
|
+ tokenMap.put("userId", userId);
|
|
|
+ tokenMap.put("token", tokenStr);
|
|
|
+ tokenMap.put("userName", postTwoJson.getStr("userName"));
|
|
|
+ log.info("大华创建会话:\n账号:{}\n过期时间:{}秒\nTokenMap:{}", userName, duration, tokenMap);
|
|
|
+ if (ObjectUtil.isEmpty(duration)) {
|
|
|
+ duration = 120;
|
|
|
+ }
|
|
|
+ // 存入redis缓存
|
|
|
+ RedisUtils.setCacheMap(cacheKey, tokenMap);
|
|
|
+ RedisUtils.expire(cacheKey, Convert.toInt(duration), TimeUnit.SECONDS);
|
|
|
+ } else {
|
|
|
+ log.error("大华=第二次创建会话失败:\n账号:{}\n密码:{}\n返回体:{}", userName, password, postTwoJson);
|
|
|
+ if ("user is repeated landing".equals(postTwoJson.getStr("message"))) {
|
|
|
+ // 说明已经登录过,那么退出,重新获取
|
|
|
+ }
|
|
|
}
|
|
|
- // 存入redis缓存
|
|
|
- RedisUtils.setCacheObject(Constants.CACHE_DH_TOKEN, token, Convert.toInt(duration), TimeUnit.SECONDS);
|
|
|
-// RedisUtils.setCacheObject(Constants.CACHE_DH_TOKEN_REFRESH, token);
|
|
|
} else {
|
|
|
- log.error("大华=第二次创建会话失败:{}", postTwoJson);
|
|
|
- if ("user is repeated landing".equals(postTwoJson.getStr("message"))) {
|
|
|
- // 说明已经登录过,那么退出,重新获取
|
|
|
-
|
|
|
- }
|
|
|
+ log.error("大华=第一次创建会话失败:{}", postOneJson);
|
|
|
}
|
|
|
- } else {
|
|
|
- log.error("大华=第一次创建会话失败:{}", postOneJson);
|
|
|
}
|
|
|
- return token;
|
|
|
+ return tokenMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -126,13 +117,11 @@ public class DhServiceImpl implements IDhService {
|
|
|
json.set("token", token);
|
|
|
json.set("duration", duration);
|
|
|
String put = HttpRequest.put(keepaliveUrl).header("X-Subject-Token", token).contentType("application/json").timeout(-1).body(json.toString()).execute().body();
|
|
|
-
|
|
|
if ("".equals(put)) {
|
|
|
// 存入redis缓存
|
|
|
RedisUtils.expire(tokenKey, Convert.toInt(duration), TimeUnit.SECONDS);
|
|
|
} else {
|
|
|
log.info("保活失败:{}。入参:{}", put, json);
|
|
|
-// authorize();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -165,14 +154,15 @@ public class DhServiceImpl implements IDhService {
|
|
|
@Override
|
|
|
public JSONArray querySingleStat() {
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
- param.put("orgCode", "S4NbecfYB1DGB68AN187Q8");
|
|
|
+ param.put("orgCode", "");
|
|
|
param.put("isSubOrg", 1);
|
|
|
param.put("page", 1);
|
|
|
param.put("pageSize", 3000);
|
|
|
String get = "";
|
|
|
+ String token = this.authorize("jtj01", "Dahua@4002", "winpc", Constants.CACHE_DH_FUYONG_TOKEN).get("token");
|
|
|
try {
|
|
|
- get = HttpRequest.get("http://10.55.134.3:8314/videoService/devicesManager/searchDevices")
|
|
|
- .header("X-Subject-Token", this.getToken())
|
|
|
+ get = HttpRequest.get("http://10.55.134.30:8314/videoService/devicesManager/searchDevices")
|
|
|
+ .header("X-Subject-Token", token)
|
|
|
.form(param)
|
|
|
.timeout(-1)
|
|
|
.execute().body();
|
|
@@ -189,214 +179,185 @@ public class DhServiceImpl implements IDhService {
|
|
|
return getJson.getJSONArray("results");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Map<String, Object> getVideoToken(String account, String key) {
|
|
|
- Map<String, Object> token = RedisUtils.getCacheMap(key);
|
|
|
- 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 = "Dahua@4002";
|
|
|
- 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", 120);
|
|
|
- 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(key, token);
|
|
|
- RedisUtils.expire(key, 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 Map<String, Object> getVideoToken(String account, String key) {
|
|
|
+// Map<String, Object> token = RedisUtils.getCacheMap(key);
|
|
|
+// 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 = "Dahua@4002";
|
|
|
+// 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", 120);
|
|
|
+// 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(key, token);
|
|
|
+// RedisUtils.expire(key, 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(String key) {
|
|
|
RedisUtils.deleteObject(key);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Map<String, Object> getTestToken() {
|
|
|
- Map<String, Object> token = RedisUtils.getCacheMap(Constants.CACHE_DH_TEST_TOKEN);
|
|
|
- if (token.isEmpty()) {
|
|
|
- token = new HashMap<>();
|
|
|
- // 从大华接口获取token
|
|
|
- JSONObject jsonOne = new JSONObject();
|
|
|
- String account = "system";
|
|
|
- jsonOne.set("userName", account);
|
|
|
- jsonOne.set("clientType", "winpc");
|
|
|
- String postOne = "";
|
|
|
- try {
|
|
|
- postOne = HttpUtil.post("http://10.55.134.30:8314/videoService/accounts/authorize", 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 = "Admin123";
|
|
|
- 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", 120);
|
|
|
- String postTwo = HttpUtil.post("http://10.55.134.30:8314/videoService/accounts/authorize", 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_TEST_TOKEN, token);
|
|
|
- RedisUtils.expire(Constants.CACHE_DH_TEST_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 Map<String, String> getTestToken() {
|
|
|
+// Map<String, String> token = RedisUtils.getCacheMap(Constants.CACHE_DH_TEST_TOKEN);
|
|
|
+// if (token.isEmpty()) {
|
|
|
+// token = new HashMap<>();
|
|
|
+// // 从大华接口获取token
|
|
|
+// JSONObject jsonOne = new JSONObject();
|
|
|
+// String account = "huashe";
|
|
|
+// 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 = "Admin123";
|
|
|
+// 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", 120);
|
|
|
+// 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_TEST_TOKEN, token);
|
|
|
+// RedisUtils.expire(Constants.CACHE_DH_TEST_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;
|
|
|
+// }
|
|
|
|
|
|
+ /**
|
|
|
+ * 组装设备树数据
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private JSONArray getList(Map<String, Object> param) {
|
|
|
param.put("nodeType", 1);
|
|
|
param.put("typeCode", "01;0;ALL;ALL");
|
|
|
param.put("page", 1);
|
|
|
param.put("pageSize", 3000);
|
|
|
String get = "";
|
|
|
+ String token = this.authorize("jtj01", "Dahua@4002", "winpc", Constants.CACHE_DH_FUYONG_TOKEN).get("token");
|
|
|
try {
|
|
|
get = HttpRequest.get(dhDeviceTreeUrl)
|
|
|
- .header("X-Subject-Token", this.getToken())
|
|
|
+ .header("X-Subject-Token", token)
|
|
|
.form(param)
|
|
|
.timeout(-1)
|
|
|
.execute().body();
|
|
|
} catch (Exception e) {
|
|
|
+ log.info("请求的参数:{}。token={}", dhDeviceTreeUrl, token);
|
|
|
log.error("大华接口2请求异常:{}", e.getMessage());
|
|
|
- throw new ServiceException("大华融合通信平台无法连接,请联系大华融合通信平台维护人员检查!");
|
|
|
+ throw new ServiceException("【jtj01】大华融合通信平台无法连接,请联系大华融合通信平台维护人员检查!");
|
|
|
}
|
|
|
+ log.info("请求的参数:{}。token={}", dhDeviceTreeUrl, token);
|
|
|
+ log.info("设备数返回数据:{}", get);
|
|
|
JSONObject getJson = JSONUtil.parseObj(get);
|
|
|
if (getJson.containsKey("code")) {
|
|
|
// 说明有错误
|
|
|
log.error("获取设备树出错:{}", getJson);
|
|
|
if (401 == getJson.getInt("code")) {
|
|
|
- RedisUtils.deleteObject(Constants.CACHE_DH_TOKEN);
|
|
|
+ RedisUtils.deleteObject(Constants.CACHE_DH_FUYONG_TOKEN);
|
|
|
}
|
|
|
- throw new ServiceException("调用大华融合通信平台接口创建会话出错,错误:" + getJson.getStr("message"));
|
|
|
+ throw new ServiceException("【jtj01】调用大华融合通信平台接口创建会话出错,错误:" + getJson.getStr("message"));
|
|
|
}
|
|
|
return getJson.getJSONArray("results");
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- /*String token = "";
|
|
|
- String userName = "shujuceshi";
|
|
|
- JSONObject jsonOne = new JSONObject();
|
|
|
- jsonOne.set("userName", userName);
|
|
|
- jsonOne.set("clientType", "other");
|
|
|
- String postOne = HttpUtil.post("http://10.211.55.3:6699/videoService/accounts/authorize", jsonOne.toString());
|
|
|
- JSONObject postOneJson = JSONUtil.parseObj(postOne);
|
|
|
- if (postOneJson.containsKey("realm")) {
|
|
|
- String randomKey = postOneJson.getStr("randomKey");
|
|
|
- String realm = postOneJson.getStr("realm");
|
|
|
- String encryptType = postOneJson.getStr("encryptType");
|
|
|
- // 第二次交互
|
|
|
- String password = "Admin123";
|
|
|
- String signature = SecureUtil.md5(
|
|
|
- SecureUtil.md5(userName + ":" + realm + ":" +
|
|
|
- SecureUtil.md5(
|
|
|
- SecureUtil.md5(
|
|
|
- userName +
|
|
|
- SecureUtil.md5(password)))) + ":" + randomKey);
|
|
|
- jsonOne.set("signature", signature);
|
|
|
- jsonOne.set("randomKey", randomKey);
|
|
|
- jsonOne.set("encryptType", encryptType);
|
|
|
- String postTwo = HttpUtil.post("http://10.211.55.3:6699/videoService/accounts/authorize", jsonOne.toString());
|
|
|
- JSONObject postTwoJson = JSONUtil.parseObj(postTwo);
|
|
|
- if (postTwoJson.containsKey("token")) {
|
|
|
- token = postTwoJson.getStr("token");
|
|
|
- // 存入redis缓存
|
|
|
-// RedisUtils.setCacheObject(Constants.CACHE_DH_TOKEN, token, 120, TimeUnit.SECONDS);
|
|
|
-// RedisUtils.setCacheObject(Constants.CACHE_DH_TOKEN_REFRESH, token);
|
|
|
- } else {
|
|
|
- log.error("大华=第二次创建会话失败:{}", postTwoJson);
|
|
|
- if ("user is repeated landing".equals(postTwoJson.getStr("message"))) {
|
|
|
- // 说明已经登录过,那么退出,重新获取
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.error("大华=第一次创建会话失败:{}", postOneJson);
|
|
|
- }
|
|
|
- System.out.println(token);*/
|
|
|
}
|
|
|
|
|
|
}
|