张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.thhy.materials.modules.biz.video.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.thhy.general.common.BasicResult;
import com.thhy.materials.modules.biz.video.entity.TVideoNo;
import com.thhy.materials.modules.biz.video.service.VideoService;
import com.thhy.materials.modules.biz.weigh.mapper.WeighMapper;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
 
@Service
public class VideoServiceImpl implements VideoService {
 
 
    @Resource
    private WeighMapper weighMapper;
 
    @Override
    public BasicResult videoList() {
        List<TVideoNo> tVideoNos = weighMapper.videoList();
        return BasicResult.success(tVideoNos);
    }
 
    @Override
    public BasicResult webVideoList(Map<String,Object> values) {
        List<TVideoNo> tVideoNos = weighMapper.webVideoList(values);
        return BasicResult.success(tVideoNos);
    }
 
    @Override
    public BasicResult videoListPathWX(Map<String, Object> values) {
 
        Integer types = Integer.valueOf(values.get("types").toString());
 
        if(types==1){
            //安全token
            String accessToken = anquan();
            String deviceNum = values.get("deviceNum").toString();
            String channelNo = values.get("channelNo").toString();
            RestTemplate restTemplate6 = new RestTemplate();
            HttpHeaders headers6 = new HttpHeaders();
            headers6.setContentType(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE));
            HttpEntity<Map<String, Object>> mapHttpEntity6 = new HttpEntity<>(null, headers6);
            //String s6 = restTemplate.postForObject("https://open.ys7.com/api/lapp/live/address/limited?accessToken="+accessToken+"&deviceSerial="+videoNum+"&channelNo=1&expireTime=86400", mapHttpEntity6, String.class);
           //expireTime=300
            //地址过期时间:单位秒数,最大默认62208000(即720天),最小默认300(即5分钟)。非必选参数,为空时返回对应设备和通道的永久地址
            String s6 = restTemplate6.postForObject("https://open.ys7.com/api/lapp/live/address/limited?accessToken="+accessToken+"&deviceSerial="+deviceNum+"&channelNo="+channelNo, mapHttpEntity6, String.class);
            System.out.println(s6);
            JSONObject jsonObject = JSONObject.parseObject(s6);
            return BasicResult.success(jsonObject);
        }else if(types==2) {
            //现场
            //安全token
            String accessToken = xianchang();
            String deviceNum = values.get("deviceNum").toString();
            String channelNo = values.get("channelNo").toString();
            RestTemplate restTemplate6 = new RestTemplate();
            HttpHeaders headers6 = new HttpHeaders();
            headers6.setContentType(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE));
            HttpEntity<Map<String, Object>> mapHttpEntity6 = new HttpEntity<>(null, headers6);
            //String s6 = restTemplate.postForObject("https://open.ys7.com/api/lapp/live/address/limited?accessToken="+accessToken+"&deviceSerial="+videoNum+"&channelNo=1&expireTime=86400", mapHttpEntity6, String.class);
            //expireTime=300
            //地址过期时间:单位秒数,最大默认62208000(即720天),最小默认300(即5分钟)。非必选参数,为空时返回对应设备和通道的永久地址
            String s6 = restTemplate6.postForObject("https://open.ys7.com/api/lapp/live/address/limited?accessToken="+accessToken+"&deviceSerial="+deviceNum+"&channelNo="+channelNo, mapHttpEntity6, String.class);
            System.out.println(s6);
            JSONObject jsonObject = JSONObject.parseObject(s6);
            return BasicResult.success(jsonObject);
        }
        return null;
    }
 
 
    @Override
    public BasicResult videoListPath(Map<String, Object> values) {
 
        Integer types = Integer.valueOf(values.get("types").toString());
 
        if(types==1){
            //安全token
            String accessToken = anquan();
           /* String deviceNum = values.get("deviceNum").toString();
            String channelNo = values.get("channelNo").toString();
            RestTemplate restTemplate6 = new RestTemplate();
            HttpHeaders headers6 = new HttpHeaders();
            headers6.setContentType(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE));
            HttpEntity<Map<String, Object>> mapHttpEntity6 = new HttpEntity<>(null, headers6);
            //String s6 = restTemplate.postForObject("https://open.ys7.com/api/lapp/live/address/limited?accessToken="+accessToken+"&deviceSerial="+videoNum+"&channelNo=1&expireTime=86400", mapHttpEntity6, String.class);
           //expireTime=300
            //地址过期时间:单位秒数,最大默认62208000(即720天),最小默认300(即5分钟)。非必选参数,为空时返回对应设备和通道的永久地址
            String s6 = restTemplate6.postForObject("https://open.ys7.com/api/lapp/live/address/limited?accessToken="+accessToken+"&deviceSerial="+deviceNum+"&channelNo="+channelNo, mapHttpEntity6, String.class);
            System.out.println(s6);
            JSONObject jsonObject = JSONObject.parseObject(s6);*/
            return BasicResult.success(accessToken);
        }else if(types==2) {
            //现场
            //安全token
            String accessToken = xianchang();
//            String deviceNum = values.get("deviceNum").toString();
//            String channelNo = values.get("channelNo").toString();
//            RestTemplate restTemplate6 = new RestTemplate();
//            HttpHeaders headers6 = new HttpHeaders();
//            headers6.setContentType(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE));
//            HttpEntity<Map<String, Object>> mapHttpEntity6 = new HttpEntity<>(null, headers6);
//            //String s6 = restTemplate.postForObject("https://open.ys7.com/api/lapp/live/address/limited?accessToken="+accessToken+"&deviceSerial="+videoNum+"&channelNo=1&expireTime=86400", mapHttpEntity6, String.class);
//            //expireTime=300
//            //地址过期时间:单位秒数,最大默认62208000(即720天),最小默认300(即5分钟)。非必选参数,为空时返回对应设备和通道的永久地址
//            String s6 = restTemplate6.postForObject("https://open.ys7.com/api/lapp/live/address/limited?accessToken="+accessToken+"&deviceSerial="+deviceNum+"&channelNo="+channelNo, mapHttpEntity6, String.class);
//            System.out.println(s6);
//            JSONObject jsonObject = JSONObject.parseObject(s6);
            return BasicResult.success(accessToken);
        }
        return null;
    }
 
    @Override
    public BasicResult videoListPage(Map<String, Object> values) {
        Integer pageSize = Integer.valueOf(values.get("pageSize").toString());
        Integer pageNum = Integer.valueOf(values.get("pageNum").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<TVideoNo>  videoNos = weighMapper.videoListPage(values);
        PageInfo<TVideoNo> tVideoNoPageInfo = new PageInfo<>(videoNos);
        return BasicResult.success(tVideoNoPageInfo);
    }
 
    public String anquan(){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE));
        HttpEntity<Map<String, Object>> mapHttpEntity = new HttpEntity<>(null, headers);
        //现场
        String s = restTemplate.postForObject("https://open.ys7.com/api/lapp/token/get?appKey=bbd3ec70de864ae89ed1591706240ef7&appSecret=198508bb0f99ee0a945839093ac869c3", mapHttpEntity, String.class);
        //安全   外边厂房
       // String s = restTemplate.postForObject("https://open.ys7.com/api/lapp/token/get?appKey=6f3dc77270d14f9b965d9530138753e8&appSecret=5fb063a890fbe80e28fbaafecf4ffa2c", mapHttpEntity, String.class);
        JSONObject jsonObject = JSONObject.parseObject(s);
        System.out.println(jsonObject);
        Object data = jsonObject.get("data");
        String s1 = JSON.toJSONString(data);
        JSONObject data1 = JSONObject.parseObject(s1);
        System.out.println(data);
        Object accessToken = data1.get("accessToken");
        return  accessToken.toString();
    }
 
 
    public String xianchang(){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE));
        HttpEntity<Map<String, Object>> mapHttpEntity = new HttpEntity<>(null, headers);
        //现场
        //String s = restTemplate.postForObject("https://open.ys7.com/api/lapp/token/get?appKey=bbd3ec70de864ae89ed1591706240ef7&appSecret=198508bb0f99ee0a945839093ac869c3", mapHttpEntity, String.class);
        //安全   外边厂房
        String s = restTemplate.postForObject("https://open.ys7.com/api/lapp/token/get?appKey=6f3dc77270d14f9b965d9530138753e8&appSecret=5fb063a890fbe80e28fbaafecf4ffa2c", mapHttpEntity, String.class);
        JSONObject jsonObject = JSONObject.parseObject(s);
        System.out.println(jsonObject);
        Object data = jsonObject.get("data");
        String s1 = JSON.toJSONString(data);
        JSONObject data1 = JSONObject.parseObject(s1);
        System.out.println(data);
        Object accessToken = data1.get("accessToken");
        return  accessToken.toString();
    }
 
 
}