示例#1
0
        private void Initialization()
        {
            //监听IP数量
            AgentPool.IpsChange += (nums) =>
            {
                this.Invoke(new Action(() => lblIpsNums.Text = $"IP数量:{nums}"));
            };
            AgentPool.AddAgentIp(JsonConfig <AgentIp> .GetSiteConfigs());
            AgentPool.SaveIps();
            RefreshRoom();
            return;

            Task.Run(async() =>
            {
                while (true)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        await Task.Delay(2000);
                        try
                        {
                            using (HttpWebResponse httpWebResponse = await CCHttpRequest.CreateGetHttpResponseAsync("http://http.tiqu.alicdns.com/getip3?num=20&type=2&pro=&city=0&yys=0&port=2&pack=74963&ts=1&ys=1&cs=1&lb=1&sb=0&pb=45&mr=2&regions=&gm=4"))
                            {
                                //获取返回内容
                                string json = await httpWebResponse.GetResponseStream().ReadAllTextAsync();
                                MsgInfo(json);
                                //将JSON字符串转换为dynamic类型
                                dynamic obj = JsonConvert.DeserializeObject <dynamic>(json);
                                if (obj.success != true)
                                {
                                    continue;
                                }
                                List <AgentIp> ips = obj.data.ToObject <List <AgentIp> >();
                                AgentPool.AddAgentIp(ips);
                                AgentPool.SaveIps();
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"【获取IP错误】:{ex.Message}");
                            MsgError($"【获取IP错误】:{ex.Message}");
                        }
                    }
                    return;

                    await Task.Delay(10000);
                }
            });
        }
示例#2
0
        async static Task <long> GetTimestamp(string dy_did)
        {
            Dictionary <string, string> header = new Dictionary <string, string>();

            header["authority"] = "www.douyu.com";
            header["method"]    = "GET";
            header["path"]      = "/api/v1/timestamp";
            header["scheme"]    = "https";
            header["Cookie"]    = $"dy_did={dy_did};acf_did={dy_did}";
            HttpWebResponse response = await CCHttpRequest.CreateGetHttpResponseAsync("https://www.douyu.com/api/v1/timestamp", header : header);

            string json = await response.GetResponseStream().ReadAllTextAsync();

            dynamic obj = JsonConvert.DeserializeObject <dynamic>(json);

            return(obj.data);
        }
示例#3
0
        /// <summary>
        /// 获取礼物
        /// </summary>
        /// <param name="roomId"></param>
        /// <returns></returns>
        public async static Task <bool> GetLiwu(int roomId)
        {
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    HttpWebResponse response = await CCHttpRequest.CreateGetHttpResponseAsync($"https://gift.douyucdn.cn/api/gift/v2/web/list?rid={roomId}");

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string json = await response.GetResponseStream().ReadAllTextAsync();

                        dynamic _dy = JsonConvert.DeserializeObject <dynamic>(json);
                        if (_dy.error == 0)
                        {
                            foreach (var item in _dy.data.giftList)
                            {
                                if (!douyuGifts.ContainsKey((int)item.id))
                                {
                                    DouyuGift douyuGift = new DouyuGift()
                                    {
                                        Id    = (int)item.id,
                                        Name  = item.name,
                                        Type  = item.priceInfo.priceType,
                                        Price = (double)item.priceInfo.price
                                    };
                                    Console.WriteLine($"礼物【{douyuGift.Name}】 ID:{douyuGift.Id}");
                                    douyuGifts[douyuGift.Id] = douyuGift;
                                }
                            }
                            return(true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    AppLog.Error($"获取直播间【{roomId}】礼物信息失败", ex);
                }
            }
            return(false);
        }