|
@@ -3,6 +3,7 @@ package com.ruoyi.zhdd.service.impl;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
@@ -60,7 +61,13 @@ public class DhServiceImpl implements IDhService {
|
|
|
JSONObject jsonOne = new JSONObject();
|
|
|
jsonOne.set("userName", userName);
|
|
|
jsonOne.set("clientType", "other");
|
|
|
- String postOne = HttpUtil.post(dhAuthorizeUrl, jsonOne.toString());
|
|
|
+ String postOne = "";
|
|
|
+ try {
|
|
|
+ postOne = HttpUtil.post(dhAuthorizeUrl, jsonOne.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("大华接口请求异常:{}", e.getMessage());
|
|
|
+ throw new ServiceException("大华接口请求异常");
|
|
|
+ }
|
|
|
JSONObject postOneJson = JSONUtil.parseObj(postOne);
|
|
|
if (postOneJson.containsKey("realm")) {
|
|
|
String randomKey = postOneJson.getStr("randomKey");
|
|
@@ -122,15 +129,43 @@ public class DhServiceImpl implements IDhService {
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
String id = sysConfigService.selectConfigByKey("dh.device.orgId");
|
|
|
param.put("id", id);
|
|
|
+ JSONArray list = getList(param);
|
|
|
+ JSONArray newList = new JSONArray();
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+ for (Object o : list) {
|
|
|
+ JSONObject getJson = JSONUtil.parseObj(o);
|
|
|
+ if (id.equals(getJson.getStr("orgCode")) && getJson.getInt("nodeType") == 1) {
|
|
|
+ param.put("id", getJson.getStr("id"));
|
|
|
+ JSONArray listTwo = getList(param);
|
|
|
+ if (listTwo != null && listTwo.size() > 0) {
|
|
|
+ for (Object two : listTwo) {
|
|
|
+ newList.add(JSONUtil.parseObj(two));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newList.add(getJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("数量:{}", newList.size());
|
|
|
+ return newList;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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", 100);
|
|
|
- String get = HttpRequest.get(dhDeviceTreeUrl)
|
|
|
- .header("X-Subject-Token", this.getToken())
|
|
|
- .form(param)
|
|
|
- .timeout(-1)
|
|
|
- .execute().body();
|
|
|
+ param.put("pageSize", 3000);
|
|
|
+ String get = "";
|
|
|
+ try {
|
|
|
+ get = HttpRequest.get(dhDeviceTreeUrl)
|
|
|
+ .header("X-Subject-Token", this.getToken())
|
|
|
+ .form(param)
|
|
|
+ .timeout(-1)
|
|
|
+ .execute().body();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("大华接口2请求异常:{}", e.getMessage());
|
|
|
+ throw new ServiceException("大华接口请求异常");
|
|
|
+ }
|
|
|
JSONObject getJson = JSONUtil.parseObj(get);
|
|
|
if (getJson.containsKey("code")) {
|
|
|
// 说明有错误
|
|
@@ -140,4 +175,47 @@ public class DhServiceImpl implements IDhService {
|
|
|
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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|