private async void DispatcherTimerOnTick(object sender, EventArgs eventArgs) { DispatcherTimer.Stop(); var session = (App.Current as App).ViewModel.Session; if (session.State != SessionState.Alive) { Logger.Log(LogType.Information, $"由于用户未登录,本次签到中止"); DispatcherTimer.Interval = new TimeSpan(0, 1, 0, 0); DispatcherTimer.Start(); Logger.Log(LogType.Information, $"自动签到计时开始,下一次尝试签到在{DispatcherTimer.Interval}后"); return; } var ready = await session.ReadyToSign(); if (ready.Status != 0) { if (ready.Message == "您今天已经签到过了或者签到时间还未开始") { var nextTry = (DateTime.Now.Date + TimeSpan.FromDays(1) + TimeSpan.FromHours(1)) - DateTime.Now; DispatcherTimer.Interval = nextTry; DispatcherTimer.Start(); Logger.Log(LogType.Information, $"自动签到计时开始,下一次尝试签到在{DispatcherTimer.Interval}后"); return; } DispatcherTimer.Interval = new TimeSpan(0, 1, 0, 0); DispatcherTimer.Start(); Logger.Log(LogType.Information, $"自动签到计时开始,下一次尝试签到在{DispatcherTimer.Interval}后"); return; } String content = "无聊..."; SignMood signMood = SignMood.Boring; if ((App.Current as App).ViewModel.AutofillList.Count > 0) { Random ran = new Random(); var s = (App.Current as App).ViewModel.AutofillList[ran.Next((App.Current as App).ViewModel.AutofillList.Count)]; content = s.Content; signMood = (SignMood)s.SignMoodValue; } var result = await(App.Current as App).ViewModel.Session.Sign(signMood, content, ready.Values["formhash"]); if (result.Status == 0) { var nextTry = (DateTime.Now.Date + TimeSpan.FromDays(1) + TimeSpan.FromHours(1)) - DateTime.Now; DispatcherTimer.Interval = nextTry; DispatcherTimer.Start(); Logger.Log(LogType.Information, $"自动签到计时开始,下一次尝试签到在{DispatcherTimer.Interval}后"); return; } DispatcherTimer.Interval = new TimeSpan(0, 1, 0, 0); DispatcherTimer.Start(); Logger.Log(LogType.Information, $"自动签到计时开始,下一次尝试签到在{DispatcherTimer.Interval}后"); return; }
public async Task <TransportResult> Sign(SignMood mood, String content, String formHash) { //<input type="hidden" name="formhash" value="1c5d4ab8"> if (State != SessionState.Alive) { throw new NotSupportedException("只有为 Alive 的会话才能签到。"); } TransportResult result = new TransportResult { Url = "/plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=0&inajax=0&mobile=yes" }; String moodValue = null; switch (mood) { case SignMood.Sad: moodValue = "ng"; break; case SignMood.Depressed: moodValue = "ym"; break; case SignMood.Boring: moodValue = "wl"; break; case SignMood.Anger: moodValue = "nu"; break; case SignMood.Sweat: moodValue = "ch"; break; case SignMood.Struggle: moodValue = "fd"; break; case SignMood.Lazy: moodValue = "yl"; break; case SignMood.Decline: moodValue = "shuai"; break; case SignMood.Happy: default: moodValue = "kx"; break; } String submit = $"qdmode=1&formhash={formHash}&todaysay={HttpUtility.UrlEncode(content)}&qdxq={moodValue}&"; Stream submitStream = new MemoryStream(Encoding.UTF8.GetBytes(submit)); Logger.Log(LogType.Information, $"开始签到,签到心情:{mood},签到内容:{content},表格hash:{formHash}"); var request = await HttpRequest.Create( "http://www.tsdm.net/plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=0&inajax=0&mobile=yes") .SetUserAgent(UserAgent).SetContentType("application/x-www-form-urlencoded; charset=UTF-8") .AddCookies(new Uri("http://www.tsdm.net"), Cookies) .Post(submitStream) .Wait(); SetCookies(request.Response); ID = Cookies["gkr8_2132_sid"].Value; var data = request.GetDataAsString(); var match = Regex.Match(data, "<div id=\"messagetext\">[\\s]*<p>(?<Message>[^<]*)</p>"); if (!match.Success) { Logger.Log(LogType.Error, $"由于不明原因签到失败"); result.Message = "获取签到结果失败。"; result.Status = -1; return(result); } result.Message = match.Groups["Message"].Value; if (result.Message.Contains("恭喜你签到成功!")) { result.Status = 0; match = Regex.Match(result.Message, @"恭喜你签到成功!获得随机奖励 (?<Reward>[^\.]*?) \."); if (match.Success) { result.Values = new Dictionary <string, string>(); result.Values.Add("reward", match.Groups["Message"].Value); } Logger.Log(LogType.Information, $"签到成功,获得奖励{match.Groups["Message"].Value}"); (App.Current as App).NotifyIcon.ShowBalloonTip(3000, "签到成功", $"签到成功,获得奖励{match.Groups["Message"].Value}", ToolTipIcon.Info); (App.Current as App).ViewModel.CheckSignTime = DateTime.Now; (App.Current as App).ViewModel.IsSignedToday = true; } else { result.Status = -1; Logger.Log(LogType.Error, $"签到失败,{result.Message}"); } return(result); }