| 
									
										
										
										
											2021-04-30 10:28:37 +08:00
										 |  |  |  | using BLL; | 
					
						
							|  |  |  |  | using Newtonsoft.Json; | 
					
						
							|  |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using System.Configuration; | 
					
						
							|  |  |  |  | using System.Web.Http; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace WebAPI.Controllers | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     ///  | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     public class VideoController : ApiController | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         ///  | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         /// <param name="projectId"></param> | 
					
						
							|  |  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |  |         public Model.ResponeData getVideoInfor(string projectId) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             Model.ResponeData responeData = new Model.ResponeData(); | 
					
						
							|  |  |  |  |             try | 
					
						
							| 
									
										
										
										
											2025-09-13 13:22:33 +08:00
										 |  |  |  |             {                | 
					
						
							| 
									
										
										
										
											2021-10-28 18:10:38 +08:00
										 |  |  |  |                 string url =ConfigurationManager.AppSettings["Video_URL"]; | 
					
						
							| 
									
										
										
										
											2025-09-13 13:22:33 +08:00
										 |  |  |  |                 var project = BLL.ProjectService.GetProjectByProjectId(projectId); | 
					
						
							|  |  |  |  |                 string URLToken = ""; | 
					
						
							|  |  |  |  |                 String restoken = BLL.CommonService.CreateGetHttpResponse(url + "api/v1/login?username=" + project.ProjectCode + "&password=" + Funs.EncryptionPassword(project.MonitorPW)); | 
					
						
							|  |  |  |  |                 Dictionary<string, string> dicres = JsonConvert.DeserializeObject<Dictionary<string, string>>(restoken); | 
					
						
							|  |  |  |  |                 URLToken = dicres["URLToken"]; | 
					
						
							| 
									
										
										
										
											2021-04-30 10:28:37 +08:00
										 |  |  |  |                 List<Dictionary<string, string>> data = new List<Dictionary<string, string>>(); | 
					
						
							|  |  |  |  |                 responeData.data = data; | 
					
						
							|  |  |  |  |                 List<string> urls = new List<string>(); | 
					
						
							| 
									
										
										
										
											2025-09-13 13:22:33 +08:00
										 |  |  |  |                 string res = APIGetHttpService.Http(url + "api/v1/device/channeltree?token=" + URLToken); | 
					
						
							| 
									
										
										
										
											2021-04-30 10:28:37 +08:00
										 |  |  |  |                 List<Dictionary<string, string>> jsonNvr = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(res); | 
					
						
							|  |  |  |  |                 foreach (Dictionary<string, string> nvr in jsonNvr) | 
					
						
							|  |  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2025-09-13 13:22:33 +08:00
										 |  |  |  |                     | 
					
						
							|  |  |  |  |                         string jsonCameras = APIGetHttpService.Http(url + "api/v1/device/channeltree?serial=" + nvr["serial"]+ "&token="+URLToken); | 
					
						
							| 
									
										
										
										
											2021-04-30 10:28:37 +08:00
										 |  |  |  |                         data.AddRange(JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(jsonCameras)); | 
					
						
							| 
									
										
										
										
											2025-09-13 13:22:33 +08:00
										 |  |  |  |                      | 
					
						
							| 
									
										
										
										
											2021-04-30 10:28:37 +08:00
										 |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             catch (Exception ex) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 responeData.code = 0; | 
					
						
							|  |  |  |  |                 responeData.message = ex.Message; | 
					
						
							| 
									
										
										
										
											2021-10-28 18:10:38 +08:00
										 |  |  |  |                 ErrLogInfo.WriteLog(ex, "WX接口-监控视频", "VideoController.getVideoInfor"); | 
					
						
							| 
									
										
										
										
											2021-04-30 10:28:37 +08:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             return responeData; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         ///  | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         /// <param name="projectId"></param> | 
					
						
							|  |  |  |  |         /// <param name="serial"></param> | 
					
						
							|  |  |  |  |         /// <param name="code"></param> | 
					
						
							|  |  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |  |         public Model.ResponeData getVideoUrl(string projectId, string serial, string code) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             var responeData = new Model.ResponeData(); | 
					
						
							|  |  |  |  |             try | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-13 13:22:33 +08:00
										 |  |  |  |                 string url = ConfigurationManager.AppSettings["Video_URL"]; | 
					
						
							|  |  |  |  |                 var project = BLL.ProjectService.GetProjectByProjectId(projectId); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 string URLToken = ""; | 
					
						
							|  |  |  |  |                 String restoken = BLL.CommonService.CreateGetHttpResponse(url + "api/v1/login?username=" + project.ProjectCode + "&password=" + Funs.EncryptionPassword(project.MonitorPW)); | 
					
						
							|  |  |  |  |                 Dictionary<string, string> dicres = JsonConvert.DeserializeObject<Dictionary<string, string>>(restoken); | 
					
						
							|  |  |  |  |                 URLToken = dicres["URLToken"]; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                  | 
					
						
							| 
									
										
										
										
											2021-04-30 10:28:37 +08:00
										 |  |  |  |                 var stmp = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds() + ""; | 
					
						
							| 
									
										
										
										
											2025-09-13 13:22:33 +08:00
										 |  |  |  |                 string jsonCamera = APIGetHttpService.Http(url + "api/v1/stream/start?token="+URLToken+"&serial=" + serial + "&code=" + code + "&_=" + stmp); | 
					
						
							| 
									
										
										
										
											2021-04-30 10:28:37 +08:00
										 |  |  |  |                 responeData.data = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonCamera); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             catch (Exception ex) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 responeData.code = 0; | 
					
						
							|  |  |  |  |                 responeData.message = ex.Message; | 
					
						
							| 
									
										
										
										
											2021-10-28 18:10:38 +08:00
										 |  |  |  |                 ErrLogInfo.WriteLog(ex, "WX接口-监控视频", "VideoController.getVideoUrl"); | 
					
						
							| 
									
										
										
										
											2021-04-30 10:28:37 +08:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             return responeData; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |