示例#1
0
        private void GetPreForecast(OlaEntities db, LotteryOpenHistory lotteryOpen)
        {
            var lastes = db.LotteryOpenHistories
                         .Where(w => w.LotteryId == this.lottery.LotteryId)
                         .OrderByDescending(w => w.QiHao).Take(3).ToList();
            int index = 1;

            foreach (var item in lastes)
            {
                switch (index)
                {
                case 1:
                    item.Forecast1 = lotteryOpen.OpenNumber;
                    break;

                case 2:
                    item.Forecast2 = lotteryOpen.OpenNumber;
                    break;

                case 3:
                    item.Forecast3 = lotteryOpen.OpenNumber;
                    break;

                default:
                    break;
                }
                index++;
            }
        }
示例#2
0
        public GetLotteryOpenNumber(LotteryInfo lottery)
        {
            this.lottery = lottery;


            using (var db = new OlaEntities())
            {
                log.Info("获取最新开奖时间:" + this.lottery.LotteryId);
                var lotteryOpen = db.LotteryOpenHistories
                                  .Where(w => w.LotteryId == this.lottery.LotteryId).OrderByDescending(w => w.QiHao).FirstOrDefault();
                if (lotteryOpen != null)
                {
                    var lotteryOpenTimes = db.LotteryOpenTimes
                                           .FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpen.QiHao);
                    if (lotteryOpenTimes != null)
                    {
                        var nextInfo = db.LotteryOpenTimes
                                       .FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpenTimes.NextQiHao);
                        if (nextInfo != null)
                        {
                            this.NextRequestDT = nextInfo.OpenTime;
                        }
                    }
                }
            }
        }
示例#3
0
        private string ForecastA(OlaEntities db, LotteryOpenHistory lottery)
        {
            var olds = db.LotteryOpenHistories
                       .Where(w => w.LotteryId == this.lottery.LotteryId)
                       .OrderByDescending(w => w.QiHao)
                       .Take(50).ToList();
            var currentOpenNumbers = SplitOpenNumber2IntList(lottery.OpenNumber);

            foreach (var item in olds)
            {
                var openNumbers = SplitOpenNumber2IntList(item.OpenNumber);
                var intersect   = currentOpenNumbers.Intersect(openNumbers);

                if (intersect.Count() == 4)
                {
                    lottery.ForecastFrom += item.QiHao + ";";
                    //log.Info(" 预测A:" + JsonConvert.SerializeObject(item));
                    var except = new List <int>();
                    except.AddRange(openNumbers.Except(currentOpenNumbers));
                    except.AddRange(currentOpenNumbers.Except(openNumbers));
                    return(Except2String(except));
                }
            }
            lottery.ForecastFrom += ";";
            return(null);
        }
示例#4
0
        /// <summary>
        /// 前二预测
        /// 历史数据加一 有一位重合 则为匹配成功
        ///
        /// </summary>
        /// <param name="db"></param>
        /// <param name="openNumber"></param>
        /// <returns></returns>
        private string ForecastC(OlaEntities db, LotteryOpenHistory lottery)
        {
            var olds = db.LotteryOpenHistories
                       .Where(w => w.Used != true && w.LotteryId == this.lottery.LotteryId)
                       .OrderByDescending(w => w.QiHao)
                       .Take(50).ToList();
            var currentOpenNumbers = SplitOpenNumber2IntList(lottery.OpenNumber.Substring(0, 5));

            foreach (var item in olds)
            {
                var openNumbers             = SplitOpenNumber2IntList(item.OpenNumber.Substring(0, 5));
                var currentOpenNumbers_plus = new List <int>();
                foreach (var n in openNumbers)
                {
                    currentOpenNumbers_plus.Add(n + 1 == 12 ? 1 : n + 1);
                }
                var intersect = currentOpenNumbers.Intersect(currentOpenNumbers_plus);

                if (intersect.Count() == 1)
                {
                    lottery.ForecastFrom += item.QiHao;
                    //log.Info(item.QiHao + " 预测C:" + JsonConvert.SerializeObject(item));
                    var except = new List <int>();
                    except.AddRange(currentOpenNumbers_plus.Except(currentOpenNumbers));
                    item.Used   = true;
                    item.UsedBy = lottery.QiHao;
                    db.SaveChanges();
                    return(Except2String(except));
                }
            }
            return(null);
        }
