获取监控视频接口改为动态的
This commit is contained in:
parent
64e85926ed
commit
83ba7cd354
@ -6,6 +6,12 @@ import cn.hutool.http.HttpResponse;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.fastbee.common.holder.ProjectHolder;
|
||||
import com.fastbee.deviceData.domain.NgYingshiCloudIntegrationInfo;
|
||||
import com.fastbee.deviceData.mapper.NgYingshiCloudIntegrationInfoMapper;
|
||||
import com.fastbee.deviceInfo.domain.DeviceInformationMonitor;
|
||||
import com.fastbee.deviceInfo.mapper.DeviceInformationMonitorMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -13,6 +19,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -22,16 +29,25 @@ public class YingshiyunService {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
@Autowired
|
||||
private DeviceInformationMonitorMapper deviceInformationMonitorMapper;
|
||||
@Autowired
|
||||
private NgYingshiCloudIntegrationInfoMapper ngYingshiCloudIntegrationInfoMapper;
|
||||
|
||||
//获取鉴权
|
||||
public String getAuth(){
|
||||
if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("yingshiyun:user:accessToken"))){
|
||||
public String getAuth(String appKey,String appSecret){
|
||||
/*if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("yingshiyun:user:accessToken"))){
|
||||
System.err.println(stringRedisTemplate.opsForValue().get("yingshiyun:user:accessToken"));
|
||||
return stringRedisTemplate.opsForValue().get("yingshiyun:user:accessToken");
|
||||
}*/
|
||||
if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("yingshiyun:user"+appKey+":"+appSecret+":accessToken"))){
|
||||
System.err.println(stringRedisTemplate.opsForValue().get("yingshiyun:user"+appKey+":"+appSecret+":accessToken"));
|
||||
return stringRedisTemplate.opsForValue().get("yingshiyun:user"+appKey+":"+appSecret+":accessToken");
|
||||
}
|
||||
// 鉴权请求
|
||||
String AUTH_URL = "https://open.ys7.com/api/lapp/token/get";
|
||||
String appKey = "b21f910dc7044d668e7625a3c0392e62";
|
||||
String appSecret = "b4beff5f8f6694dd6993c8c5b618417b";
|
||||
/*String appKey = "b21f910dc7044d668e7625a3c0392e62";
|
||||
String appSecret = "b4beff5f8f6694dd6993c8c5b618417b";*/
|
||||
// 构建请求体参数
|
||||
String body = StrUtil.format("appKey={}&appSecret={}", appKey, appSecret);
|
||||
HttpResponse response = HttpRequest.post(AUTH_URL)
|
||||
@ -45,21 +61,68 @@ public class YingshiyunService {
|
||||
JSONObject data = JSONUtil.parseObj(jsonObject.get("data"));
|
||||
String accessToken = data.get("accessToken").toString();
|
||||
|
||||
stringRedisTemplate.opsForValue().set("yingshiyun:user:accessToken",accessToken, 60*60*24*6, TimeUnit.MILLISECONDS);
|
||||
//stringRedisTemplate.opsForValue().set("yingshiyun:user:accessToken",accessToken, 60*60*24*6, TimeUnit.MILLISECONDS);
|
||||
stringRedisTemplate.opsForValue().set("yingshiyun:user"+appKey+":"+appSecret+":accessToken",accessToken, 60*60*24*6, TimeUnit.MILLISECONDS);
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
//获取视频播放地址
|
||||
public Map<String,Object> getVideoPlayUrl(String deviceSerial){
|
||||
String accessToken = getAuth();
|
||||
// System.err.println(accessToken);
|
||||
/**
|
||||
* 根据设备编码查找项目id,根据项目id查找萤石云对接账号信息
|
||||
*/
|
||||
System.err.println("deviceSerial:"+deviceSerial);
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
List<DeviceInformationMonitor> monitorList=new LambdaQueryChainWrapper<>(deviceInformationMonitorMapper)
|
||||
.select(DeviceInformationMonitor::getProjectId)
|
||||
.eq(DeviceInformationMonitor::getDeviceEncoding,deviceSerial)
|
||||
.list();
|
||||
if(monitorList.size()==0)
|
||||
{
|
||||
System.err.println("设备信息未找到");
|
||||
return map;
|
||||
}
|
||||
Long projectId=monitorList.get(0).getProjectId();
|
||||
/*String projectId=ProjectHolder.getProjectInfo().getProjectId();
|
||||
System.err.println("projectId:"+projectId);*/
|
||||
List<NgYingshiCloudIntegrationInfo> infoList=new LambdaQueryChainWrapper<>(ngYingshiCloudIntegrationInfoMapper)
|
||||
.select(NgYingshiCloudIntegrationInfo::getAppkey,NgYingshiCloudIntegrationInfo::getAppsecret)
|
||||
.eq(NgYingshiCloudIntegrationInfo::getProjectid,projectId)
|
||||
.list();
|
||||
if(infoList.size()==0)
|
||||
{
|
||||
System.err.println("萤石云信息不存在");
|
||||
return map;
|
||||
}
|
||||
String accessToken = getAuth(infoList.get(0).getAppkey(),infoList.get(0).getAppsecret());
|
||||
System.err.println(accessToken);
|
||||
String VIDEO_PLAY_URL = "https://open.ys7.com/api/lapp/v2/live/address/get";
|
||||
|
||||
String body = StrUtil.format("accessToken={}&deviceSerial={}&protocol={}",accessToken ,deviceSerial,"2");
|
||||
|
||||
HttpResponse response = HttpRequest.post(VIDEO_PLAY_URL)
|
||||
.body(body).execute();
|
||||
JSONObject jsonObject = JSONUtil.parseObj(response.body());
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
System.err.println("jsonObject:"+jsonObject);
|
||||
|
||||
if(jsonObject.get("code").toString().equals("60019"))
|
||||
{
|
||||
//如果设备加密
|
||||
//解密
|
||||
String VIDEO_DECODE_URL = "https://open.ys7.com/api/lapp/device/encrypt/off";
|
||||
String decodeBody=StrUtil.format("accessToken={}&deviceSerial={}",accessToken ,deviceSerial);
|
||||
HttpResponse decodeResponse=HttpRequest.post(VIDEO_DECODE_URL).body(decodeBody).execute();
|
||||
JSONObject decodeJsonObject=JSONUtil.parseObj(decodeResponse.body());
|
||||
System.err.println("decodeJsonObject:"+decodeJsonObject);
|
||||
if(!decodeJsonObject.get("code").toString().equals("200"))
|
||||
{
|
||||
return map;
|
||||
}
|
||||
response = HttpRequest.post(VIDEO_PLAY_URL)
|
||||
.body(body).execute();
|
||||
jsonObject = JSONUtil.parseObj(response.body());
|
||||
System.err.println("解密后jsonObject:"+jsonObject);
|
||||
}
|
||||
if(!jsonObject.get("code").toString().equals("200")){
|
||||
return map;
|
||||
}
|
||||
@ -71,6 +134,8 @@ public class YingshiyunService {
|
||||
|
||||
map.put("playUrl",playUrl);
|
||||
map.put("accessToken",accessToken);
|
||||
System.err.println("playUrl:"+playUrl);
|
||||
System.err.println("accessToken:"+accessToken);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user