package com.basic.security.utils;
|
|
import com.basic.security.model.Alarm;
|
import com.google.gson.Gson;
|
|
import org.apache.http.util.TextUtils;
|
|
import java.io.BufferedInputStream;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import java.net.HttpURLConnection;
|
import java.net.URL;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
public class VideoPath {
|
static Map<String, String> deviceMap = new HashMap<>();
|
static Map<String, String> ngxMap = new HashMap<>();
|
static Gson gson = new Gson();
|
static Gson gson1 = new Gson();
|
|
static {
|
{
|
deviceMap.put("DSVAD010120181119", "http://172.17.50.241:11111/getRecordVideoPath");
|
deviceMap.put("DSVAD010220181119", "http://172.17.50.242:11111/getRecordVideoPath");
|
deviceMap.put("DSVAD010320181119", "http://172.17.50.243:11111/getRecordVideoPath");
|
deviceMap.put("DSVAD010420181119", "http://172.17.50.244:11111/getRecordVideoPath");
|
|
ngxMap.put("DSVAD010120181119", "http://172.17.50.241/videosource");
|
ngxMap.put("DSVAD010220181119", "http://172.17.50.242/videosource");
|
ngxMap.put("DSVAD010320181119", "http://172.17.50.243/videosource");
|
ngxMap.put("DSVAD010420181119", "http://172.17.50.244/videosource");
|
}
|
|
{
|
|
// deviceMap.put("DSVAD010220181119", "http://58.118.225.79:51111/getRecordVideoPath");
|
//
|
// ngxMap.put("DSVAD010120181119","http://58.118.225.79:44180/videosource");
|
// ngxMap.put("DSVAD010220181119", "http://58.118.225.79:44280/videosource");
|
// ngxMap.put("DSVAD010320181119", "http://58.118.225.79:44380/videosource");
|
// ngxMap.put("DSVAD010420181119", "http://58.118.225.79:44480/videosource");
|
}
|
|
|
}
|
|
public static String getVideoUrl(Map<String, String> alarm) {
|
String videoUrl = "";
|
try {
|
String indeviceId = alarm.get(Alarm.indeviceid);//"DSVAD010120181119";
|
String url = deviceMap.get(indeviceId);
|
if (url == null) {
|
return videoUrl;
|
}
|
|
URL url1 = new URL(url);
|
HttpURLConnection conn = (HttpURLConnection) url1.openConnection();
|
conn.setConnectTimeout(5000);
|
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
conn.setDoOutput(true);
|
conn.setDoInput(true);
|
conn.setRequestMethod("POST");
|
|
|
Map<String, String> map1 = new HashMap<>();
|
map1.put("imgKey", alarm.get(Alarm.imgKey));
|
map1.put("picDate", alarm.get(Alarm.picDate));
|
map1.put("videoNum", alarm.get(Alarm.videoReqNum));
|
System.out.println("VideoPath.getVideoUrl " + map1);
|
|
String json = gson1.toJson(map1);
|
|
OutputStream os = conn.getOutputStream();
|
os.write(json.getBytes("UTF-8"));
|
os.close();
|
|
|
InputStream in = new BufferedInputStream(conn.getInputStream());
|
String out = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
|
|
Map map = gson.fromJson(out, Map.class);
|
String filePath = (String) map.get("file_path");
|
if (filePath != null && filePath.contains("/cut")) {
|
String ngxUrl = ngxMap.get(indeviceId);
|
if (!TextUtils.isEmpty(ngxUrl)) {
|
videoUrl = ngxUrl + filePath.split("/cut")[1];
|
}
|
}
|
in.close();
|
conn.disconnect();
|
} catch (Exception e) {
|
System.out.println("VideoPath.getVideoUrl " + e.getMessage());
|
}
|
return videoUrl;
|
}
|
|
public static void main(String[] args) {
|
// 11-12 09:57:26.694 2032-2121/com.basic.security I/System.out: VideoPath.getVideoUrl {videoNum=210235C2TM3188000194, imgKey=210235C2TM3188000194$2019-11-12-09-36-38_56200, picDate=2019-11-12 09:36:39:096}
|
// 11-12 09:57:26.722 2032-2121/com.basic.security I/System.out: VideoPath.getVideoUrl {"videoNum":"210235C2TM3188000194","imgKey":"210235C2TM3188000194$2019-11-12-09-36-38_56200","picDate":"2019-11-12 09:36:39:096"}
|
// 11-12 09:57:26.727 2032-2121/com.basic.security I/System.out: VideoPath.getVideoUrl application/json
|
|
|
Map<String, String> alarm = new HashMap<>();
|
alarm.put(Alarm.imgKey, "210235C2TM3188000194$2019-11-12-09-36-38_56200");
|
alarm.put(Alarm.alarmTime, "2019-11-12 09:36:39:096");
|
alarm.put(Alarm.indeviceid, "DSVAD010220181119");
|
alarm.put(Alarm.videoReqNum, "210235C2TM3188000194");
|
String videoUrl = getVideoUrl(alarm);
|
System.out.println(videoUrl);
|
}
|
|
}
|