示例#5
0
        private void GetForecast(OlaEntities db, LotteryOpenHistory lotteryOpen)
        {
            var forecast = ForecastA(db, lotteryOpen) + ";";

            forecast += ForecastB(db, lotteryOpen) + ";";
            forecast += ForecastC(db, lotteryOpen);
            lotteryOpen.CurrentForecastNumber = forecast;
        }
示例#6
0
        public async Task <ActionResult> Register(RegisterModel model)
        {
            if (string.IsNullOrEmpty(model.AuthCode))
            {
                return(Json("请从官方渠道进入", JsonRequestBehavior.AllowGet));
            }
            //SuperAuthCode
            var superAuthCode = ConfigurationManager.AppSettings["SuperAuthCode"].ToString();

            if (superAuthCode.ToLower() != model.AuthCode.ToLower())
            {
                using (var db = new OlaEntities())
                {
                    var ac = db.AuthCodes.FirstOrDefaultAsync(w => w.Code == model.AuthCode);
                    if (ac == null)
                    {
                        return(Json("请从官方渠道进入,没有邀请码无法注册", JsonRequestBehavior.AllowGet));
                    }
                }
            }

            // 验证短信验证码
            var key = SMS_Prefix + model.Mobile;

            if (Session[key] == null)
            {
                return(Json("验证码已过期", JsonRequestBehavior.AllowGet));
            }

            if (Session[key].ToString() != model.Vcode)
            {
                return(Json("验证码错误", JsonRequestBehavior.AllowGet));
            }
            using (var db = new OlaEntities())
            {
                var wxUser = await db.WeiXinUsers.FirstOrDefaultAsync(w => w.openid == model.OpenId);

                if (wxUser == null)
                {
                    return(Json("账户信息不存在,请重新进入", JsonRequestBehavior.AllowGet));
                }
                wxUser.phone = model.Mobile;
                await db.SaveChangesAsync();

                WriteCookie(wxUser.Id);
            }
            return(Json("success", JsonRequestBehavior.AllowGet));
        }
示例#7
0
        private void Generate(DateTime startTime, DateTime endTime, int step, int startQiHao)
        {
            using (var db = new OlaEntities())
            {
                while (startTime <= endTime)
                {
                    string qihao  = startTime.ToString("yyyyMMdd") + startQiHao.ToString(this.QiHaoFormat);
                    var    exists = db.LotteryOpenTimes.Any(w => w.LotteryId == this.LotteryId && w.QiHao == qihao);
                    if (exists)
                    {
                        startQiHao++;
                        startTime = startTime.AddMinutes(step);
                        continue;
                    }

                    string next_qihao = startTime.ToString("yyyyMMdd") + (startQiHao + 1).ToString(this.QiHaoFormat);
                    if (startQiHao + 1 > this.MaxQiHao)
                    {
                        next_qihao = startTime.AddDays(1).ToString("yyyyMMdd") + this.MinQiHao.ToString(this.QiHaoFormat);
                    }

                    string pre_qihao = startTime.ToString("yyyyMMdd") + (startQiHao - 1).ToString(this.QiHaoFormat);
                    if (startQiHao - 1 == 0)
                    {
                        pre_qihao = startTime.AddDays(-1).ToString("yyyyMMdd") + this.MaxQiHao.ToString(this.QiHaoFormat);
                    }

                    db.LotteryOpenTimes.Add(new LotteryOpenTime
                    {
                        CreateTime = DateTime.Now,
                        Id         = Guid.NewGuid(),
                        LotteryId  = this.LotteryId,
                        NextQiHao  = next_qihao,
                        PreQiHao   = pre_qihao,
                        OpenTime   = startTime,
                        QiHao      = qihao,
                        StartTime  = startTime.AddMinutes(-step).AddSeconds(-30),
                        EndTime    = startTime.AddSeconds(-30),
                    });

                    startQiHao++;
                    startTime = startTime.AddMinutes(step);
                }
                db.SaveChanges();
            }
        }
