Esempio n. 1
0
        public async Task <TransportResult> ReadyToSign()
        {
            if (State != SessionState.Alive)
            {
                throw new NotSupportedException("只有为 Alive 的会话才能准备签到。");
            }

            TransportResult result = new TransportResult {
                Url = "/plugin.php?id=dsu_paulsign:sign&mobile=yes"
            };
            var request = await HttpRequest.Create(
                "http://www.tsdm.net/plugin.php?id=dsu_paulsign:sign&mobile=yes")
                          .SetUserAgent(UserAgent)
                          .AddCookies(new Uri("http://www.tsdm.net"), Cookies)
                          .Get()
                          .Wait();

            SetCookies(request.Response);
            ID = Cookies["gkr8_2132_sid"].Value;
            var data = request.GetDataAsString();

            if (data.Contains("您今天已经签到过了或者签到时间还未开始"))
            {
                result.Message = "您今天已经签到过了或者签到时间还未开始";
                result.Status  = -1;
                result.Url     = "/plugin.php?id=dsu_paulsign:sign&mobile=yes";

                Logger.Log(LogType.Information, $"由于今天已经签到,签到失败");

                return(result);
            }

            var match = Regex.Match(data, "<input type=\"hidden\" name=\"formhash\" value=\"(?<Hash>[a-zA-Z0-9]*)\">");

            if (!match.Success)
            {
                result.Message = "获取表格 Hash 失败,无法进行签到。";
                result.Status  = -1;

                Logger.Log(LogType.Warning, $"无法获取表格 hash");

                return(result);
            }

            var formHash = match.Groups["Hash"].Value;

            result.Values = new Dictionary <string, string>();
            result.Values.Add("formhash", formHash);


            Logger.Log(LogType.Information, $"获取签到表格hash:{formHash}");

            return(result);
        }
Esempio n. 2
0
        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);
        }