netcore 使用Topshelf 每天 自动模拟向乐柠签到

前言

  用友旗下乐柠是我们经销商程序员定期学习的地方 培训等,每天签到能拿积分换去课程来学习ERP相关,每天签到太累

调度器直接上一篇文章(netcore 使用Topshelf 每天定时备份云服务器数据库备份)的 轮子WooDispatch 

 

任务及模拟登录过程

public class LeningJob : IJob
    {
        public LeningConfig leningConfig;
        public ILogService logService;

        public LeningJob(IOptions<LeningConfig> options,ILogService _logService)
        {
            leningConfig= options.Value;
            logService = _logService;
        }

        public Task Execute(IJobExecutionContext context)
        {

            var Jobname = $"{context.JobDetail.Key.Group}.{context.JobDetail.Key.Name}";

            RestClient restClient = new RestClient("http://www.lening100.com/login!userLoginn.action");
            var client = new RestClient("http://www.lening100.com/login!userLoginn.action");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddHeader("Host", "www.lening100.com");

            request.AddParameter("username",  leningConfig.UserName);
            request.AddParameter("password",  leningConfig.Password);
            IRestResponse response = client.Execute(request);
            var result =  response.Content;
            var clientqd = new RestClient("http://www.lening100.com/new-pages/attend/user!userAttend.action");
            clientqd.Timeout = -1;
            var requestqd = new RestRequest(Method.POST);
            requestqd.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            requestqd.AddHeader("Host", "www.lening100.com");
            for (int i = 0; i < response.Cookies.Count(); i++)
            {
                requestqd.AddParameter(response.Cookies[i].Name, response.Cookies[i].Value,ParameterType.Cookie);
            }
            var date = DateTime.Now;
            string data = $"year={date.ToString("yyyy")}&month={date.ToString("MM")}&day={date.ToString("dd")}";
            requestqd.AddParameter("year", date.ToString("yyyy"));
            requestqd.AddParameter("month", date.ToString("MM"));
            requestqd.AddParameter("day", date.ToString("dd"));
            IRestResponse responseqd = clientqd.Execute(requestqd);
            if (!responseqd.IsSuccessful)
            {
                logService.Error(Jobname, $"签到失败 错误码:{(int)responseqd.StatusCode}", responseqd.Content);
            }
            else
            {
                if (responseqd.Content == "ok")
                {
                    logService.Error(Jobname, "签到成功");
                }
                else if (responseqd.Content == "2")
                {
                    
                    logService.Warn(Jobname, $"今天已经签到过了");
                }
                else
                {
                    logService.Info(Jobname, responseqd.Content);
                }
            }
            

            return Task.CompletedTask;
        }
    }

  

原文地址:https://www.cnblogs.com/leoxjy/p/12101323.html