示例#8
0
        public ActionResult Register(string authCode, string openId)
        {
            ViewBag.AuthCode = authCode;
            ViewBag.OpenId   = openId;

            if (string.IsNullOrEmpty(authCode))
            {
                return(Json("请从官方渠道进入", JsonRequestBehavior.AllowGet));
            }
            using (var db = new OlaEntities())
            {
                var ac = db.AuthCodes.FirstOrDefaultAsync(w => w.Code == authCode && w.IsExpired == false);
                if (ac == null)
                {
                    return(Json("请从官方渠道进入,没有邀请码无法注册", JsonRequestBehavior.AllowGet));
                }
            }
            return(View());
        }
示例#9
0
        //    //1
        //    var a = new List<string> { "2", "4", "5", "8", "10" };
        //    var b = new List<string> { "2", "3", "4", "5", "10" };
        //    // ab交集
        //    var c = a.Intersect(b);
        //    var d = new List<string>();
        //        // 匹配四位
        //        if (c.Count() == 4)
        //        {
        //            // 合并AUB-AnB = An(AUB)+Bn(AUB)= B\A+A\B
        //            d.AddRange(b.Except(a));
        //            d.AddRange(a.Except(b));
        //        }
        //ConsoleHelper.ConsoleInfo(d);

        //        //2
        //        // 当前期a每一位都减一
        //        var e = new List<string> { "1", "3", "4", "7", "9" };
        ////向上按一的算法进行匹配
        //var f = new List<string> { "1", "3", "7", "9", "10" };
        //// 匹配到以后每一位都加一
        //var g = new List<string> { "2", "4", "8", "10", "11" };
        ////重复1 找结果
        //// 5 11

        ////3 前二
        private string ForecastB(OlaEntities db, LotteryOpenHistory lottery)
        {
            var olds = db.LotteryOpenHistories
                       .Where(w => w.LotteryId == this.lottery.LotteryId)
                       .OrderByDescending(w => w.QiHao)
                       .Take(50).ToList();
            var currentOpenNumbers       = SplitOpenNumber2IntList(lottery.OpenNumber);
            var currentOpenNumbers_minus = new List <int>();

            foreach (var item in currentOpenNumbers)
            {
                currentOpenNumbers_minus.Add(item - 1 == 0 ? 11 : item - 1);
            }
            //log.Info("B-1:01 " + string.Join(",", currentOpenNumbers_minus));

            foreach (var item in olds)
            {
                var openNumbers = SplitOpenNumber2IntList(item.OpenNumber);
                var intersect   = currentOpenNumbers_minus.Intersect(openNumbers);

                if (intersect.Count() != 4)
                {
                    continue;
                }
                lottery.ForecastFrom += item.QiHao + ";";
                //log.Info(item.QiHao + " B匹配:02 " + item.OpenNumber);
                var currentOpenNumbers_plus = new List <int>();
                foreach (var n in openNumbers)
                {
                    currentOpenNumbers_plus.Add(n + 1 == 12 ? 1 : n + 1);
                }
                //log.Info(" B + 1:03 " + string.Join(",", currentOpenNumbers_plus));
                var except = new List <int>();
                except.AddRange(currentOpenNumbers_plus.Except(currentOpenNumbers));
                return(Except2String(except));
            }
            lottery.ForecastFrom += ";";
            return(null);
        }
示例#10
0
        /// <summary>
        /// 生成一天的开奖时间
        /// </summary>
        /// <param name="date"></param>
        private void GenerateOneDay(DateTime date)
        {
            // 00:05 -- 02:00
            var startTime = new DateTime(date.Year, date.Month, date.Day, 0, 5, 0);
            var endTime   = new DateTime(date.Year, date.Month, date.Day, 2, 0, 0);

            Generate(startTime, endTime, 5, this.MinQiHao);
            // 10:00 -- 22:00
            startTime = new DateTime(date.Year, date.Month, date.Day, 10, 0, 0);
            endTime   = new DateTime(date.Year, date.Month, date.Day, 22, 10, 0);
            Generate(startTime, endTime, 10, 24);

            // 22:05 -- 00:00
            startTime = new DateTime(date.Year, date.Month, date.Day, 22, 5, 0);
            var nextDay = date.AddDays(1);

            endTime = new DateTime(nextDay.Year, nextDay.Month, nextDay.Day, 0, 0, 0);
            Generate(startTime, endTime, 5, 97);
            // 第 120 期
            using (var db = new OlaEntities())
            {
                db.LotteryOpenTimes.Add(new LotteryOpenTime
                {
                    CreateTime = DateTime.Now,
                    Id         = Guid.NewGuid(),
                    LotteryId  = this.LotteryId,
                    NextQiHao  = date.ToString("yyyyMMdd") + this.MinQiHao.ToString(this.QiHaoFormat),
                    PreQiHao   = date.AddDays(-1).ToString("yyyyMMdd") + (this.MaxQiHao - 1).ToString(this.QiHaoFormat),
                    OpenTime   = date,
                    QiHao      = date.AddDays(-1).ToString("yyyyMMdd") + this.MaxQiHao.ToString(this.QiHaoFormat),
                    StartTime  = date.AddMinutes(-5).AddSeconds(-30),
                    EndTime    = date.AddSeconds(-30),
                });
                db.SaveChanges();
            }
        }
