/// <summary>
        /// 更新直播间分类
        /// </summary>
        /// <param name="user"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static async Task <bool> UpdateLiveCategory(User user, string id)
        {
            try
            {
                LiveCategoryDataInfo liveCategoryData = await GetLiveCategoryInfo();

                if (liveCategoryData == null || liveCategoryData.Code != 0 || liveCategoryData.Data == null)
                {
                    return(false);
                }
                bool isOk = false;
                foreach (var item in liveCategoryData.Data)
                {
                    foreach (var cate in item.List)
                    {
                        if (cate.id.Equals(id, StringComparison.OrdinalIgnoreCase))
                        {
                            isOk = true;
                        }
                    }
                }
                if (!isOk)
                {
                    return(false);
                }

                string roomId = await GetRoomId(user);

                var queries = new QueryCollection {
                    { "room_id", roomId },
                    { "area_id", id },
                    { "csrf_token", user.Data.Csrf },
                    { "csrf", user.Data.Csrf }
                };
                using (HttpResponseMessage response = await user.Handler.SendAsync(HttpMethod.Post, _updateLiveRoomCategory, queries, user.AppHeaders, user.Data.Cookie))
                {
                    ResultModel <IResultData> resultModel = await response.ConvertResultModel <IResultData>();

                    if (resultModel.Code == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        throw new Exception($"Update live category failed. error code is {resultModel.Code}({resultModel.Msg}).");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        /// <summary>
        /// 获取Key
        /// </summary>
        /// <param name="user">用户</param>
        /// <returns></returns>
        public static async Task <string> GetKeyAsync(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            QueryCollection queries;

            queries = new QueryCollection {
                { "appkey", General["appkey"] }
            };
            queries.SortAndSign();
            using (HttpResponseMessage response = await user.Handler.SendAsync(HttpMethod.Post, OAUTH2_GETKEY_URL, queries, null))
                return(await response.Content.ReadAsStringAsync());
        }
        /// <summary>
        /// 修改直播间名称
        /// </summary>
        /// <param name="user"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static async Task <bool> UpdateLiveRoomName(User user, string name)
        {
            if (user == null || !user.IsLogin)
            {
                throw new Exception("User unlogin.");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new Exception("Live name can not null.");
            }
            if (name.Length > 30)
            {
                throw new Exception("Live name length cannot more than 30.");
            }
            try
            {
                string roomId = await GetRoomId(user);

                var queries = new QueryCollection {
                    { "room_id", roomId },
                    { "title", name },
                    { "csrf_token", user.Data.Csrf },
                    { "csrf", user.Data.Csrf }
                };
                using (HttpResponseMessage response = await user.Handler.SendAsync(HttpMethod.Post, _updateLiveRoomNameApi, queries, user.AppHeaders, user.Data.Cookie))
                {
                    ResultModel <StartLiveDataInfo> resultModel = await response.ConvertResultModel <StartLiveDataInfo>();

                    if (resultModel.Code == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        throw new Exception($"Update live room name failed. error code is {resultModel.Code}({resultModel.Msg}).");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 开始直播
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="roomId">房间号</param>
        /// <param name="liveCategory">直播类型 默认户外</param>
        /// <returns></returns>
        public static async Task <StartLiveDataInfo> StartLive(User user, string liveCategory = "123")
        {
            if (user == null || !user.IsLogin)
            {
                throw new Exception("User unlogin.");
            }
            try
            {
                string roomId = await GetRoomId(user);

                var queries = new QueryCollection {
                    { "room_id", roomId },
                    { "platform", "pc" },
                    { "area_v2", liveCategory },
                    { "csrf_token", user.Data.Csrf },
                    { "csrf", user.Data.Csrf }
                };
                using (HttpResponseMessage response = await user.Handler.SendAsync(HttpMethod.Post, _startLiveApi, queries, user.AppHeaders, user.Data.Cookie))
                {
                    ResultModel <StartLiveDataInfo> resultModel = await response.ConvertResultModel <StartLiveDataInfo>();

                    if (resultModel.Code == 0)
                    {
                        resultModel.Data.RoomId = roomId;
                        return(resultModel.Data);
                    }
                    else
                    {
                        throw new Exception($"Start live failed. error code is {resultModel.Code}({resultModel.Msg}).");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #5
0
        /// <summary>
        /// 获取信息
        /// </summary>
        /// <param name="user">用户</param>
        /// <returns></returns>
        public static async Task <string> GetInfoAsync(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            QueryCollection queries;

            queries = new QueryCollection {
                { "access_key", user.LoginData["access_key"] },
                { "ts", ApiUtils.GetTimeStamp().ToString() }
            };
            queries.AddRange(user.LoginData["cookie"].Split(';').Select(item => {
                string[] pair;

                pair = item.Split('=');
                return(new KeyValuePair <string, string>(pair[0], pair[1]));
            }));
            queries.AddRange(General);
            queries.SortAndSign();
            using (HttpResponseMessage response = await user.Client.SendAsync(HttpMethod.Get, OAUTH2_INFO_URL, queries, user.AppHeaders))
                return(await response.Content.ReadAsStringAsync());
        }
Exemple #6
0
 public static void SortAndSign(this QueryCollection queries)
 {
     queries.Sort((x, y) => x.Key[0] - y.Key[0]);
     queries.Add("sign", ComputeSign(queries.ToQueryString()));
 }