/// <summary> /// 彩种编码 /// </summary> /// <param name="code">彩种编码</param> /// <param name="name">彩种名称</param> public SysBase(string code, string name) { this.Code = code; this.Name = name; if (!string.IsNullOrEmpty(this.Code)) { this.SysLottery = _sysLotteryDal.GetSysLotteryByCode(this.Code); } }
private static DateTime?OpenTime = null; //开奖时间 public static void QqSsc() { try { //http://api.b1cp.com/t?p=json&t=qqffc&token=FF446B723EB25993 //http://www.b1cp.com/api?p=json&t=txffc&limit=1&token=00fb782bad8e5241 Log.Debug("开始腾迅分分彩..."); SysLotteryModel sysLottery = _lotteryDal.GetSysLotteryByCode("qqffc"); if (sysLottery == null || string.IsNullOrEmpty(sysLottery.ApiUrl)) { throw new Exception("无效的API配置"); } //Stopwatch sw = new Stopwatch(); //sw.Start(); // 开始监视代码运行时间 //如果上期开奖时间大于1分钟 if (OpenTime.HasValue && OpenTime.Value.AddSeconds(60) > DateTime.Now) { return; } //string url = "http://api.b1cp.com/t?p=json&t=txffc&token=776E371D7EF404E4"; //IList<ByLottery> data = ByHelper.GetLotteryData(url); IList <ByLottery> data = ByHelper.GetLotteryData(sysLottery.ApiUrl); //sw.Stop(); // 停止监视 //Log.DebugFormat("获取腾迅分分彩花费时间: {0}毫秒", sw.Elapsed.Milliseconds); foreach (ByLottery lot in data) { string openTime = lot.opentime; string openCode = lot.opencode; string expect = lot.expect; //期号 expect = expect.Substring(0, 8) + "-" + expect.Substring(8); //存储开奖号码 if (_dal.Update(1005, expect, openCode, openTime, openCode)) { OpenTime = Convert.ToDateTime(openTime); //开奖时间 Public.SaveLotteryData2File(1005); //存储开奖号码到JSON/XML文件 LotteryCheck.RunOfIssueNum(1005, expect); //处理开奖信息 } } } catch (Exception ex) { Log.ErrorFormat("腾讯分分彩异常: {0}", ex); //new LogExceptionDAL().Save("采集异常", "腾讯分分彩获取开奖数据出错,错误代码:" + ex.Message); } }
/// <summary> /// 更新彩票数据 /// </summary> /// <param name="code">彩票编码</param> public static void UpdateData(object code = null) { try { //http://api.b1cp.com/t?p=json&t=qqffc&token=FF446B723EB25993 //http://www.b1cp.com/api?p=json&t=txffc&limit=1&token=00fb782bad8e5241 //Log.Debug("开始QqSsc..."); //if (code == "ssl") //{ // string test = ""; //} SysLotteryModel sysLottery = _lotteryDal.GetSysLotteryByCode(code.ToString()); Log.DebugFormat("获取开奖信息: {0} {1}", sysLottery.Title, sysLottery.Code); if (sysLottery == null || string.IsNullOrEmpty(sysLottery.ApiUrl)) { throw new Exception("无效的API配置"); } int lotId = sysLottery.Id; //彩票Id IList <ByLottery> data = ByHelper.GetLotteryData(sysLottery.ApiUrl); foreach (ByLottery lot in data) { string openTime = lot.opentime; string openCode = lot.opencode; string expect = lot.expect; //期号 expect = GetExpect(code.ToString(), expect); if (_dal.Update(lotId, expect, openCode, openTime, openCode)) { Public.SaveLotteryData2File(lotId); LotteryCheck.RunOfIssueNum(lotId, expect); Log.DebugFormat("发布开奖信息: {0} {1}", sysLottery.Title, openCode); } Log.DebugFormat("开奖信息详细: {0} {1} {2}", sysLottery.Title, expect, openCode); } } catch (Exception ex) { Log.ErrorFormat("官方彩票异常: {0} {1}", code != null ? code.ToString() : "奖种无效", ex); //new LogExceptionDAL().Save("采集异常", "腾讯分分彩获取开奖数据出错,错误代码:" + ex.Message); } }