示例#11
0
        public void GetLotteryOpenNumberFrom163()
        {
            if (DateTime.Now <= this.NextRequestDT ||
                string.IsNullOrEmpty(this.lottery.url163))
            {
                return;
            }
            try
            {
                HtmlWeb htmlWeb = new HtmlWeb();
                HtmlWeb.PreRequestHandler handler = delegate(HttpWebRequest request)
                {
                    request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
                    request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                    request.CookieContainer        = new CookieContainer();
                    return(true);
                };
                htmlWeb.PreRequest += handler;
                var doc = htmlWeb.Load(this.lottery.url163);

                var tds = doc.DocumentNode.SelectNodes("//td");
                if (tds == null)
                {
                    return;
                }
                var lotteries = new List <LotteryOpenHistory>();
                foreach (var td in tds)
                {
                    try
                    {
                        HtmlAttribute attr_data_win_number = td.Attributes["data-award"];
                        HtmlAttribute attr_data_period     = td.Attributes["data-period"];
                        if (attr_data_win_number != null && attr_data_period != null)
                        {
                            var win_number = attr_data_win_number.Value;
                            var period     = attr_data_period.Value;
                            if (string.IsNullOrEmpty(win_number) || string.IsNullOrEmpty(period))
                            {
                                continue;
                            }
                            period = this.lottery.Prefix + period;
                            // 过滤掉已经添加的期号
                            var qihao = Convert.ToInt32(period);
                            if (qihao < this.NextQiHao)
                            {
                                continue;
                            }
                            lotteries.Add(new LotteryOpenHistory
                            {
                                OpenNumber = win_number.Replace(" ", ","),
                                QiHao      = period,
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom163 解析数据失败", ex);
                    }
                }
                lotteries = lotteries.OrderBy(w => w.QiHao).ToList();
                //log.Info("下一期期号:" + this.NextQiHao + this.lottery.Name + ":" + lotteries.Count + " " + JsonConvert.SerializeObject(lotteries));
                using (var db = new OlaEntities())
                {
                    foreach (var lotteryOpen in lotteries)
                    {
                        try
                        {
                            var lotteryOpenTimes = db.LotteryOpenTimes
                                                   .FirstOrDefault(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                            if (lotteryOpenTimes != null)
                            {
                                lotteryOpen.OpenTime = lotteryOpenTimes.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                                var history = db.LotteryOpenHistories
                                              .Any(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                                if (!history)
                                {
                                    // 预测
                                    GetForecast(db, lotteryOpen);

                                    lotteryOpen.Id         = Guid.NewGuid();
                                    lotteryOpen.LotteryId  = this.lottery.LotteryId;
                                    lotteryOpen.CreateTime = DateTime.Now;
                                    lotteryOpen.Source     = (int)LotteryOpenNumberSourceEnum.网易彩票;

                                    // 获取前三期的预测号码
                                    GetPreForecast(db, lotteryOpen);
                                    db.LotteryOpenHistories.Add(lotteryOpen);
                                    db.SaveChanges();
                                    UpdateWebClientLotteryOpenInfo(lotteryOpen.LotteryId);
                                    var nextInfo = db.LotteryOpenTimes.FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpenTimes.NextQiHao);
                                    if (nextInfo != null)
                                    {
                                        this.NextQiHao     = Convert.ToInt32(nextInfo.QiHao);
                                        this.NextRequestDT = nextInfo.OpenTime;
                                        log.Info("添加:" + this.lottery.Name + " 期号:" + lotteryOpen.QiHao + " 开奖号码:" + lotteryOpen.OpenNumber + " 获取时间: " + DateTime.Now + " 下次获取时间: " + this.NextRequestDT);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom163 解析数据失败", ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom163 获取数据失败", ex);
            }
        }
示例#12
0
 public BaseGenerator()
 {
     db = new OlaEntities();
 }
示例#13
0
        public async Task <ActionResult> BaseCallback(string code, string state, string authCode, string returnUrl)
        {
            //log.Info("code:" + code + " state:" + state + " authCode:" + authCode + " returnUrl:" + returnUrl);
            if (string.IsNullOrEmpty(code))
            {
                ViewBag.Info = "您拒绝了授权!";
                return(View("Info"));
            }

            OAuthAccessTokenResult result = null;

            //通过,用code换取access_token
            try
            {
                result = OAuthApi.GetAccessToken(WeiXinConfig.appId, WeiXinConfig.appSecret, code);

                if (result.errcode != ReturnCode.请求成功)
                {
                    ViewBag.Info = "错误:" + result.errmsg;
                    return(View("Info"));
                }
                //下面2个数据也可以自己封装成一个类,储存在数据库中(建议结合缓存)
                //如果可以确保安全,可以将access_token存入用户的cookie中,每一个人的access_token是不一样的
                //Session["OAuthAccessTokenStartTime"] = DateTime.Now;
                //Session["OAuthAccessToken"] = result;

                //因为第一步选择的是OAuthScope.snsapi_userinfo,这里可以进一步获取用户详细信息
                using (var db = new OlaEntities())
                {
                    var wxUser = await db.WeiXinUsers.FirstOrDefaultAsync(w => w.openid == result.openid);

                    if (wxUser == null)
                    {
                        //log.Info(JsonConvert.SerializeObject(result));
                        OAuthUserInfo userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
                        //log.Info(JsonConvert.SerializeObject(userInfo));

                        if (string.IsNullOrEmpty(authCode))
                        {
                            ViewBag.Info = "验证失败!请从正规途径进入!" + result.errmsg;
                            return(View("Info"));
                        }

                        wxUser = new WeiXinUser
                        {
                            city       = userInfo.city,
                            country    = userInfo.country,
                            headimgurl = userInfo.headimgurl,
                            nickname   = userInfo.nickname,
                            openid     = userInfo.openid,
                            province   = userInfo.province,
                            sex        = userInfo.sex,
                            unionid    = userInfo.unionid,
                            CreateTime = DateTime.Now,
                            phone      = null,
                            AuthCode   = authCode,
                            state      = (int)WeiXinUserStateEnum.Normal,
                        };
                        db.WeiXinUsers.Add(wxUser);
                        await db.SaveChangesAsync();
                    }
                    if (string.IsNullOrEmpty(wxUser.phone))
                    {
                        if (!string.IsNullOrEmpty(authCode))
                        {
                            return(RedirectToAction("Register", new { authCode, wxUser.openid }));
                        }
                        else
                        {
                            ViewBag.Info = "验证失败!请从正规途径进入!";
                            return(View("Info"));
                        }
                    }
                    if (wxUser.state != (int)WeiXinUserStateEnum.Normal)
                    {
                        ViewBag.Info = "您已经被限制访问该网站,请联系网站负责人!";
                        return(View("Info"));
                    }
                    WriteCookie(wxUser.Id);
                }
                //log.Info("login:"******"Index", "L"));
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                ViewBag.Info = ex.Message;
                return(View("Info"));
            }
        }
示例#14
0
        /// <summary>
        /// 更新开奖号码
        /// </summary>
        public void UpdateOpenNumber()
        {
            using (var db = new OlaEntities())
            {
                foreach (var item in lotteryInfos)
                {
                    var lottery = db.LotteryOpenHistories
                                  .Where(w => w.LotteryId == item.LotteryId)
                                  .OrderByDescending(w => w.QiHao)
                                  .FirstOrDefault();

                    if (lottery != null)
                    {
                        // 未更新
                        if (LastLotteryOpenHistories.Any(w => w.LotteryId == lottery.LotteryId && w.QiHao == lottery.QiHao))
                        {
                            continue;
                        }
                        needUpdate = true;
                        var lastLotteryOpenHistory = LastLotteryOpenHistories.FirstOrDefault(w => w.LotteryId == lottery.LotteryId);
                        if (lastLotteryOpenHistory != null)
                        {
                            lastLotteryOpenHistory.CreateTime = lottery.CreateTime;
                            lastLotteryOpenHistory.OpenNumber = lottery.OpenNumber;
                            lastLotteryOpenHistory.OpenTime   = lottery.OpenTime;
                            lastLotteryOpenHistory.QiHao      = lottery.QiHao;
                        }
                        else
                        {
                            LastLotteryOpenHistories.Add(lottery);
                        }
                    }
                }
            }
            if (needUpdate)
            {
                try
                {
                    int columns = 5;
                    this.Controls.Clear();
                    int width = this.Width / columns;
                    AddControls("彩种", width, this.Width * 0 / columns, 10);
                    AddControls("期号", width, this.Width * 1 / columns, 10);
                    AddControls("开奖号码", width, this.Width * 2 / columns, 10);
                    AddControls("开奖时间", width, this.Width * 3 / columns, 10);
                    AddControls("获取时间", width, this.Width * 4 / columns, 10);

                    int row    = 1;
                    int height = 35;
                    int y      = 0;
                    foreach (var item in lotteryInfos)
                    {
                        row++;
                        y = row * height;
                        var last = LastLotteryOpenHistories
                                   .FirstOrDefault(w => w.LotteryId == item.LotteryId);
                        if (last != null)
                        {
                            AddControls(item.Name, width, this.Width * 0 / columns, y);
                            AddControls(last.QiHao, width, this.Width * 1 / columns, y);
                            AddControls(last.OpenNumber, width, this.Width * 2 / columns, y);
                            AddControls(last.OpenTime.Substring(5), width, this.Width * 3 / columns, y);
                            AddControls(last.CreateTime.ToString("MM-dd HH:mm:ss"), width, this.Width * 4 / columns, y);
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            }

            needUpdate = false;
        }
示例#15
0
        public void GetLotteryOpenNumberFrom500()
        {
            if (DateTime.Now <= this.NextRequestDT ||
                string.IsNullOrEmpty(this.lottery.url500))
            {
                return;
            }
            try
            {
                var url  = this.lottery.url500.Replace("{date}", DateTime.Now.ToString("yyyyMMdd"));
                var xDoc = XDocument.Load(url);

                var result = from x in xDoc.Descendants("row")
                             select new LotteryOpenHistory
                {
                    OpenNumber = x.Attribute("opencode").Value,
                    QiHao      = this.lottery.Prefix + x.Attribute("expect").Value.Replace("-", ""),
                };
                result = result.OrderBy(w => w.QiHao);
                using (var db = new OlaEntities())
                {
                    foreach (var lotteryOpen in result)
                    {
                        try
                        {
                            var qihao = Convert.ToInt32(lotteryOpen.QiHao);
                            if (qihao < this.NextQiHao)
                            {
                                continue;
                            }
                            var lotteryOpenTimes = db.LotteryOpenTimes
                                                   .FirstOrDefault(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                            if (lotteryOpenTimes != null)
                            {
                                lotteryOpen.OpenTime = lotteryOpenTimes.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                                var history = db.LotteryOpenHistories
                                              .Any(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                                if (!history)
                                {
                                    // 预测
                                    GetForecast(db, lotteryOpen);

                                    lotteryOpen.CreateTime = DateTime.Now;
                                    lotteryOpen.Id         = Guid.NewGuid();
                                    lotteryOpen.LotteryId  = this.lottery.LotteryId;
                                    lotteryOpen.Source     = (int)LotteryOpenNumberSourceEnum.五百彩票;
                                    // 获取前三期的预测号码
                                    GetPreForecast(db, lotteryOpen);
                                    db.LotteryOpenHistories.Add(lotteryOpen);
                                    db.SaveChanges();
                                    UpdateWebClientLotteryOpenInfo(lotteryOpen.LotteryId);
                                    var nextInfo = db.LotteryOpenTimes.FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpenTimes.NextQiHao);
                                    if (nextInfo != null)
                                    {
                                        this.NextQiHao     = Convert.ToInt32(nextInfo.QiHao);
                                        this.NextRequestDT = nextInfo.OpenTime;
                                        log.Info("添加:" + this.lottery.Name + " 期号:" + lotteryOpen.QiHao + " 开奖号码:" + lotteryOpen.OpenNumber + " 获取时间: " + DateTime.Now + " 下次获取时间: " + this.NextRequestDT);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom500 解析数据失败", ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom500 爬取数据失败", ex);
            }
        }
示例#16
0
        public void GetLotteryOpenNumberFromkm28()
        {
            if (DateTime.Now <= this.NextRequestDT ||
                string.IsNullOrEmpty(this.lottery.urlkm28))
            {
                return;
            }
            try
            {
                HtmlWeb htmlWeb = new HtmlWeb();
                HtmlWeb.PreRequestHandler handler = delegate(HttpWebRequest request)
                {
                    request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
                    request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                    request.CookieContainer        = new CookieContainer();
                    return(true);
                };
                htmlWeb.PreRequest += handler;
                var url = this.lottery.urlkm28.Replace("{date}", DateTime.Now.ToString("yyyy-MM-dd"));
                var doc = htmlWeb.Load(url);
                var trs = doc.DocumentNode.SelectNodes("//table[@class='tac fl']/tr");

                var lotteries = new List <LotteryOpenHistory>();
                foreach (var tr in trs)
                {
                    try
                    {
                        var tds = tr.SelectNodes("./td");
                        if (tds == null || tds.Count != 3)
                        {
                            continue;
                        }

                        var period = tds[0].InnerText;
                        if (string.IsNullOrEmpty(period))
                        {
                            continue;
                        }
                        var win_number = tds[2].InnerText;
                        if (string.IsNullOrEmpty(win_number))
                        {
                            continue;
                        }
                        win_number = win_number.Replace(" ", ",");
                        period     = DateTime.Now.ToString("yyyyMMdd") + period;
                        // 过滤掉已经添加的期号
                        var qihao = Convert.ToInt32(period);
                        if (qihao < this.NextQiHao)
                        {
                            continue;
                        }
                        lotteries.Add(new LotteryOpenHistory
                        {
                            OpenNumber = win_number,
                            QiHao      = period,
                        });
                    }
                    catch (Exception ex)
                    {
                        log.Error(this.lottery.Name + " GetLotteryOpenNumberFromkm28 解析数据失败", ex);
                    }
                }

                lotteries = lotteries.OrderBy(w => w.QiHao).ToList();
                //log.Info("下一期期号:" + this.NextQiHao + this.lottery.Name + ":" + lotteries.Count + " " + JsonConvert.SerializeObject(lotteries));
                using (var db = new OlaEntities())
                {
                    foreach (var lotteryOpen in lotteries)
                    {
                        try
                        {
                            var lotteryOpenTimes = db.LotteryOpenTimes
                                                   .FirstOrDefault(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                            if (lotteryOpenTimes != null)
                            {
                                lotteryOpen.OpenTime = lotteryOpenTimes.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                                var history = db.LotteryOpenHistories
                                              .Any(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                                if (!history)
                                {
                                    // 预测
                                    GetForecast(db, lotteryOpen);

                                    lotteryOpen.Id         = Guid.NewGuid();
                                    lotteryOpen.LotteryId  = this.lottery.LotteryId;
                                    lotteryOpen.CreateTime = DateTime.Now;
                                    lotteryOpen.Source     = (int)LotteryOpenNumberSourceEnum.开门彩;
                                    // 获取前三期的预测号码
                                    GetPreForecast(db, lotteryOpen);
                                    db.LotteryOpenHistories.Add(lotteryOpen);
                                    db.SaveChanges();
                                    UpdateWebClientLotteryOpenInfo(lotteryOpen.LotteryId);
                                    var nextInfo = db.LotteryOpenTimes.FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpenTimes.NextQiHao);
                                    if (nextInfo != null)
                                    {
                                        this.NextQiHao     = Convert.ToInt32(nextInfo.QiHao);
                                        this.NextRequestDT = nextInfo.OpenTime;
                                        log.Info("添加:" + this.lottery.Name + " 期号:" + lotteryOpen.QiHao + " 开奖号码:" + lotteryOpen.OpenNumber + " 获取时间: " + DateTime.Now + ":下次获取时间 " + this.NextRequestDT);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 解析数据失败", ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 获取数据失败", ex);
            }
        }
示例#17
0
        public void GetLotteryOpenNumberFromgdlottery()
        {
            if (DateTime.Now <= this.NextRequestDT ||
                string.IsNullOrEmpty(this.lottery.urlgdlottery))
            {
                return;
            }
            try
            {
                HtmlWeb htmlWeb = new HtmlWeb();
                HtmlWeb.PreRequestHandler handler = delegate(HttpWebRequest request)
                {
                    request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
                    request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                    request.CookieContainer        = new CookieContainer();
                    return(true);
                };
                htmlWeb.PreRequest += handler;
                var doc = htmlWeb.Load(this.lottery.urlgdlottery);
                var trs = doc.DocumentNode.SelectNodes("//table[@bordercolorlight='#008000']/tr");
                if (trs == null)
                {
                    return;
                }
                trs.RemoveAt(0);
                trs.RemoveAt(0);

                var lotteries = new List <LotteryOpenHistory>();
                foreach (var tr in trs)
                {
                    try
                    {
                        var tds = tr.ChildNodes;
                        if (tds.Count < 4)
                        {
                            continue;
                        }
                        var period = tds[1].InnerHtml.Trim('\r');
                        var td     = tds[3];
                        var spans  = td.ChildNodes;
                        if (spans.Count < 2)
                        {
                            continue;
                        }
                        var strongs = spans[1].ChildNodes;
                        if (strongs.Count < 2)
                        {
                            continue;
                        }
                        var win_number = strongs[1].InnerHtml.Replace("\r\n\t", "");
                        win_number = win_number.Replace("\r\n\t", "");
                        win_number = win_number.Replace("   \t", "");
                        win_number = win_number.Trim(' ');
                        win_number = win_number.Replace(',', ',');
                        if (string.IsNullOrEmpty(win_number) || string.IsNullOrEmpty(period))
                        {
                            continue;
                        }
                        period = this.lottery.Prefix + period;
                        // 过滤掉已经添加的期号
                        var qihao = Convert.ToInt32(period);
                        if (qihao < this.NextQiHao)
                        {
                            continue;
                        }
                        lotteries.Add(new LotteryOpenHistory
                        {
                            OpenNumber = win_number,
                            QiHao      = period,
                        });
                    }
                    catch (Exception ex)
                    {
                        log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 解析数据失败", ex);
                    }
                }
                lotteries = lotteries.OrderBy(w => w.QiHao).ToList();
                //log.Info("下一期期号:" + this.NextQiHao + this.lottery.Name + ":" + lotteries.Count + " " + JsonConvert.SerializeObject(lotteries));
                using (var db = new OlaEntities())
                {
                    foreach (var lotteryOpen in lotteries)
                    {
                        try
                        {
                            var lotteryOpenTimes = db.LotteryOpenTimes
                                                   .FirstOrDefault(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                            if (lotteryOpenTimes != null)
                            {
                                lotteryOpen.OpenTime = lotteryOpenTimes.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                                var history = db.LotteryOpenHistories
                                              .Any(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                                if (!history)
                                {
                                    // 预测
                                    GetForecast(db, lotteryOpen);

                                    lotteryOpen.Id         = Guid.NewGuid();
                                    lotteryOpen.LotteryId  = this.lottery.LotteryId;
                                    lotteryOpen.CreateTime = DateTime.Now;
                                    lotteryOpen.Source     = (int)LotteryOpenNumberSourceEnum.广东体彩网;

                                    // 获取前三期的预测号码
                                    GetPreForecast(db, lotteryOpen);
                                    db.LotteryOpenHistories.Add(lotteryOpen);
                                    db.SaveChanges();
                                    UpdateWebClientLotteryOpenInfo(lotteryOpen.LotteryId);
                                    var nextInfo = db.LotteryOpenTimes.FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpenTimes.NextQiHao);
                                    if (nextInfo != null)
                                    {
                                        this.NextQiHao     = Convert.ToInt32(nextInfo.QiHao);
                                        this.NextRequestDT = nextInfo.OpenTime;
                                        log.Info("添加:" + this.lottery.Name + " 期号:" + lotteryOpen.QiHao + " 开奖号码:" + lotteryOpen.OpenNumber + " 获取时间: " + DateTime.Now + ":下次获取时间 " + this.NextRequestDT);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 解析数据失败", ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 获取数据失败", ex);
            }
        }