Browse Source

实时轨迹 流媒体修改

S0025136190 1 year ago
parent
commit
11c4c1dc9b

+ 3 - 0
Backend/sample/src/main/java/com/dji/sample/common/smsp/CallSmsp.java

@@ -79,6 +79,9 @@ public class CallSmsp {
                     }
                     }
                 }
                 }
             }
             }
+//            if(response.get("message") != null) {
+//                resultList
+//            }
             return resultList;
             return resultList;
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();

+ 13 - 48
Backend/sample/src/main/java/com/dji/sample/component/AuthInterceptor.java

@@ -7,6 +7,7 @@ import cn.hutool.crypto.digest.DigestUtil;
 import com.dji.sample.common.error.CommonErrorEnum;
 import com.dji.sample.common.error.CommonErrorEnum;
 import com.dji.sample.common.model.CustomClaim;
 import com.dji.sample.common.model.CustomClaim;
 import com.dji.sample.common.util.JwtUtil;
 import com.dji.sample.common.util.JwtUtil;
+import com.dji.sample.component.mqtt.config.MqttPropertyConfiguration;
 import com.dji.sample.configuration.CustomConfiguration;
 import com.dji.sample.configuration.CustomConfiguration;
 import com.dji.sample.manage.model.entity.UserEntity;
 import com.dji.sample.manage.model.entity.UserEntity;
 import com.dji.sample.manage.service.IUserService;
 import com.dji.sample.manage.service.IUserService;
@@ -58,47 +59,6 @@ public class AuthInterceptor implements HandlerInterceptor {
             return false;
             return false;
         }
         }
         String token = request.getHeader(PARAM_TOKEN);
         String token = request.getHeader(PARAM_TOKEN);
-        String sign = request.getHeader(SIGN);
-        if (StringUtils.hasText(sign)) {
-            if ("GET".equalsIgnoreCase(request.getMethod())) {
-                // Get sign from the query string
-                String key = request.getHeader(KEY);
-                String userCode = request.getHeader(USER_CODE);
-                UserEntity userEntity = userService.getUserByUsername(userCode);
-                if (userEntity == null) {
-                    response.setStatus(HttpStatus.UNAUTHORIZED.value());
-                    log.error(CommonErrorEnum.NO_TOKEN.getMessage());
-                    return false;
-                }
-                byte[] decodedBytes = Base64.decode(key);
-                String decodedString = new String(decodedBytes);
-                // Step 1: Parse the date-time string
-                String dateTimeString = extractDateTime(decodedString,userCode);
-                // Step 2: Convert the date-time string to LocalDateTime
-                LocalDateTime dateTime = parseTimestamp(dateTimeString);
-                // Step 3: Calculate the difference between the current time and the extracted time
-                LocalDateTime currentTime = LocalDateTime.now();
-                Duration duration = Duration.between(dateTime, currentTime);
-
-                // Step 4: Check if the difference is greater than 5 minutes
-                boolean isMoreThanFiveMinutes = duration.toMinutes() > 5;
-                if (isMoreThanFiveMinutes) {
-                    response.setStatus(HttpStatus.UNAUTHORIZED.value());
-                    log.error(CommonErrorEnum.NO_TOKEN.getMessage());
-                    return false;
-                }
-                String generatedHash = DigestUtil.sha256Hex(userCode+decodedString+ CustomConfiguration.signKey);
-                // Verify the hash
-                boolean isMatch = StrUtil.equals(generatedHash, sign);
-                if(!isMatch) {
-                    response.setStatus(HttpStatus.UNAUTHORIZED.value());
-                    log.error(CommonErrorEnum.NO_TOKEN.getMessage());
-                    return false;
-                }
-                return true;
-            }
-        }
-        // Check if the token exists.
         if (!StringUtils.hasText(token)) {
         if (!StringUtils.hasText(token)) {
             response.setStatus(HttpStatus.UNAUTHORIZED.value());
             response.setStatus(HttpStatus.UNAUTHORIZED.value());
             log.error(CommonErrorEnum.NO_TOKEN.getMessage());
             log.error(CommonErrorEnum.NO_TOKEN.getMessage());
@@ -148,12 +108,17 @@ public class AuthInterceptor implements HandlerInterceptor {
     }
     }
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
-        String aa = "adminPC1722596411adminPC";
-        String ab = Base64.encode(aa);
-        String ac =DigestUtil.sha256Hex("adminPC"+aa+CustomConfiguration.signKey);
-        System.out.println("base:"+ab+"ac"+ac);
-        System.out.println("adminPC"+aa+CustomConfiguration.signKey);
-        System.out.println("adminPC"+aa+CustomConfiguration.signKey);
-        System.out.println(DigestUtil.sha256Hex("adminPCadminPC1722596411adminPC7e92430eb1f949e9a750fadf68777c44"));
+        String username = "apminPC";
+        String client_id = "e534550a85d94faba22e8040e76514bc";
+        String workspace_id = "e3dea0f5-37f2-4d79-a3q8-490af3228070";
+        String workspace_name = "测试";
+        Long timestamp = Long.parseLong("1722932935");
+        String dataInput  = client_id+timestamp+username+workspace_id+workspace_name;
+        String generatedHash = DigestUtil.sha256Hex(dataInput.toUpperCase()+"7e92430eb1f949e9a750fadf68777c44");
+        //String ac =DigestUtil.sha256Hex("adminPC"+aa+CustomConfiguration.signKey);
+        System.out.println("base:"+generatedHash);
+
+        //System.out.println("mq:"+mqttPropertyConfiguration.mqttConnectOptions().getUserName());
+        //System.out.println(DigestUtil.sha256Hex("apminapmin1722844106apmin7e92430eb1f949e9a750fadf68777c44"));
     }
     }
 }
 }

+ 11 - 0
Backend/sample/src/main/java/com/dji/sample/configuration/CustomConfiguration.java

@@ -43,6 +43,13 @@ public class CustomConfiguration {
      */
      */
     public static String smspRtmpUrl;
     public static String smspRtmpUrl;
 
 
+
+    /**
+     * 获取clientId
+     * @param smspRtmpUrl
+     */
+    public static String clientId;
+
     public void setFrequency(int frequency) {
     public void setFrequency(int frequency) {
         CustomConfiguration.frequency = frequency;
         CustomConfiguration.frequency = frequency;
     }
     }
@@ -62,6 +69,10 @@ public class CustomConfiguration {
     public void setSmspRtmpUrl(String smspRtmpUrl) {
     public void setSmspRtmpUrl(String smspRtmpUrl) {
         CustomConfiguration.smspRtmpUrl = smspRtmpUrl;
         CustomConfiguration.smspRtmpUrl = smspRtmpUrl;
     }
     }
+
+    public void setClientId(String clientId) {
+        CustomConfiguration.clientId = clientId;
+    }
 }
 }
 
 
 
 

+ 2 - 1
Backend/sample/src/main/java/com/dji/sample/manage/service/impl/LiveStreamServiceImpl.java

@@ -106,7 +106,8 @@ public class LiveStreamServiceImpl implements ILiveStreamService {
                         .setVideoQuality(liveParam.getVideoQuality()));
                         .setVideoQuality(liveParam.getVideoQuality()));
 
 
         if (!response.getData().getResult().isSuccess()) {
         if (!response.getData().getResult().isSuccess()) {
-            return HttpResultResponse.error(response.getData().getResult());
+            throw new RuntimeException(response.getData().getResult().getMessage());
+            //return HttpResultResponse.error(response.getData().getResult());
         }
         }
 
 
         LiveDTO live = new LiveDTO();
         LiveDTO live = new LiveDTO();

+ 29 - 34
Backend/sample/src/main/java/com/dji/sample/manage/service/impl/ManageDeviceLivestreamUrlServiceImpl.java

@@ -3,6 +3,7 @@ package com.dji.sample.manage.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.dji.sample.common.smsp.CallSmsp;
 import com.dji.sample.common.smsp.CallSmsp;
 import com.dji.sample.common.util.DesUtil;
 import com.dji.sample.common.util.DesUtil;
+import com.dji.sample.configuration.CustomConfiguration;
 import com.dji.sample.manage.dao.IDevicePayloadMapper;
 import com.dji.sample.manage.dao.IDevicePayloadMapper;
 import com.dji.sample.manage.dao.IManageDeviceLivestreamUrlMapper;
 import com.dji.sample.manage.dao.IManageDeviceLivestreamUrlMapper;
 import com.dji.sample.manage.dao.IUserMapper;
 import com.dji.sample.manage.dao.IUserMapper;
@@ -22,6 +23,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
@@ -38,21 +40,17 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
     @Autowired
     @Autowired
     private IManageDeviceLivestreamUrlMapper mapper;
     private IManageDeviceLivestreamUrlMapper mapper;
 
 
-    @Autowired
-    private IDevicePayloadMapper payloadMapper;
-
-    private final String clientId = "e534550a85d94faba73e8040e76514bc";
 
 
     @Override
     @Override
     public ManageDeviceLivestreamUrlDTO getUrl(ManageDeviceLivestreamUrlDTO deviceLivestreamUrlDTO) {
     public ManageDeviceLivestreamUrlDTO getUrl(ManageDeviceLivestreamUrlDTO deviceLivestreamUrlDTO) {
 
 
 
 
         QueryWrapper<UserEntity> userWrapper = new QueryWrapper<>();
         QueryWrapper<UserEntity> userWrapper = new QueryWrapper<>();
-        userWrapper.lambda().eq(UserEntity::getUserType, UserTypeEnum.API.getVal()).eq(UserEntity::getClientId,clientId);
+        userWrapper.lambda().eq(UserEntity::getUserType, UserTypeEnum.API.getVal()).eq(UserEntity::getClientId, CustomConfiguration.clientId);
         UserEntity userEntity = userMapper.selectOne(userWrapper);
         UserEntity userEntity = userMapper.selectOne(userWrapper);
         if (userEntity == null) {
         if (userEntity == null) {
             log.debug("The user is null.");
             log.debug("The user is null.");
-            return null;
+            throw new RuntimeException ("The user is null.");
         }
         }
         //密码解密
         //密码解密
         String password = DesUtil.getDecryptData(userEntity.getPassword(),userEntity.getSalt());
         String password = DesUtil.getDecryptData(userEntity.getPassword(),userEntity.getSalt());
@@ -75,6 +73,9 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
             log.debug("The result is null.");
             log.debug("The result is null.");
             throw new RuntimeException (tokenMap.get("message"));
             throw new RuntimeException (tokenMap.get("message"));
         }
         }
+        List<Integer> urlL = urlList.stream()
+                .map(ManageDeviceLivestreamUrlEntity::getChannelId)
+                .collect(Collectors.toList());
         //过滤payloadIndex
         //过滤payloadIndex
         List<ManageDeviceLivestreamUrlEntity> filterIndexList = urlList.stream().filter(channelData -> deviceLivestreamUrlDTO.getPayloadIndex().equals(channelData.getPayloadIndex()))
         List<ManageDeviceLivestreamUrlEntity> filterIndexList = urlList.stream().filter(channelData -> deviceLivestreamUrlDTO.getPayloadIndex().equals(channelData.getPayloadIndex()))
                 .collect(Collectors.toList());
                 .collect(Collectors.toList());
@@ -83,45 +84,23 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
             List<ManageDeviceLivestreamUrlDTO> channelList = rtmpList.stream().filter(channelData -> filterIndexList.get(0).getChannelId().equals(channelData.getChannelId()))
             List<ManageDeviceLivestreamUrlDTO> channelList = rtmpList.stream().filter(channelData -> filterIndexList.get(0).getChannelId().equals(channelData.getChannelId()))
                     .collect(Collectors.toList());
                     .collect(Collectors.toList());
             if (channelList.size() > 0) {
             if (channelList.size() > 0) {
-                //判断url是否一致
-                for(ManageDeviceLivestreamUrlEntity url : filterIndexList) {
-                    if (url.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())) {
-                        if(!url.getUrl().equals(channelList.get(0).getRtmpUrl())) {
-                            url.setUrl(channelList.get(0).getRtmpUrl());
-                            mapper.updateById(url);}
-                    } else if(url.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())) {
-                        if(!url.getUrl().equals(channelList.get(0).getWebRtcUrl())) {
-                            url.setUrl(channelList.get(0).getWebRtcUrl());
-                            mapper.updateById(url);
-                        }
-                    }
-                }
+                update(filterIndexList,channelList);
                 rtmpDto.setRtmpUrl(channelList.get(0).getRtmpUrl());
                 rtmpDto.setRtmpUrl(channelList.get(0).getRtmpUrl());
                 rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
                 rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
             } else {
             } else {
                 if(rtmpList.size() > 0) {
                 if(rtmpList.size() > 0) {
                     //过滤channelId
                     //过滤channelId
-                    channelList = rtmpList.stream().filter(channelData -> !urlList.contains(channelData.getChannelId()))
+                    channelList = rtmpList.stream().filter(channelData -> !urlL.contains(channelData.getChannelId()))
                             .collect(Collectors.toList());
                             .collect(Collectors.toList());
-                    for(ManageDeviceLivestreamUrlEntity url : filterIndexList) {
-                        url.setChannelId(channelList.get(0).getChannelId());
-
-                        if (url.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())) {
-                            url.setUrl(channelList.get(0).getRtmpUrl());
-                            mapper.updateById(url);
-                        } else if(url.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())) {
-                            url.setUrl(channelList.get(0).getWebRtcUrl());
-                            mapper.updateById(url);
-                        }
-                    }
+                    update(filterIndexList,channelList);
                     rtmpDto.setRtmpUrl(channelList.get(0).getRtmpUrl());
                     rtmpDto.setRtmpUrl(channelList.get(0).getRtmpUrl());
                     rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
                     rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
                 } else {
                 } else {
                     for(ManageDeviceLivestreamUrlEntity url : filterIndexList) {
                     for(ManageDeviceLivestreamUrlEntity url : filterIndexList) {
                         if (url.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())) {
                         if (url.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())) {
-                            rtmpDto.setRtmpUrl(channelList.get(0).getRtmpUrl());
+                            rtmpDto.setRtmpUrl(url.getUrl());
                         } else if(url.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())) {
                         } else if(url.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())) {
-                            rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
+                            rtmpDto.setWebRtcUrl(url.getUrl());
                         }
                         }
                     }
                     }
                 }
                 }
@@ -129,8 +108,9 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
         } else {
         } else {
             //过滤channelId
             //过滤channelId
             List<ManageDeviceLivestreamUrlDTO> channelList = rtmpList;
             List<ManageDeviceLivestreamUrlDTO> channelList = rtmpList;
+
             if(urlList.size() > 0) {
             if(urlList.size() > 0) {
-                channelList = rtmpList.stream().filter(channelData -> urlList.contains(channelData.getChannelId()))
+                channelList = rtmpList.stream().filter(channelData -> !urlL.contains(channelData.getChannelId()))
                         .collect(Collectors.toList());
                         .collect(Collectors.toList());
             }
             }
             ManageDeviceLivestreamUrlEntity urlEntity = new ManageDeviceLivestreamUrlEntity();
             ManageDeviceLivestreamUrlEntity urlEntity = new ManageDeviceLivestreamUrlEntity();
@@ -157,4 +137,19 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
         }
         }
         return rtmpDto;
         return rtmpDto;
     }
     }
+
+    private void update(List<ManageDeviceLivestreamUrlEntity> entitys,List<ManageDeviceLivestreamUrlDTO> dtos) {
+        for(ManageDeviceLivestreamUrlEntity url : entitys) {
+            url.setChannelId(dtos.get(0).getChannelId());
+            if (url.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())) {
+                url.setUrl(dtos.get(0).getRtmpUrl());
+                mapper.updateById(url);
+            } else if(url.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())) {
+                url.setUrl(dtos.get(0).getWebRtcUrl());
+                mapper.updateById(url);
+            }
+        }
+    }
+
+
 }
 }

+ 11 - 6
Backend/sample/src/main/java/com/dji/sample/manage/service/impl/SDKDeviceService.java

@@ -71,6 +71,9 @@ public class SDKDeviceService extends AbstractDeviceService {
     @Autowired
     @Autowired
     private IFlightTrackTaskService flightTaskService;
     private IFlightTrackTaskService flightTaskService;
 
 
+    // 定义一个静态变量来存储上次调用的时间戳
+    private static long lastInvocationTimestamp = 0;
+
     @Override
     @Override
     public TopicStatusResponse<MqttReply> updateTopoOnline(TopicStatusRequest<UpdateTopo> request, MessageHeaders headers) {
     public TopicStatusResponse<MqttReply> updateTopoOnline(TopicStatusRequest<UpdateTopo> request, MessageHeaders headers) {
         UpdateTopoSubDevice updateTopoSubDevice = request.getData().getSubDevices().get(0);
         UpdateTopoSubDevice updateTopoSubDevice = request.getData().getSubDevices().get(0);
@@ -301,15 +304,16 @@ public class SDKDeviceService extends AbstractDeviceService {
     private void pushFlyTrackToWeb(String from, DeviceDTO device,OsdRcDrone data) {
     private void pushFlyTrackToWeb(String from, DeviceDTO device,OsdRcDrone data) {
         //推送实时轨迹信息
         //推送实时轨迹信息
         List<FlightTrackDTO> trackList = getFlightLine(device);
         List<FlightTrackDTO> trackList = getFlightLine(device);
-        if(!CollectionUtils.isEmpty(trackList)) {
+        if (System.currentTimeMillis() - lastInvocationTimestamp >= 2000) {
+            if(!CollectionUtils.isEmpty(trackList)) {
+                lastInvocationTimestamp = System.currentTimeMillis();
+                deviceService.pushOsdDataToWeb(device.getWorkspaceId(), BizCodeEnum.DRONE_FLY_TRACK, from, trackList);
+            }
+            //模拟第二条实时航线
+            List<FlightTrackDTO> flightPoints =  flightTaskService.getRTFlightTrackByTaskId(44);
             deviceService.pushOsdDataToWeb(device.getWorkspaceId(), BizCodeEnum.DRONE_FLY_TRACK, from, trackList);
             deviceService.pushOsdDataToWeb(device.getWorkspaceId(), BizCodeEnum.DRONE_FLY_TRACK, from, trackList);
         }
         }
 
 
-        //模拟第二条实时航线
-        List<FlightTrackDTO> flightPoints =  flightTaskService.getRTFlightTrackByTaskId(44);
-        deviceService.pushOsdDataToWeb(device.getWorkspaceId(), BizCodeEnum.DRONE_FLY_TRACK, from, trackList);
-
-
     }
     }
 
 
     private List<FlightTrackDTO> getFlightLine(DeviceDTO device) {
     private List<FlightTrackDTO> getFlightLine(DeviceDTO device) {
@@ -723,4 +727,5 @@ public class SDKDeviceService extends AbstractDeviceService {
             deviceRedisService.setDeviceOsd(dockSn, oldDock);
             deviceRedisService.setDeviceOsd(dockSn, oldDock);
         }
         }
     }
     }
+
 }
 }

+ 2 - 1
Backend/sample/src/main/resources/application.yml

@@ -184,4 +184,5 @@ custom-config:
   key: b1uruk98vuk40cdego6jw5yv9tygjm3s
   key: b1uruk98vuk40cdego6jw5yv9tygjm3s
   signKey: 7e92430eb1f949e9a750fadf68777c44
   signKey: 7e92430eb1f949e9a750fadf68777c44
   smspTokenUrl: https://smsp.jkec.info:4443/api/v1/login
   smspTokenUrl: https://smsp.jkec.info:4443/api/v1/login
-  smspRtmpUrl: https://smsp.jkec.info:4443/api/v1/channelstream/all
+  smspRtmpUrl: https://smsp.jkec.info:4443/api/v1/channelstream/all
+  clientId: e534550a85d94faba73e8040e76514bc