Example #1
0
        /// <summary>
        /// 通过腾讯云开放接口统计直播相关信息(腾讯云统计接口并未全部开放,有可能无法使用)
        /// </summary>
        /// <param name="liveInterface">腾讯云统计接口字符串,比如:Get_LiveStat,Get_LivePushStat,Get_LivePlayStat</param>
        /// <param name="streamId">腾讯云直播ID</param>
        /// <returns></returns>
        public static string GetLiveStatistics(string liveInterface, string streamId = null)
        {
            ////////拼接查询参数///////////////////
            //有效时间
            DateTime expireTime     = DateTime.Now.AddMinutes(10);
            var      epoch          = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var      txTime         = (expireTime.ToUniversalTime() - epoch).TotalSeconds;
            long     expireUnixTime = Convert.ToInt64(txTime);
            //安全签名及API key和API appid
            int appid = 0;

            int.TryParse(ConfigurationManager.AppSettings["live_appid"].ToString(), out appid);
            string apikey = ConfigurationManager.AppSettings["live_apikey"].ToString();
            string sign   = CloseBlackScreenLiveSchedule.CreateMD5(apikey + expireUnixTime.ToString());
            // --------------------------------------------------------------------------------------
            string baseUrl = "http://statcgi.video.qcloud.com/";
            string url     = string.Format("/common_access?cmd ={0}&interface={1}&t={2}&sign={3}&Param.n.page_no=1&Param.n.page_size=300", appid, liveInterface, expireTime, sign);

            if (!string.IsNullOrEmpty(streamId))
            {
                url = url + "&Param.s.stream_id=" + streamId;
            }
            //---------------------------------------------------------------------------------------
            RestRequest request = new RestRequest();

            request.Resource = url;
            RestClient client = new RestClient(new Uri(baseUrl));
            var        rsp    = client.Execute <LiveStatisticsRsp>(request);
            var        test   = rsp.Data;

            return("");
        }
Example #2
0
        public Response Execute(User currentUser, string request)
        {
            var req = JsonConvert.DeserializeObject <Request <LiveRoom> >(request);
            var obj = req.FirstEntity();
            var sql = @"
UPDATE dbo.LiveRoom 
SET State=@State  
WHERE Id=@Id 
";

            if (obj.State == LiveDic.Active)
            {
                //直播中断流计数器设置为0
                sql = @"
UPDATE dbo.LiveRoom 
SET State=@State ,NotPushCount=0 
WHERE Id=@Id 
";
                //通过腾讯API接口开启对应直播码且关闭的的直播房间,解决同一直播ID房间关闭再次创建房间无法正常推流问题
                try { CloseBlackScreenLiveSchedule.CheckLiveIsNotPush(obj, true); }
                catch (Exception e) { }
            }

            var cmd = CommandHelper.CreateText <LiveRoom>(FetchType.Execute, sql);

            cmd.Params.Add("@Id", obj.Id);
            cmd.Params.Add("@State", obj.State);

            var result = DbContext.GetInstance().Execute(cmd);

            if (obj.State == LiveDic.Active)
            {
                //直播状态变为"Active"时,打开直播黑屏检测计时器
                CloseBlackScreenLiveSchedule.StartTimer();
            }


            return(result);
        }