/// <summary> /// 下注 /// </summary> /// <param name="periodNo">期号</param> /// <param name="rule">玩法枚举</param> /// <param name="number">下注号码</param> /// <param name="money">单个号码金额</param> public void Bet(long periodNo, Pk10Rule rule, string number, decimal money) { LotteryData lotteryData = GetLotteryData(); PrintLog($"{Environment.NewLine}即将下注,账户余额:¥ [{lotteryData.Balance}], 玩法: [{rule.GetAttributeValue()}],号码: [{number}], 下注金额: {money}."); string url = $"bet/bet.do?_t={DateTime.UtcNow.Ticks}"; // 构建表单参数 var betParam = new BetParam(periodNo, rule, number, money); var postBodyBuilder = new StringBuilder(); postBodyBuilder.Append($"gameId={betParam.GameId}&turnNum={betParam.TurnNum}&totalNums={betParam.TotalNums}"); postBodyBuilder.Append($"&totalMoney={betParam.TotalMoney}&betSrc={betParam.BetSrc}"); for (int idx = 0; idx < betParam.BetBeanList.Count; idx++) { var bean = betParam.BetBeanList[idx]; postBodyBuilder.Append($"&betBean[{idx}].playId={bean.PlayId}&betBean[{idx}].money={bean.Money}"); } // 提交投注 try { BetResult result = _restHelper.Post <BetResult>(url, postBodyBuilder.ToString()); if (!result.Success) { if (result.Msg.Contains("该账号在异地登陆")) { LoginTimeout = true; throw new ArgumentException("该账号在异地登陆, 请重试!"); } else { throw new ArgumentException($"{result.Msg}, 状态码: {result.Code}."); } } else { PrintLog($"下注成功, 当前账户余额: {lotteryData.Balance}"); } } catch (Exception ex) { throw ex; } }
private static bool CheckIsWin(Pk10Rule rule, string betNo, string drawNo) { if (string.IsNullOrWhiteSpace(betNo) || string.IsNullOrWhiteSpace(drawNo)) { return(false); } var betNos = betNo.Split(','); var winNos = drawNo.Split(','); if (!betNos.Any() || winNos.Length < 10) { return(false); } var champion = Convert.ToInt32(winNos[0]); var second = Convert.ToInt32(winNos[1]); var tenth = Convert.ToInt32(winNos[9]); switch (rule) { case Pk10Rule.Champion: case Pk10Rule.Second: case Pk10Rule.Third: case Pk10Rule.Fourth: return(betNos.Contains(winNos[(int)rule - 1])); case Pk10Rule.BigOrSmall: return(string.Equals(betNos[0], champion > 5 ? "大" : "小")); case Pk10Rule.OddOrEven: return(string.Equals(betNos[0], champion % 2 != 0 ? "单" : "双")); case Pk10Rule.DragonOrTiger: return(string.Equals(betNos[0], champion > tenth ? "龙" : "虎")); case Pk10Rule.Sum: return(betNos.Contains((champion + second).ToString().PadLeft(2, '0'))); } return(false); }
/// <param name="periodNo">期号</param> /// <param name="rule">玩法枚举</param> /// <param name="number">下注号码</param> /// <param name="money">单个号码金额</param> public BetParam(long periodNo, Pk10Rule rule, string number, decimal money) { this.TurnNum = periodNo; string[] arrNums = CheckNumberValid(rule, number); BetBeanList = new List <BetBean>(); foreach (string num in arrNums) { RulePlayId rulePlayId = Da2088Helper.GetPlayId(rule, num); if (rulePlayId == null) { throw new ArgumentOutOfRangeException($"玩法 {rule.GetAttributeValue()}, 下注号码: {num}, 下注号码不合规则!"); } BetBeanList.Add(new BetBean(rulePlayId.PlayId, money)); } // 初始化总金额 TotalNums = arrNums.Length; TotalMoney = arrNums.Length * money; }
/// <summary> /// 检查下注号码是否有效 /// </summary> /// <param name="number"></param> /// <param name="arrNums"></param> private string[] CheckNumberValid(Pk10Rule rule, string number) { string[] arrNums = number.Split(','); if (arrNums == null || arrNums.Length <= 0) { throw new ArgumentException($"下注失败! \t 详情: 下注号码({number})为空."); } // 委托,测试号码是否有效 Func <string, bool> IsValidNumberFunc = (n) => { if (rule >= Pk10Rule.BigOrSmall && rule <= Pk10Rule.DragonOrTiger) { return(true); } bool parseResult = int.TryParse(n, out int m); if (!parseResult) { return(false); } if (m < 1 || m > 19) { return(false); } return(true); }; if (!arrNums.Any(IsValidNumberFunc)) { throw new ArgumentException($"下注失败! \t 详情: 下注号码({number})格式不正确,请检查后重试!"); } return(arrNums); }
public DataCollectedEventArgs(LotteryType lottery, Pk10Rule rule, List <IForecastPlanModel> plans) { this.Lottery = lottery; this.Rule = rule; this.Plans = plans; }
public CollectErrorEventArgs(Pk10Rule rule, string errorMessage) { this.Rule = rule; this.Exception = new Exception(errorMessage); }
public CollectErrorEventArgs(Pk10Rule rule, Exception exception) { this.Rule = rule; this.Exception = exception; }
public static int ToInt(this Pk10Rule rule) => (int)rule;
public static Pk10RuleType ToPk10RuleType(this Pk10Rule rule) => (int)rule <= 4 ? Pk10RuleType.SingleNo : (rule == Sum ? Pk10RuleType.FirstAndSecondGroup : Pk10RuleType.TwoSides);
public static string ToStringName(this Pk10Rule rule) => Pk10Rules[rule];
public RulePlayId(Pk10Rule rule, string num, uint playId) { this.Rule = rule; this.Number = num; this.PlayId = playId; }
public static RulePlayId GetPlayId(Pk10Rule rule, string num) { return(RulePlayIdContainer.FirstOrDefault(x => x.Rule == rule && x.Number == num)); }
private async Task StartPk10(Pk10Rule rule) { var prefix = $"{LotteryType.Pk10}_{rule}"; //大管家Job,负责创建每期的扫水Job var stewardJob = QuartzUtil.CreateSimpleJob($"{prefix}_Steward_Job", $"{LotteryType.Pk10}_JobGroup", Scan); /* * 北京赛车时间为每天9:00到23:50,每5分钟开一期,共179期 (北京时间) * * “0 1/5 9-23 * * ?” * 每天9点到23点,每5分钟的第1分钟第0秒。如 9:01:00,9:06:00 ... 9:56:00 ... 23:51:00,23:56:00 * * 9-23(GMT+08:00) => 1-15(UTC) */ var pk10Trigger = QuartzUtil.CreateTrigger(prefix, "JinMaTrigger", $"0 1/5 {1.ToLocalHour()}-{15.ToLocalHour()} * * ?"); //启动定时扫水 await QuartzUtil.GetScheduler().ScheduleJob(stewardJob, pk10Trigger); async void Scan() { var timestamp = DateTime.UtcNow; var periodNo = Pk10Scheduler.Instance.GetPeriodNo(timestamp); var locked = new RulePeriodLocked(rule, periodNo); var jobTrigger = $"{prefix}_Scan_{periodNo}".ToJobTrigger(); var trigger = QuartzUtil.CreateTrigger(jobTrigger.Trigger, "0/5 * * * * ? *"); var job = QuartzUtil.CreateSimpleJob(jobTrigger.Job, () => { //避免第一轮任务执行未完成时第二轮任务开始执行,锁定 同一种玩法同一期 任务 lock (locked) { //Job废弃 if (locked.Finished) { return; } //超时自毁 if ((DateTime.UtcNow - timestamp).TotalMinutes > 5) { QuartzUtil.TryDestroyJob(jobTrigger).Wait(); locked.Finish(); return; } //扫水 var task = JinMaAnalyzer.Instance.GetForecastData(LotteryType.Pk10, (int)rule); task.Wait(); var plans = task.Result; /* * 如果目标网站接口正常,每次都可以扫到结果,即使没有更新最新期预测数据。所以如果没有扫水结果,说明目标网站接口出错或扫到到数据异常 */ if (plans == null) { DataCollectedError?.Invoke(this, new CollectErrorEventArgs(rule, "扫水异常或数据数据错误")); return; } //扫到老数据 if (plans.Any(p => p.LastDrawnPeriod + 1 < periodNo)) { return; } //成功扫到最新数据 JinMaAnalyzer.Instance.CalcuteScore(plans); DataCollectedSuccess?.Invoke(this, new DataCollectedEventArgs(LotteryType.Pk10, rule, plans)); //扫水成功自毁 QuartzUtil.TryDestroyJob(jobTrigger).Wait(); locked.Finish(); } }); await QuartzUtil.GetScheduler().ScheduleJob(job, trigger); } }
public RulePeriodLocked(Pk10Rule rule, long periodNo) { Rule = rule; PeriodNo = periodNo; Finished = false; }