Exemplo n.º 1
0
        /// <summary>
        /// 获取单个设备信息
        /// </summary>
        /// <param name="deviceSerial"></param>
        public void GetEzvizDevice(string deviceSerial)
        {
            var postData = "accessToken=" + _ezvizAccessToken + "&deviceSerial=" + deviceSerial;
            var device   = ToHttp.ToPost <Device>("https://open.ys7.com/api/lapp/device/info", postData);

            LogHelper.WriteLog(typeof(string), JsonConvert.SerializeObject(device));
            if (device.code == "200")
            {
                string status;
                if (device.data.status == 0)
                {
                    status = "离线";
                }
                else if (device.data.status == 1)
                {
                    status = "在线";
                }
                else
                {
                    status = "未知";
                }
                if (!_dbContext2.XlProject.Any(x => x.XlShebeiId == device.data.deviceSerial && x.IsDeleted == 0))
                {
                    XlProject xlProject = new XlProject();
                    xlProject.AddPeople     = "狗";
                    xlProject.AddTime       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    xlProject.XlProjectUuid = Guid.NewGuid();
                    xlProject.XlShebeiId    = device.data.deviceSerial;
                    xlProject.XlShebeiType  = "五水共治污水监控";
                    xlProject.IsDeleted     = 0;
                    xlProject.ShebeiAddress = device.data.deviceName;
                    xlProject.ShebeiType    = status;
                    xlProject.UrlType       = 3;
                    _dbContext2.XlProject.Add(xlProject);
                    LogHelper.WriteLog(typeof(string), "添加" + device.data.deviceName);
                }
                else
                {
                    var xlp = _dbContext2.XlProject.FirstOrDefault(x => x.XlShebeiId == device.data.deviceSerial && x.IsDeleted == 0);
                    xlp.ShebeiAddress = device.data.deviceName;
                    xlp.ShebeiType    = status;
                    xlp.UrlType       = 3;
                    LogHelper.WriteLog(typeof(string), "修改" + device.data.deviceName);
                }
                _dbContext2.SaveChanges();
            }
            else if (device.code == "10002")
            {
                LogHelper.WriteLog(typeof(string), "token失效");
                GetEzvizAccessToken();
                GetEzvizDevice(deviceSerial);
            }
            else
            {
                LogHelper.WriteLog(typeof(string), device.code + "|" + device.msg);
            }
        }
        /// <summary>
        /// 停止控制
        /// </summary>
        /// <param name="deviceSerial"></param>
        /// <param name="channelNo"></param>
        /// <returns></returns>
        private object StopEzvizPTZ(string deviceSerial, int channelNo)
        {
            var postData  = "accessToken=" + _ezvizAccessToken + "&deviceSerial=" + deviceSerial + "&channelNo=" + channelNo;
            var ptzResult = ToHttp.ToPost <PTZResult>("https://open.ys7.com/api/lapp/device/ptz/stop", postData);

            if (ptzResult.code == "10002")
            {
                GetEzvizAccessToken();
                StopEzvizPTZ(deviceSerial, channelNo);
            }

            return(ptzResult);
        }
        /// <summary>
        /// ezviz平台获取token
        /// </summary>
        private void GetEzvizAccessToken()
        {
            var postData = "appKey=" + _ezvizAppKey + "&appSecret=" + _ezvizSecret;
            var token    = ToHttp.ToPost <AccessToken>("https://open.ys7.com/api/lapp/token/get", postData);

            if (token.code == "200")
            {
                _ezvizAccessToken = token.data.accessToken;
                WebConfigurationManager.AppSettings.Set("token", token.data.accessToken);
            }
            else
            {
                throw new Exception("获取token错误:" + token.code + "|" + token.msg);
            }
        }
        /// <summary>
        /// 云台控制
        /// </summary>
        /// <param name="deviceSerial"></param>
        /// <param name="channelNo"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        private object ToEzvizPTZ(string deviceSerial, int channelNo, int direction)
        {
            var postData  = "accessToken=" + _ezvizAccessToken + "&deviceSerial=" + deviceSerial + "&channelNo=" + channelNo + "&direction=" + direction + "&speed=1";
            var ptzResult = ToHttp.ToPost <PTZResult>("https://open.ys7.com/api/lapp/device/ptz/start", postData);

            if (ptzResult.code == "10002")
            {
                GetEzvizAccessToken();
                ToEzvizPTZ(deviceSerial, channelNo, direction);
            }



            return(ptzResult);
        }
Exemplo n.º 5
0
        /// <summary>
        /// ezviz平台获取token
        /// </summary>
        public void GetEzvizAccessToken()
        {
            var postData = "appKey=" + _ezvizAppKey + "&appSecret=" + _ezvizSecret;
            var token    = ToHttp.ToPost <AccessToken>("https://open.ys7.com/api/lapp/token/get", postData);

            if (token.code == "200")
            {
                _ezvizAccessToken = token.data.accessToken;
                ConfigurationManager.AppSettings.Set("token", token.data.accessToken);
            }
            else
            {
                LogHelper.WriteLog(typeof(string), token.code + "|" + token.msg);
                throw new Exception(token.code + " | " + token.msg);
            }
        }
        /// <summary>
        /// ezviz 获取监控直播列表
        /// </summary>
        /// <param name="pageIndex">页数</param>
        private object GetEzvizLiveList(int pageIndex)
        {
            //var hls = "";
            var postData  = "accessToken=" + _ezvizAccessToken + "&pageStart=" + pageIndex + "&pageSize=50";
            var liveVideo = ToHttp.ToPost <LiveVideo>("https://open.ys7.com/api/lapp/live/video/list", postData);

            if (liveVideo.code == "200")
            {
                var index = liveVideo.data.FindIndex(x => x.deviceSerial == _deviceSerial);
                if (index != -1)
                {
                    return(liveVideo.data[index]);
                }
                else
                {
                    if ((liveVideo.page.total - (pageIndex + 1) * 50) % 50 > 0)
                    {
                        pageIndex++;
                        return(GetEzvizLiveList(pageIndex));
                    }
                    else
                    {
                        return(null);
                    }
                }
                //_liveList.AddRange(liveVideo.data);
            }
            else if (liveVideo.code == "10002")
            {
                GetEzvizAccessToken();
                return(GetEzvizLiveList(0));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取设备列表
        /// </summary>
        /// <param name="pageIndex">页数</param>
        public void GetEzvizDevices(int pageIndex)
        {
            var postData = "accessToken=" + _ezvizAccessToken + "&pageStart=" + pageIndex + "&pageSize=50";
            var devices  = ToHttp.ToPost <Devices>("https://open.ys7.com/api/lapp/device/list", postData);

            if (devices.code == "200")
            {
                _sewage.AddRange(devices.data);
                if ((devices.page.total - (pageIndex + 1) * 50) % 50 > 0)
                {
                    pageIndex++;
                    GetEzvizDevices(pageIndex);
                }
            }
            else if (devices.code == "10002")
            {
                GetEzvizAccessToken();
                GetEzvizDevices(0);
            }
            else
            {
                LogHelper.WriteLog(typeof(string), devices.code + "|" + devices.msg);
            }
        }