视频获取

pull/15/head
zhangyue 2024-01-09 19:20:45 +08:00
parent 25077ea9a6
commit 905576b68b
6 changed files with 361 additions and 11 deletions

View File

@ -5,10 +5,8 @@ import com.alibaba.fastjson.JSONObject;
import com.zcloud.entity.PageData; import com.zcloud.entity.PageData;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
@ -249,6 +247,76 @@ public class HttpClientService {
} }
return null; return null;
} }
/**
* POST
* @param url
* @param headerMap
* @param bodyMap
* @return JSON
* @throws Exception
*/
public static Map<String, Object> sendPostJsonForMap(String url, Map<String, Object> headerMap, PageData bodyMap) throws Exception{
JSONObject jsonObject = null;
HttpClient client = new SSLClient();
HttpResponse response = null;
try{
/**
* httpclient
*/
client = HttpClients.createDefault();
/**
* post
*/
HttpPost post = new HttpPost(url);
for (String key : headerMap.keySet()) {
post.setHeader(key, headerMap.get(key).toString());
}
/**
* Entity
*/
StringEntity entity = new StringEntity(JSONObject.toJSONString(bodyMap), ContentType.create("application/json", "utf-8"));
/**
*
*/
post.setEntity(entity);
/**
* post
*/
response = client.execute(post);
/**
*
*/
int statusCode = response.getStatusLine().getStatusCode();
if (SUCCESS_CODE == statusCode){
/**
* EntityUitls
*/
String result = EntityUtils.toString(response.getEntity(),"UTF-8");
/**
* json,json
*/
try{
jsonObject = JSONObject.parseObject(result);
Map<String, Object> maps = new HashMap<String, Object>();
maps = parseJSON2Map(jsonObject);
return maps;
}catch (Exception e){
e.printStackTrace();
return null;
}
}else{
LOGGER.error("HttpClientService-line: {}, errorMsg{}", 146, "POST请求失败");
}
}catch (Exception e){
LOGGER.error("HttpClientService-line: {}, Exception{}", 149, e);
}finally {
/* response.close();
client.close();*/
}
return null;
}
/** /**
* POSTAccept * POSTAccept

View File

@ -9,6 +9,7 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.Map;
/** /**
* description: http * description: http
@ -130,6 +131,70 @@ public class HttpRequestUtil {
return result.toString(); return result.toString();
} }
/**
* Http get
*
* @param httpUrl
* @return
*/
public static String doGetInitHearer(String httpUrl, Map<String, Object> headerMap) throws Exception {
//链接
HttpURLConnection connection = null;
InputStream is = null;
BufferedReader br = null;
StringBuffer result = new StringBuffer();
try {
//创建连接
URL url = new URL(httpUrl);
connection = (HttpURLConnection) url.openConnection();
//设置请求方式
connection.setRequestMethod("GET");
//设置请求头
for (String key : headerMap.keySet()) {
connection.setRequestProperty(key, headerMap.get(key).toString());
}
//设置连接超时时间
connection.setReadTimeout(15000);
//开始连接
connection.connect();
//获取响应数据
if (connection.getResponseCode() == 200) {
//获取返回的数据
is = connection.getInputStream();
if (null != is) {
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String temp = null;
while (null != (temp = br.readLine())) {
result.append(temp);
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != br) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != is) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//关闭远程连接
connection.disconnect();
}
return result.toString();
}
/** /**
* Http get * Http get
* *

View File

@ -0,0 +1,69 @@
package com.zcloud.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* @author fangjiakai
* @date 2024/1/8 20:56
*/
@Component
public class RedisUtil {
@Autowired
private RedisTemplate redisTemplate;
/**
* string
* @param key
* @param value
*/
public void setString(String key, String value){
redisTemplate.opsForValue().set(key,value);
}
/**
* string
* @param key
* @param value
*/
public String getString(String key){
return redisTemplate.opsForValue().get(key).toString();
}
/**
* stringtime
* @param key
* @param value
* @param time
*/
public void setString(String key, String value, long time){
redisTemplate.opsForValue().set(key,value,time, TimeUnit.SECONDS);
}
/**
* key
* @param key
*/
public boolean hasKey(String key){
return redisTemplate.hasKey(key);
}
/**
* key
* @param key
*/
public long getExpire(String key){
return redisTemplate.getExpire(key);
}
/**
*
* @param key
* @param time
*/
public void expire(String key, long time) {
redisTemplate.expire(key, time, TimeUnit.SECONDS);
}
}

View File

@ -0,0 +1,148 @@
package com.zcloud.util.ys;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zcloud.entity.PageData;
import com.zcloud.util.*;
import org.apache.http.NameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import java.net.URLEncoder;
import java.util.*;
/**
*
*/
@Component
public class YSUtil {
private static final String vmip = "http://172.14.0.54";
private static final String name = "loadmin";
private static final String passwd = "_Ab54321";
private static final String vmport = "7010";
private static final String linkPort = "8093";
private static final String VIIDPort = "8088";
@Autowired
private RedisUtil redisUtil;
public void loginOrKeepAlive() throws Exception {
// 剩余过期时间 -2为AccessToken已经过期
Long residueTimeOut = redisUtil.getExpire("AccessToken");
// 如果已经过期重新获取AccessToken
if (residueTimeOut < 0) {
Map resultFinal = null;
// 首次登录获取accessCode
Map resultFirst = HttpClientService.sendPostJsonForMap(vmip + ":" + VIIDPort + "/VIID/login/v2", new HashMap<String, Object>(), null);
if (resultFirst != null && resultFirst.get("AccessCode") != null) {
String accessCode = resultFirst.get("AccessCode").toString();
// MD5(BASE64(UserName)+ AccessCode + MD5(用户密码))
PageData pd = new PageData();
String LoginSignature = MD5.md5(encode(name.getBytes()) + accessCode + MD5.md5(passwd));
pd.put("UserName", name);
pd.put("AccessCode", accessCode);
pd.put("LoginSignature", LoginSignature);
// 第二次登录获取AccessToken
resultFinal = HttpClientService.sendPostJsonForMap(vmip + ":" + VIIDPort + "/VIID/login/v2", new HashMap<String, Object>(), pd);
if (resultFinal != null && resultFinal.get("AccessToken") != null) {
String AccessToken = resultFinal.get("AccessToken").toString();
redisUtil.setString("AccessToken", AccessToken, 30);
}
}
} else if (residueTimeOut < 10) { // 10秒内过期进行AccessToken保活并刷新redis过期时间
Map<String, Object> header = new HashMap<String, Object>();
System.out.println(redisUtil.getString("AccessToken"));
header.put("Authorization", redisUtil.getString("AccessToken"));
Map keepAliveResult = HttpClientService.sendPostJsonForMap(vmip + ":" + VIIDPort + "/VIID/hadesadapter/user/keepalive", header, null);
if (keepAliveResult != null && keepAliveResult.get("ErrCode") != null && ("0").equals(keepAliveResult.get("ErrCode").toString())) {
redisUtil.expire("AccessToken", 30);
}
}
}
public JSONObject queryAreaList(PageData pd) throws Exception {
this.loginOrKeepAlive();
Map<String, Object> header = new HashMap<String, Object>();
header.put("Authorization", redisUtil.getString("AccessToken"));
JSONObject condition = new JSONObject();
condition.put("QueryCount", 1);
condition.put("PageFirstRowNumber", 0);
condition.put("PageRowNum", 200);
JSONArray conditionArray = new JSONArray();
// 查询条件
// 这个queryCondition查询条件翻译过来就是 where RES_TYPE = "1"
// 查询条件的类型 - 256-资源类型(RES_TYPE)
// 查询条件的逻辑关系 0 代表等于
// 查询条件的值 在资源类型中 1 -组织域
// JSONObject queryCondition = initQueryCondition(256, 0, "1");
// 这个queryCondition1查询条件翻译过来就是 order by RES_SUB_TYPE asc
// 查询条件的类型 - 11-资源子类型(RES_SUB_TYPE)
// 查询条件的逻辑关系 6 代表升序
// JSONObject queryCondition2 = initQueryCondition(11, 6, "");
// 这个queryCondition3查询条件翻译过来就是 order by EVENT_TYPE_NAME asc
// 查询条件的类型 - 273-事件类型名称(EVENT_TYPE_NAME)
// 查询条件的逻辑关系 6 代表升序
// JSONObject queryCondition3 = initQueryCondition(273, 6, "");
// 以此类推下面将不在举例说明具体的查询条件编码数据字典附录在src/main/webapp/uploadFiles/ys/ysDictionaries.md 这里
conditionArray.add(initQueryCondition(256, 0, "1"));
conditionArray.add(initQueryCondition(11, 6, ""));
conditionArray.add(initQueryCondition(273, 6, ""));
conditionArray.add(initQueryCondition(1, 6, ""));
conditionArray.add(initQueryCondition(269, 0, "1"));
condition.put("Condition", conditionArray);
condition.put("ItemNum", conditionArray.size());
String encodedOrg = URLEncoder.encode(pd.get("org").toString(), "UTF-8");
String encodedCondition = URLEncoder.encode(condition.toJSONString(), "UTF-8");
String resultStr = HttpRequestUtil.doGetInitHearer(vmip + ":" + VIIDPort +"/VIID/query?org="+encodedOrg+"&condition="+encodedCondition, header);
JSONObject resultJson = JSONObject.parseObject(resultStr);
return resultJson;
}
public JSONObject queryCameraList(PageData pd) throws Exception {
this.loginOrKeepAlive();
Map<String, Object> header = new HashMap<String, Object>();
header.put("Authorization", redisUtil.getString("AccessToken"));
JSONObject condition = new JSONObject();
condition.put("QueryCount", 1);
condition.put("PageFirstRowNumber", 0);
condition.put("PageRowNum", 200);
JSONArray conditionArray = new JSONArray();
conditionArray.add(initQueryCondition(256, 0, "1001"));
conditionArray.add(initQueryCondition(273, 6, ""));
conditionArray.add(initQueryCondition(1, 6, ""));
condition.put("Condition", conditionArray);
condition.put("ItemNum", conditionArray.size());
String encodedOrg = URLEncoder.encode(pd.get("org").toString(), "UTF-8");
String encodedCondition = URLEncoder.encode(condition.toJSONString(), "UTF-8");
String resultStr = HttpRequestUtil.doGetInitHearer(vmip + ":" + VIIDPort +"/VIID/query?org="+encodedOrg+"&condition="+encodedCondition, header);
JSONObject resultJson = JSONObject.parseObject(resultStr);
return resultJson;
}
private JSONObject initQueryCondition(int queryType, int logicFlag, String queryData) {
JSONObject queryCondition = new JSONObject();
queryCondition.put("QueryType", queryType); // 查询条件的类型
queryCondition.put("LogicFlag", logicFlag); // 查询条件的逻辑关系
queryCondition.put("QueryData", queryData); // 查询条件的值
return queryCondition;
}
//base64加密
public static String encode(byte[] content) {
return new sun.misc.BASE64Encoder().encode(content);
}
}

View File

@ -1,11 +1,11 @@
datasource.no1.driver-class-name: com.mysql.cj.jdbc.Driver datasource.no1.driver-class-name: com.mysql.cj.jdbc.Driver
datasource.no1.url=jdbc:mysql://39.101.130.96:33068/qa-gwj-prevention?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf-8 datasource.no1.url=jdbc:mysql://192.168.0.18:3306/qa-cmt-prevention?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf-8
datasource.no1.username=root datasource.no1.username=root
datasource.no1.password=Mysql@zcloud88888 datasource.no1.password=root
datasource.no2.driver-class-name: com.mysql.cj.jdbc.Driver datasource.no2.driver-class-name: com.mysql.cj.jdbc.Driver
datasource.no2.url=jdbc:mysql://39.101.130.96:33068/qa-gwj-regulatory?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf-8 datasource.no2.url=jdbc:mysql://192.168.0.18:3306/qa-cmt-regulatory?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf-8
datasource.no2.username=root datasource.no2.username=root
datasource.no2.password=Mysql@zcloud88888 datasource.no2.password=root
#druid??? #druid???
@ -82,7 +82,7 @@ rocketmq.consumer.group2=edu-admin-edit
rocketmq.consumer.group1=edu-admin-add rocketmq.consumer.group1=edu-admin-add
#rocketmq.name-server=10.0.140.141:9876 #rocketmq.name-server=10.0.140.141:9876
#rocketmq.name-server=192.168.0.70:9876 #rocketmq.name-server=192.168.0.70:9876
rocketmq.name-server=192.168.0.31:9876 rocketmq.name-server=192.168.0.18:9876
rocketmq.producer.group=libmiddle rocketmq.producer.group=libmiddle
rocketmq.producer.send-message-timeout=3000 rocketmq.producer.send-message-timeout=3000
rocketmq.producer.compress-message-body-threshold=4096 rocketmq.producer.compress-message-body-threshold=4096
@ -110,11 +110,11 @@ base.info.BACKENDADDR=http://192.168.0.31:8992/qa-regulatory-gwj/
# Redis\u6570\u636E\u5E93\u7D22\u5F15\uFF08\u9ED8\u8BA4\u4E3A0\uFF09 # Redis\u6570\u636E\u5E93\u7D22\u5F15\uFF08\u9ED8\u8BA4\u4E3A0\uFF09
spring.redis.database=0 spring.redis.database=0
# Redis\u670D\u52A1\u5668\u5730\u5740 # Redis\u670D\u52A1\u5668\u5730\u5740
spring.redis.host=39.103.224.166 spring.redis.host=127.0.0.1
# Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3 # Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3
spring.redis.port=63799 spring.redis.port=6379
# Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09 # Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09
spring.redis.password=redis@zcloud88888 spring.redis.password=
# \u8FDE\u63A5\u6C60\u6700\u5927\u8FDE\u63A5\u6570\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09 # \u8FDE\u63A5\u6C60\u6700\u5927\u8FDE\u63A5\u6570\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09
spring.redis.jedis.pool.max-active=20 spring.redis.jedis.pool.max-active=20
# \u8FDE\u63A5\u6C60\u6700\u5927\u963B\u585E\u7B49\u5F85\u65F6\u95F4\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09 # \u8FDE\u63A5\u6C60\u6700\u5927\u963B\u585E\u7B49\u5F85\u65F6\u95F4\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09