/// <summary> /// 从主要链接查询开奖号码 昨天/今天 /// </summary> /// <param name="IsToday"></param> /// <returns></returns> private List <GuiZhou11x5Entity> GetDocByMainUrl(bool IsToday = true) { var list = new List <GuiZhou11x5Entity>(); try { var time = DateTime.Now; var arg = new OpenCaiApiArg { code = EnumHelper.GetLotteryCode(SCCLottery.GuiZhou11x5), // rows = int.Parse(GetPeriodsNumberToDay(time, IsToday)), date = time.ToString("yyyy-MM-dd") }; if (!IsToday) { arg.date = time.AddDays(-1).ToString("yyyy-MM-dd"); } var data = OpenCaiApiServices.GetOpenCaiApiData(arg); if (data == null) { return(list); } if (data.data != null) { if (data.data.Count == 0) { return(list); } for (var i = 0; i < data.data.Count; i++) { var tmp = new GuiZhou11x5Entity { Id = int.Parse(data.data[i].GetTermStr()), OpenCode = data.data[i].GetOpenCodeStr(), OpenTime = DateTime.Parse(data.data[i].opentime) }; list.Add(tmp); } var checkDataHelper = new CheckDataHelper(); var dbdata = services.GetListIn(currentLottery, IsToday) .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()); checkDataHelper.CheckData(dbdata, list.ToDictionary(w => w.Id.ToString(), w => w.OpenCode), Config.Area, currentLottery); } } catch (Exception ee) { log.Error(GetType(), string.Format("【{0}】通过站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ee.Message)); } return(list); }
/// <summary> /// 从备用链接查询开奖号码 昨天/今天 /// </summary> /// <param name="IsToday"></param> /// <returns></returns> private List <GuiZhou11x5Entity> GetDocByBackUrl(bool IsToday = true) { var list = new List <GuiZhou11x5Entity>(); try { var date = CommonHelper.SCCSysDateTime.ToSCCDateTimeString3(); if (!IsToday) { date = CommonHelper.SCCSysDateTime.AddDays(-1).ToSCCDateTimeString3(); } var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 var timeStamp1 = (long)(DateTime.Now - startTime).TotalSeconds; // 相差秒数 var timeStamp2 = timeStamp1 + new Random().Next(100, 1000); //http://www.17mcp.com/out/json/kjgaopinkuayu.do?mark=list&type=3&pubdate=2017-11-19&callbackparam=jsonp1511164496643&_=1511166091893 //string url = string.Format(@"{0}mark=list&type=3&pubdate={1}&callbackparam=jsonp{2}&_={3}",Config.MainUrl, date, timeStamp1, timeStamp2); var url = string.Format(@"{0}mark=list&type=3&pubdate={1}", Config.BackUrl, date); var HtmlResource = NetHelper.GetUrlResponse(url, "POST", "1"); HtmlResource = HtmlResource.Replace("null", ""); HtmlResource = HtmlResource.Replace("(", ""); HtmlResource = HtmlResource.Replace(")", ""); // 去掉不能用的部分 if (HtmlResource == null) { return(list); } var obj = HtmlResource.JsonToEntity <JArray>(); for (var i = 0; i < obj.First["kjgplist"].Count(); i++) { var tmp = new GuiZhou11x5Entity { Id = int.Parse(obj.First["kjgplist"][i]["qihao"].ToString()), OpenCode = CommonHelper.TRHandleCode(obj.First["kjgplist"][i]["haoma"].ToString()), OpenTime = GetOpenTimeByPeriodNum(int.Parse(obj.First["kjgplist"][i]["qihao"].ToString())) }; list.Add(tmp); } var checkDataHelper = new CheckDataHelper(); var dbdata = services.GetListIn(currentLottery, IsToday) .ToDictionary(w => w.Term.ToString(), w => w.GetCodeStr()); checkDataHelper.CheckData(dbdata, list.ToDictionary(w => w.Id.ToString(), w => w.OpenCode), Config.Area, currentLottery); } catch (Exception ee) { log.Error(GetType(), string.Format("【{0}】通过站点抓取开奖列表时发生错误,错误信息【{1}】", Config.Area + currentLottery, ee.Message)); } return(list); }
/// <summary> /// 插入单条 /// </summary> /// <param name="data"></param> /// <returns></returns> public bool SaveRecord(GuiZhou11x5Entity data) { var model = new OpenCode5Model(); model.Term = Convert.ToInt64(data.Id); //期号 var haoMaArray = data.OpenCode.Split(','); model.OpenCode1 = Convert.ToInt32(haoMaArray[0]); model.OpenCode2 = Convert.ToInt32(haoMaArray[1]); model.OpenCode3 = Convert.ToInt32(haoMaArray[2]); model.OpenCode4 = Convert.ToInt32(haoMaArray[3]); model.OpenCode5 = Convert.ToInt32(haoMaArray[4]); model.OpenTime = data.OpenTime; if (services.AddOpen5Code(currentLottery, model)) { GetMaxPeriodNum((int)model.Term); //添加成功存放期数 return(true); } return(false); }