a
554325746@qq.com
2019-12-25 38492bbaa63586e2f4877da0eaa01a082fd565a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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);
    }
 
}