Commit 0f7cd3fd authored by 高飞's avatar 高飞

修改调用服务为传递rtsp 解析为flv

parent b04165ba
...@@ -338,25 +338,18 @@ public void sendevent( Alarm trffClientMessage){ ...@@ -338,25 +338,18 @@ public void sendevent( Alarm trffClientMessage){
//huode resid 中值、 //huode resid 中值、
if(null!=rtsp) { if(null!=rtsp) {
if( null==stringRedisTemplate.opsForValue().get(resisvalue)) if( null==stringRedisTemplate.opsForValue().get(videoid))
{ {
log.info("flv-----"); log.info("flv-----");
flvCacheService.getvalue(); flvCacheService.getvalue(videoid,rtsp);
} }
log.info(stringRedisTemplate.opsForValue().get(videoid));
JSONObject jsonObject = JSONObject.parseObject(stringRedisTemplate.opsForValue().get(videoid));
JSONArray jsonArr = JSONObject.parseArray(stringRedisTemplate.opsForValue().get(resisvalue)); if (null != jsonObject.getJSONArray("play_list") && jsonObject.getJSONArray("play_list").size() > 0) {
log.info("jsonArr" + jsonArr.size()); return String.valueOf(jsonObject.getJSONArray("play_list").get(0));
for (int i = 0; i < jsonArr.size(); i++) {
JSONObject jsonObject = jsonArr.getJSONObject(i);
if (jsonObject.getString("source").equalsIgnoreCase(rtsp)) {
if (null != jsonObject.getJSONArray("play_uris") && jsonObject.getJSONArray("play_uris").size() > 3) {
return String.valueOf(jsonObject.getJSONArray("play_uris").get(2));
}
}
} }
} }
return ""; return "";
......
...@@ -51,7 +51,7 @@ public class FileTransferManager { ...@@ -51,7 +51,7 @@ public class FileTransferManager {
/// System.out.println("connection.getResponseCode:" + connection.getResponseCode() ); /// System.out.println("connection.getResponseCode:" + connection.getResponseCode() );
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream inputStream = connection.getInputStream(); InputStream inputStream = connection.getInputStream();
log.info("url:",url , " --- "+"key:",key); log.info("url:"+url+" ---key:"+key);
String pname = DateUtils.formatCurrDayNoSign() + "_"+recordid+"_0000_"+key.replace("path",""); String pname = DateUtils.formatCurrDayNoSign() + "_"+recordid+"_0000_"+key.replace("path","");
String fileName = pname +filesuff; String fileName = pname +filesuff;
String ftputl = FTPUtil.getFtpUrl(ftp) + basePath + "/" + fileName; String ftputl = FTPUtil.getFtpUrl(ftp) + basePath + "/" + fileName;
......
...@@ -18,7 +18,6 @@ import org.springframework.stereotype.Component; ...@@ -18,7 +18,6 @@ import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
@Component
public class MyApplicationStartingEventListener implements ApplicationListener<SpringApplicationEvent>, ApplicationContextAware { public class MyApplicationStartingEventListener implements ApplicationListener<SpringApplicationEvent>, ApplicationContextAware {
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
......
package com.hzjt.service; package com.hzjt.service;
import com.hzjt.domain.ResultObj;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.*; import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -24,18 +28,20 @@ public class FLVCacheService { ...@@ -24,18 +28,20 @@ public class FLVCacheService {
@Value("${flv.url}") @Value("${flv.url}")
private String url; private String url;
public void getvalue() { public void getvalue(String videoid,String rtsp) {
try { try {
HttpHeaders headers = getHttpHeaders(); HttpHeaders headers = new HttpHeaders();
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
RestTemplate client = new RestTemplate(); RestTemplate client = new RestTemplate();
ResponseEntity<String> request = client.exchange((url), HttpMethod.GET, requestEntity, String.class); String jsonString = "{\"video_id\":\""+videoid+"\",\"url\":\""+rtsp+"\"}";
log.info("jsonString"+jsonString);
headers.setContentType(MediaType.valueOf("application/json;UTF-8"));
HttpEntity<String> strEntity = new HttpEntity<>(jsonString,headers);
ResponseEntity<String> response = client.postForEntity(url, strEntity, String.class);
//解析返回结果 //解析返回结果
log.info("response"+response.getBody());
if (request.getBody() != null) { if (response.getBody() != null) {
log.info("flv response success" ); log.info("flv response success" );
stringRedisTemplate.opsForValue().set(resisvalue,request.getBody(), 32, TimeUnit.MINUTES); stringRedisTemplate.opsForValue().set(videoid,response.getBody(), 10, TimeUnit.MINUTES);
} else { } else {
log.error("flv response " + "empty..."); log.error("flv response " + "empty...");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment