From 42a2772d1aa7493bcc4fac3e24ee8eda4eebc23d Mon Sep 17 00:00:00 2001
From: xubinbin <1323875150@qq.com>
Date: 星期二, 12 十二月 2023 17:09:04 +0800
Subject: [PATCH] bugfix:请求头带token, SecurityUtils 获取用户id 一直为0 #1195

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java |   42 ++++++++++++++++++------------------------
 1 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java
old mode 100644
new mode 100755
index 4ad39a9..0b23a9c
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java
@@ -1,13 +1,15 @@
 package com.genersoft.iot.vmp.vmanager.gb28181.media;
 
 import com.genersoft.iot.vmp.common.StreamInfo;
+import com.genersoft.iot.vmp.conf.exception.ControllerException;
 import com.genersoft.iot.vmp.conf.security.SecurityUtils;
 import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
 import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
-import com.genersoft.iot.vmp.service.IStreamProxyService;
 import com.genersoft.iot.vmp.service.IMediaService;
+import com.genersoft.iot.vmp.service.IStreamProxyService;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
-import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
+import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -22,7 +24,7 @@
 
 @Tag(name  = "濯掍綋娴佺浉鍏�")
 @Controller
-@CrossOrigin
+
 @RequestMapping(value = "/api/media")
 public class MediaController {
 
@@ -51,22 +53,21 @@
     @Parameter(name = "useSourceIpAsStreamIp", description = "鏄惁浣跨敤璇锋眰IP浣滀负杩斿洖鐨勫湴鍧�IP")
     @GetMapping(value = "/stream_info_by_app_and_stream")
     @ResponseBody
-    public WVPResult<StreamInfo> getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app,
-                                                             @RequestParam String stream,
-                                                             @RequestParam(required = false) String mediaServerId,
-                                                             @RequestParam(required = false) String callId,
-                                                             @RequestParam(required = false) Boolean useSourceIpAsStreamIp){
+    public StreamContent getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app,
+                                                     @RequestParam String stream,
+                                                     @RequestParam(required = false) String mediaServerId,
+                                                     @RequestParam(required = false) String callId,
+                                                     @RequestParam(required = false) Boolean useSourceIpAsStreamIp){
         boolean authority = false;
         if (callId != null) {
             // 鏉冮檺鏍¢獙
             StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
-            if (streamAuthorityInfo.getCallId().equals(callId)) {
+            if (streamAuthorityInfo != null
+                    && streamAuthorityInfo.getCallId() != null
+                    && streamAuthorityInfo.getCallId().equals(callId)) {
                 authority = true;
             }else {
-                WVPResult<StreamInfo> result = new WVPResult<>();
-                result.setCode(401);
-                result.setMsg("fail");
-                return result;
+                throw new ControllerException(ErrorCode.ERROR400.getCode(), "鑾峰彇鎾斁鍦板潃閴存潈澶辫触");
             }
         }else {
             // 鏄惁鐧婚檰鐢ㄦ埛, 鐧婚檰鐢ㄦ埛杩斿洖瀹屾暣淇℃伅
@@ -87,11 +88,8 @@
             streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
         }
 
-        WVPResult<StreamInfo> result = new WVPResult<>();
         if (streamInfo != null){
-            result.setCode(0);
-            result.setMsg("scccess");
-            result.setData(streamInfo);
+            return  new StreamContent(streamInfo);
         }else {
             //鑾峰彇娴佸け璐ワ紝閲嶅惎鎷夋祦鍚庨噸璇曚竴娆�
             streamProxyService.stop(app,stream);
@@ -99,7 +97,7 @@
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
-                e.printStackTrace();
+                logger.error("[绾跨▼浼戠湢澶辫触]锛� {}", e.getMessage());
             }
             if (useSourceIpAsStreamIp != null && useSourceIpAsStreamIp) {
                 String host = request.getHeader("Host");
@@ -110,14 +108,10 @@
                 streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
             }
             if (streamInfo != null){
-                result.setCode(0);
-                result.setMsg("scccess");
-                result.setData(streamInfo);
+                return new StreamContent(streamInfo);
             }else {
-                result.setCode(-1);
-                result.setMsg("fail");
+                throw new ControllerException(ErrorCode.ERROR100);
             }
         }
-        return result;
     }
 }

--
Gitblit v1.8.0