123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- using Microsoft.AspNetCore.DataProtection;
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json;
- using RabbitMQ.Client;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- namespace Ropin.Inspection.Common.Helper
- {
- public class LiveGBSHelper
- {
- public static string loginUrl= "http://124.71.132.255:10000/";
- private const string username = "admin";
- private const string password = "62582E39C499493DCBB1344A9BCB897B";
- private static GBSToken tokenResult;
-
- public static async Task<GBSToken> GetToken()
- {
- if (tokenResult != null && DateTime.Now < tokenResult.tokenDate)
- {
- return tokenResult;
- }
- var url = $"{loginUrl}api/v1/login?username={username}&password={password}";
- GBSToken token=null;
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- token = JsonConvert.DeserializeObject<GBSToken>(result);
- tokenResult=token;
- tokenResult.tokenDate = DateTime.Now.AddMilliseconds(tokenResult.TokenTimeout);
- }
- }
- return token;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
- public static async Task<DeviceChanneModel> GetDeviceChannellist()
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- DeviceChanneModel model = new DeviceChanneModel();
- var url = $"{loginUrl}api/v1/device/channellist?token={tokenResult.URLToken}";
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- model = JsonConvert.DeserializeObject<DeviceChanneModel>(result);
- }
- }
- return model;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
-
-
-
- public static async Task<ChannelVideo> GeChannelVideo(string serial,string channelId)
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- ChannelVideo model = new ChannelVideo();
- var url = $"{loginUrl}api/v1/stream/start?token={tokenResult.URLToken}&serial={serial}&code={channelId}";
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- model = JsonConvert.DeserializeObject<ChannelVideo>(result);
- }
- }
- return model;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
-
-
-
- public static async Task<VideoStartRecording> StartRecording(string serial, string channelId)
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- VideoStartRecording DownloadURL = null;
- var url = $"{loginUrl}api/v1/record/start?token={tokenResult.URLToken}&serial={serial}&code={channelId}";
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- DownloadURL = JsonConvert.DeserializeObject<VideoStartRecording>(result);
- }
- }
- return DownloadURL;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
-
-
-
- public static async Task<VideoRecording> StopRecording(string serial, string channelId)
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- VideoRecording model = null;
- var url = $"{loginUrl}api/v1/record/stop?token={tokenResult.URLToken}&serial={serial}&code={channelId}";
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- model = JsonConvert.DeserializeObject<VideoRecording>(result);
- }
- }
- return model;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
-
-
-
-
- public static async Task<cloudrecordQuerydaily> cloudrecordQuerydaily(string serial, string channelId,string date)
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- cloudrecordQuerydaily model = null;
- var url = $"{loginUrl}api/v1/cloudrecord/querydaily?token={tokenResult.URLToken}&serial={serial}&code={channelId}&period={date}";
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- model = JsonConvert.DeserializeObject<cloudrecordQuerydaily>(result);
- }
- }
- return model;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- #region 前端设备录像
-
-
-
-
-
-
-
-
- public static async Task<playbackRecordList> playbackRecordList(string serial, string channelId, string starDate,string endDate)
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- playbackRecordList model = null;
- var url = $"{loginUrl}api/v1/playback/recordlist?token={tokenResult.URLToken}&serial={serial}&code={channelId}&starttime={starDate}&endtime={endDate}";
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- model = JsonConvert.DeserializeObject<playbackRecordList>(result);
- }
- }
- return model;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
-
-
-
-
-
- public static async Task<ChannelVideo> playbackStart(string serial, string channelId, string starDate, string endDate,bool Download=false,int DownloadSpeed=4)
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- ChannelVideo model = new ChannelVideo();
- var url = $"{loginUrl}api/v1/playback/start?token={tokenResult.URLToken}&serial={serial}&code={channelId}&starttime={starDate}&endtime={endDate}";
- if (Download)
- {
- url = $"{loginUrl}api/v1/playback/start?token={tokenResult.URLToken}&serial={serial}&code={channelId}&starttime={starDate}&endtime={endDate}&download={Download}&download_speed={DownloadSpeed}";
- }
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- model = JsonConvert.DeserializeObject<ChannelVideo>(result);
- }
- }
- return model;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
-
-
-
-
-
- public static async Task<string> playbackControl(string streamid,string command,string range="now",int scale=2)
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- string bol = "false";
- var url = $"{loginUrl}api/v1/playback/control?token={tokenResult.URLToken}&streamid={streamid}&command={command}";
- if (command== "play")
- {
- url = $"{loginUrl}api/v1/playback/control?token={tokenResult.URLToken}&streamid={streamid}&command={command}&range={range}";
- }else if (command== "scale")
- {
- url = $"{loginUrl}api/v1/playback/control?token={tokenResult.URLToken}&streamid={streamid}&command={command}&scale={scale}";
- }
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- bol=JsonConvert.DeserializeObject<string>(result);
- }
- }
- return bol;
- }
- catch (Exception ex)
- {
- return "error";
- }
- }
-
-
-
-
-
- public static async Task<playbackStopPlaybackFileURL> playbackStop(string streamid)
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- playbackStopPlaybackFileURL model = new playbackStopPlaybackFileURL();
- var url = $"{loginUrl}api/v1/playback/stop?token={tokenResult.URLToken}&streamid={streamid}";
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- model = JsonConvert.DeserializeObject<playbackStopPlaybackFileURL>(result);
- }
- }
- return model;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
-
-
- public static async Task<playbackStreaminfoEntity> playbackStreaminfo(string streamid)
- {
- if (tokenResult == null || DateTime.Now >= tokenResult.tokenDate)
- {
- tokenResult = await GetToken();
- }
- playbackStreaminfoEntity model = new playbackStreaminfoEntity();
- var url = $"{loginUrl}api/v1/playback/streaminfo?token={tokenResult.URLToken}&streamid={streamid}";
- try
- {
- using (HttpClient http = new HttpClient())
- {
- var requestt = new HttpRequestMessage(HttpMethod.Get, url);
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await http.SendAsync(requestt);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- string result = await response.Content.ReadAsStringAsync();
- model = JsonConvert.DeserializeObject<playbackStreaminfoEntity>(result);
- }
- }
- return model;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- #endregion
- }
- }
- public class GBSToken
- {
- public string CookieToken { get; set; }
- public string URLToken { get; set; }
- public string StreamToken { get; set; }
- public int TokenTimeout { get; set; }
- public DateTime tokenDate { get; set; }
- }
- public class DeviceChanneModel
- {
- public int ChannelCount { get; set; }
- public List<ChanneModel> ChannelList { get; set; }
- }
- public class ChanneModel
- {
- public string ID { get; set; }
- public string DeviceID { get; set; }
- public string DeviceName { get; set; }
- public string DeviceCustomName { get; set; }
- public bool DeviceOnline { get; set; }
- public int Channel { get; set; }
- public string Name { get; set; }
- public string CustomName { get; set; }
- public string SnapURL { get; set; }
- public string Manufacturer { get; set; }
- public string CustomManufacturer { get; set; }
- public string Model { get; set; }
- public string CustomModel { get; set; }
- public string Owner { get; set; }
- public string CivilCode { get; set; }
- public string CustomCivilCode { get; set; }
- public string Address { get; set; }
- public string CustomAddress { get; set; }
- public string Firmware { get; set; }
- public string CustomFirmware { get; set; }
- public string SerialNumber { get; set; }
- public string CustomSerialNumber { get; set; }
- public string IPAddress{get;set; }
- public string CustomIPAddress { get; set; }
- public int Port { get; set; }
- public int CustomPort { get; set; }
- public int Parental { get; set; }
- public string ParentID { get; set; }
- public string CustomParentID { get; set; }
- public int Secrecy { get; set; }
- public int RegisterWay { get; set; }
- public string Status { get; set; }
- }
- public class ChannelVideo
- {
- public string StreamID { get; set; }
- public string SMSID { get; set; }
- public string DeviceID { get; set; }
- public string ChannelID { get; set; }
- public string ChannelName { get; set; }
- public string FLV { get; set; }
- public string HLS { get; set; }
- public string RTSP { get; set; }
- public string RTMP { get; set; }
- public string SnapURL { get; set; }
- public string WEBRTC { get; set; }
- public string WS_FLV { get; set; }
- }
- public class VideoRecording
- {
- public string StreamID { get; set; }
- public int RecordCount { get; set; }
- public List<VideoRecordingMode> RecordList { get; set; }
- }
- public class VideoRecordingMode
- {
- public string StartTime { get; set; }
- public string EndTime { get; set; }
- public string DownloadURL { get; set; }
- }
- public class VideoStartRecording
- {
- public string DownloadURL { get; set; }
- }
- public class playbackStopPlaybackFileURL
- {
- public string PlaybackFileURL { get; set; }
- }
- public class cloudrecordQuerydaily
- {
-
- public string name { get; set; }
-
- public string osd { get; set; }
- public List<recordQuerydaily> list { get; set; }
- }
- public class recordQuerydaily
- {
-
- public string name {get;set;}
-
- public string startAt {get;set;}
-
- public double duration { get; set; }
-
- public string hls { get; set; }
-
- public bool important { get; set; }
- }
- public class playbackRecordList
- {
-
- public string DeviceID { get; set; }
-
- public string Name { get; set; }
-
- public int SumNum { get; set; }
-
- public List<RecordList> RecordList { get; set; }
- }
- public class RecordList
- {
-
- public string CameraName { get; set; }
-
- public string ChannelID { get; set; }
-
- public string DeviceID { get; set; }
-
- public string Name { get; set; }
-
- public string FilePath { get; set; }
-
- public string Address { get; set; }
-
- public string StartTime { get; set; }
-
- public string EndTime { get; set; }
-
- public string Secrecy { get; set; }
-
- public string Type { get; set; }
-
- public string RecorderID { get; set; }
- }
- public class playbackStreaminfoEntity
- {
- public string StreamID { get; set; }
- public string SMSID { get; set; }
- public string DeviceID { get; set; }
- public string ChannelID { get; set; }
- public string ChannelName { get; set; }
- public string WEBRTC { get; set; }
- public string FLV { get; set; }
- public string WS_FLV { get; set; }
- public string RTMP { get; set; }
- public string HLS { get; set; }
- public string StartAt { get; set; }
- public string RecordStartAt { get; set; }
- public int Duration { get; set; }
- public string SourceVideoCodecName { get; set; }
- public int SourceVideoWidth { get; set; }
- public int SourceVideoHeight { get; set; }
- public double SourceVideoFrameRate { get; set; }
- public string SourceAudioCodecName { get; set; }
- public double SourceAudioSampleRate { get; set; }
- public int RTPCount { get; set; }
- public int RTPLostCount { get; set; }
- public double RTPLostRate { get; set; }
- public int VideoFrameCount { get; set; }
- public int InBytes { get; set; }
- public double InBitRate { get; set; }
- public int OutBytes { get; set; }
- public int PlaybackDuration { get; set; }
- public int TimestampSec { get; set; }
- public double PlaybackProgress { get; set; }
- public double DownloadProgress { get; set; }
- public double PlaybackFileSizea { get; set; }
- public string PlaybackFileURL { get; set; }
- public string PlaybackFileError { get; set; }
- }
|