private void button1_Click(object sender, EventArgs e) { try { if (CacheHelper.Token == null || string.IsNullOrEmpty(CacheHelper.Token.msgs)) { helper.Log(ConsoleColor.Red, "企业微信,通信出错请检查!"); WeiXinHelper.CreateLog("weixin", $"企业微信获取token出错", 2); return; } if (!isRun) { Console.Clear(); dic.Clear(); this.dataGridView1.DataSource = new BindingList <User>(); if (int.TryParse(textBox2.Text, out int interval)) { Interval = interval; } Interval = Interval < 10000 ? 10000 : Interval; if (int.TryParse(textBox3.Text, out int begin)) { Begin = begin; } if (Begin < 0 || Begin > 23) { Begin = 8; } if (int.TryParse(textBox4.Text, out int end)) { End = end; } if (End < 0 || End > 23) { Begin = 2; } initHours(); isRun = true; this.button1.Enabled = false; this.button2.Enabled = true; var flag = RefreshUser(); if (!flag) { return; } helper.Log(ConsoleColor.Red, $"开始任务,开始时间{Begin},结束时间 {End}"); helper.Log(ConsoleColor.Yellow, $"开始启动程序,请等待。。。"); } } catch (Exception ex) { WeiXinHelper.CreateLog("main", "★★★★★" + ex, 2); helper.Log(ConsoleColor.Red, "★★★★★" + ex); WeiXinHelper.SendText("13142025891", "★★★★★" + ex, false); } }
private void initUser() { var list = WeiXinHelper.GetUsers(); if (list.Count == 0) { WeiXinHelper.CreateLog("main", " 没有获取到任何用户信息", 2); WeiXinHelper.SendText("13142025891", " 没有获取到任何用户信息", false); } }
private void button2_Click(object sender, EventArgs e) { if (isRun) { foreach (var d in dic.Keys) { if (dic.TryGetValue(d, out User u)) { u.cancelToken.Cancel(); WeiXinHelper.SendText(u.Account, $"{u.Account} 已停止刷任务。", true); } } isRun = false; helper.Log(ConsoleColor.Yellow, $"程序程序!"); this.button1.Enabled = true; this.button2.Enabled = false; } }
public static List <User> GetUsers() { string url = string.Format(getUsers, CacheHelper.Token.msgs); var list = new List <User>(); try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); var respText = ""; using (Stream resStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(resStream, Encoding.UTF8); respText = reader.ReadToEnd(); resStream.Close(); } var jArray = JsonConvert.DeserializeObject <WeinUserResult>(respText); if (jArray != null && jArray.userlist != null && jArray.userlist.Count > 0) { jArray.userlist.ForEach(p => { list.AddRange(User.Clone(p)); }); } } catch (WebException ex) { WeiXinHelper.CreateLog("main", "★★★★★" + ex, 2); //helper.Log(ConsoleColor.Red, "★★★★★" + ex); WeiXinHelper.SendText("13142025891", "★★★★★" + ex, false); //Login(u); } catch (Exception ex) { WeiXinHelper.CreateLog("main", "★★★★★" + ex, 2); //helper.Log(ConsoleColor.Red, "★★★★★" + ex); WeiXinHelper.SendText("13142025891", "★★★★★" + ex, false); } return(list); }
/// <summary> /// Post数据接口 /// </summary> /// <param name="postUrl">接口地址</param> /// <param name="paramData">提交json数据</param> /// <param name="dataEncode">编码方式</param> /// <returns></returns> static string PostWebRequest(string postUrl, string paramData, Encoding dataEncode) { string ret = string.Empty; try { byte[] byteArray = dataEncode.GetBytes(paramData); //转化 HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl)); webReq.Method = "POST"; webReq.ContentType = "application/x-www-form-urlencoded"; webReq.ContentLength = byteArray.Length; Stream newStream = webReq.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length);//写入参数 newStream.Close(); HttpWebResponse response = (HttpWebResponse)webReq.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default); ret = sr.ReadToEnd(); sr.Close(); response.Close(); newStream.Close(); } catch (WebException ex) { WeiXinHelper.CreateLog("main", "★★★★★" + ex, 2); //helper.Log(ConsoleColor.Red, "★★★★★" + ex); WeiXinHelper.SendText("13142025891", "★★★★★" + ex, false); //Login(u); return(ex.Message); } catch (Exception ex) { WeiXinHelper.CreateLog("main", "★★★★★" + ex, 2); //helper.Log(ConsoleColor.Red, "★★★★★" + ex); WeiXinHelper.SendText("13142025891", "★★★★★" + ex, false); return(ex.Message); } return(ret); }
private void Main_Load(object sender, EventArgs e) { refrenshTime = DateTime.Now.AddDays(-1); Interval = 20000; Begin = 8; End = 22; dic = new ConcurrentDictionary <string, User>(); a1 = new MessageBoxShow(ShowMessage); Task.Run(() => { try { while (true) { if (isRun) { RefreshUser(); } System.Threading.Thread.Sleep(1000 * 60 * 10); Refresh(); Console.Clear(); } } catch (Exception ex) { helper.Log(ConsoleColor.Red, "★★★★★" + ex); WeiXinHelper.CreateLog("main", "★★★★★" + ex, 2); WeiXinHelper.SendText("13142025891", "★★★★★" + ex, false); } }); // var str = File.ReadAllText("Users.json", Encoding.Default); //var lst = JsonConvert.DeserializeObject<List<User>>(str); //var sb = new StringBuilder(); this.dataGridView1.AutoGenerateColumns = false; dataGridView1.AllowUserToAddRows = false; dataGridView1.RowHeadersVisible = false; }
private void Refresh() { var hours = DateTime.Now.Hour; if (hours == Begin) { if (refrenshTime.Date != DateTime.Now.Date) { foreach (var d in dic.Keys) { if (dic.TryGetValue(d, out User u)) { u.IsMax = false; u.HasBiaoqian = false; u.IsWapMax = false; } } refrenshTime = DateTime.Now; WeiXinHelper.SendText("", $" {Begin}点初始化所有线程!", false); } } }
private static Msg va(Validate v, string cookie, string account, StringBuilder sb) { Dictionary <string, string> postParams = new Dictionary <string, string>(); postParams.Add("geetest_challenge", v.challenge); postParams.Add("geetest_validate", v.validate); postParams.Add("geetest_seccode", v.validate + "|jordan"); // 要提交的字符串数据。格式形如:user=uesr1&password=123 task_type=1&app=1&pc=2&maxmoney=2000&hasCaptcha=0&captcha_code= string postString = ""; foreach (KeyValuePair <string, string> de in postParams) { //把提交按钮中的中文字符转换成url格式,以防中文或空格等信息 postString += System.Web.HttpUtility.UrlEncode(de.Key.ToString()) + "=" + System.Web.HttpUtility.UrlEncode(de.Value.ToString()) + "&"; } CookieContainer cookieContainer = new CookieContainer(); // 将提交的字符串数据转换成字节数组 byte[] postData = Encoding.ASCII.GetBytes(postString); // 设置提交的相关参数 HttpWebRequest request = WebRequest.Create("http://s.58leke.com/gt3/pc-geetest/ajax_validate") as HttpWebRequest; request.Method = "POST"; request.KeepAlive = false; request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8"; request.ContentLength = postData.Length; request.AllowAutoRedirect = false; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"; request.Headers.Add("Cookie", cookie); // 提交请求数据 System.IO.Stream outputStream = request.GetRequestStream(); outputStream.Write(postData, 0, postData.Length); outputStream.Close(); // 接收返回的页面 HttpWebResponse response = request.GetResponse() as HttpWebResponse; System.IO.Stream responseStream = response.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.GetEncoding("gb2312")); //var cookie = response.Headers.Get("Set-Cookie"); var cookies = response.Headers.Get("Set-Cookie"); var srcString = reader.ReadToEnd(); Log(ConsoleColor.Yellow, $"{account} 提交验证!{srcString}"); WeiXinHelper.CreateLog("wap" + account, $"{account} 提交验证!{srcString}", 3); sb.AppendLine($"{account} 提交验证!{srcString}"); WeiXinHelper.SendText("13142025891", sb.ToString(), false); var jArray = JsonConvert.DeserializeObject <Msg>(srcString); if (jArray == null || jArray.status != "success") { jArray = new Msg { code = "-1", msgs = srcString }; } else { jArray.code = "8"; jArray.msgs = "验证成功!"; } return(jArray); }
public static void Do(User u, string cookie) { Log(ConsoleColor.Green, $"{u.Account} 已开始刷任务,请等待。。。"); WeiXinHelper.SendText("13142025891", $"wap {u.Account} 已经登录成功,开始刷任务请等待。。。", false); while (true) { if (!Main.isRun) { Log(ConsoleColor.White, $"{u.Account} 程序已停止!"); WeiXinHelper.CreateLog(u.Account, $"{u.Account} 程序已停止!", 1); return; } var hours = DateTime.Now.Hour; if (!Main.ListHours.Contains(hours)) { Log(ConsoleColor.Yellow, $"{u.Account} 已经到了暂停任务时间 {Main.End} 点,任务停止,明天{Main.Begin}点开始刷!!"); WeiXinHelper.CreateLog("wap" + u.Account, $"{u.Account} 已经到了暂停任务时间 {Main.End} 点,任务停止,明天{Main.Begin}点开始刷!!", 1); WeiXinHelper.SendText(u.WeiXinId, $"手机端 {u.Account} 已经到了暂停任务时间 {Main.End} 点,任务停止,明天{Main.Begin}点开始刷!!", false); return; } if (u.BeginTime > hours) { Log(ConsoleColor.Yellow, $"{u.Account} 你设定的是 {u.BeginTime}点开始,现在是 {hours}点,任务停止 !"); WeiXinHelper.CreateLog(u.Account, $"{u.Account} 你设定的是 {u.BeginTime}点开始,现在是 {hours}点,任务停止 !", 1); WeiXinHelper.SendText(u.WeiXinId, $"{u.Account} 你设定的是 {u.BeginTime}点开始,现在是 {hours}点,任务停止 !", false); return; } var r = new Msg(); try { u.IsWapMax = false; r = Getdingdan(u, cookie); if (u.cancelToken.IsCancellationRequested) { Log(ConsoleColor.White, $"{u.Account} 已停止!"); WeiXinHelper.CreateLog("wap" + u.Account, $"{u.Account} 已停止刷任务!", 1); break; } if (r.code == "-1") { System.Threading.Thread.Sleep(1000 * 60 * 5); } else if (r.code == "8") { System.Threading.Thread.Sleep(1000 * 60 * 5); } else if (r.code == "2")//登录超时 { WeiXinHelper.SendText("", $"手机端 {u.Account} {r.msgs}", true); } else if (r.code == "1") { u.HasBiaoqian = false; //u.IsComplete = true; //Main.a1.Invoke($"{u.Account} {r.msgs}"); Log(ConsoleColor.Green, $"{u.Account} {r.msgs}"); WeiXinHelper.SendText(u.WeiXinId, $"手机端 {u.Account} 已经刷到任务,马上去做吧!", false); WeiXinHelper.CreateLog("wap" + u.Account, $"{u.Account} 已经刷到任务,马上去做吧!", 1); System.Threading.Thread.Sleep(1000 * 60 * 5); } else if (r.msgs.Contains("任务没完成") || r.msgs.Contains("评价") || r.msgs.Contains("工单未处理")) { if (r.msgs.Contains("标签任务没完成")) { Log(ConsoleColor.Yellow, $"{u.Account} {r.msgs}, 转刷普通任务!"); u.HasBiaoqian = true; } if (r.msgs.Contains("进行中的任务没完成")) { Log(ConsoleColor.Yellow, $"{u.Account} {r.msgs}, 转刷标签任务!"); u.HasBiaoqian = false; } WeiXinHelper.SendText(u.WeiXinId, $"手机端 {u.Account} {r.msgs},快去完成吧!", false); WeiXinHelper.CreateLog("wap" + u.Account, $"{u.Account} {r.msgs},快去完成吧!", 1); Log(ConsoleColor.Yellow, $"{u.Account} {r.msgs}"); u.IsComplete = true; System.Threading.Thread.Sleep(1000 * 60 * 5); } else if (r.msgs.Contains("关闭任务")) { //Main.a1.Invoke($"{u.Account} {r.msgs}"); //Log(ConsoleColor.Yellow, $"{u.Account} {r.msgs}"); WeiXinHelper.CreateLog("wap" + u.Account, $"{u.Account} {r.msgs}", 1); WeiXinHelper.SendText(u.WeiXinId, $"手机端 {u.Account} {r.msgs} ,暂停5分钟再刷,请等待!", false); u.IsComplete = false; System.Threading.Thread.Sleep(1000 * 60 * 5); } else if (r.msgs.Contains("已上限")) { //Main.a1.Invoke($"{u.Account} {r.msgs}"); Log(ConsoleColor.Yellow, $"{u.Account} {r.msgs},明天{Main.Begin}点开始刷!!"); WeiXinHelper.CreateLog("wap" + u.Account, $"{u.Account} {r.msgs} ,明天{Main.Begin}点开始刷!!", 1); WeiXinHelper.SendText(u.WeiXinId, $" 手机端 {u.Account} {r.msgs},!明天{Main.Begin}点开始刷!!", true); u.IsComplete = false; u.IsWapMax = true; return; //System.Threading.Thread.Sleep(1000 * 60*60*6); } else { //Log(ConsoleColor.Yellow, $"{u.Account} {r.msgs}"); WeiXinHelper.CreateLog("wap" + u.Account, $"{u.Account} {r.msgs}", 1); u.IsComplete = false; System.Threading.Thread.Sleep(Main.Interval); } } catch (WebException er) { Log(ConsoleColor.Red, $"{u.Account} 刷任务出错,error: {er.Message} "); WeiXinHelper.CreateLog("wap" + u.Account, $"{u.Account} 刷任务出错,error: {er.Message} ", 2); System.Threading.Thread.Sleep(1000 * 10); } catch (Exception e) { Log(ConsoleColor.Red, $"{u.Account} 返回出错,error: {e.Message} "); WeiXinHelper.CreateLog("wap" + u.Account, $"{u.Account} 返回出错,error: {e.Message} ", 2); System.Threading.Thread.Sleep(1000 * 10); } } }
private bool RefreshUser() { var list = WeiXinHelper.GetUsers(); if (list.Count == 0) { WeiXinHelper.CreateLog("main", " 没有获取到任何用户信息", 2); WeiXinHelper.SendText("13142025891", " 没有获取到任何用户信息", false); MessageBox.Show("没有获取到任何用户信息 ,请确认!"); return(false); } else { WeiXinHelper.CreateLog("main", " 拉取用户数据成功", 1); } var startList = new List <string>(); foreach (var user in list) { User u = null; if (dic.TryGetValue(user.Account, out u)) { if (user.IsRun) { if (!u.IsRun) { if (dic.TryRemove(user.Account, out u)) { var newu = new User { Account = u.Account, IsRun = true, Wap = user.Wap, BeginTime = user.BeginTime, Pass = u.Pass, UserName = u.UserName, WeiXinId = u.WeiXinId, cancelToken = new CancellationTokenSource(), IsComplete = u.IsComplete, IsMax = u.IsMax, IsWapMax = u.IsWapMax, HasBiaoqian = u.HasBiaoqian, EndTime = user.EndTime, days = user.days }; ShowMessage(u, 2); ShowMessage(newu, 1); dic.TryAdd(newu.Account, newu); startList.Add(newu.Account); } } else { u.Wap = user.Wap; u.BeginTime = user.BeginTime; u.EndTime = user.EndTime; u.days = user.days; } } else { u.IsRun = false; u.cancelToken.Cancel(); } } else { user.cancelToken = new CancellationTokenSource(); if (user.IsRun == true) { startList.Add(user.Account); } if (user.group == WeiXinHelper.userGroup) { dic.TryAdd(user.Account, user); ShowMessage(user, 1); } } } Start(startList); ShowMessage(null, 3); return(true); }
private void Start(List <string> list) { Task.Run(() => { try { foreach (var d in list) { if (dic.TryGetValue(d, out User u)) { Task.Run(() => { try { while (true) { if (u.cancelToken.IsCancellationRequested) { helper.Log(ConsoleColor.Red, u.Account + " 停止,退出线程"); WeiXinHelper.CreateLog(u.Account, "停止,退出线程", 1); break; } var hours = DateTime.Now.Hour; if (!u.IsMax && ListHours.Contains(hours) && u.BeginTime <= hours) { helper.Login(u); } helper.Log(ConsoleColor.Red, u.Account + " 不再程序执行时间内或者 今天已经max!"); WeiXinHelper.CreateLog(u.Account, "不再程序执行时间内或者 今天已经max!", 1); System.Threading.Thread.Sleep(1000 * 10 * 5); u.HasBiaoqian = false; //Refresh(u); } } catch (Exception ex) { WeiXinHelper.CreateLog(u.Account, "★★★★★" + ex, 2); helper.Log(ConsoleColor.Red, "★★★★★" + ex); WeiXinHelper.SendText("13142025891", "★★★★★" + ex, false); } return(1); }); System.Threading.Thread.Sleep(1000 * 10); if (u.Wap) { Task.Run(() => { try { while (true) { if (u.cancelToken.IsCancellationRequested) { helper.Log(ConsoleColor.Red, u.Account + " 停止,退出线程"); WeiXinHelper.CreateLog(u.Account, "停止,退出线程", 1); break; } var hours = DateTime.Now.Hour; if (!u.IsWapMax && ListHours.Contains(hours) && u.BeginTime <= hours) { waphelper.Login(u); } helper.Log(ConsoleColor.Red, u.Account + " 不再程序执行时间内或者 今天已经max!"); WeiXinHelper.CreateLog(u.Account, "不再程序执行时间内或者 今天已经max!", 1); u.HasBiaoqian = false; System.Threading.Thread.Sleep(1000 * 60 * 5); //Refresh(u); } } catch (Exception ex) { WeiXinHelper.CreateLog(u.Account, "★★★★★" + ex, 2); helper.Log(ConsoleColor.Red, "★★★★★" + ex); WeiXinHelper.SendText("13142025891", "★★★★★" + ex, false); } return(1); }); } System.Threading.Thread.Sleep(10000); } } } catch (Exception ex) { WeiXinHelper.CreateLog("main", "★★★★★" + ex, 2); helper.Log(ConsoleColor.Red, "★★★★★" + ex); WeiXinHelper.SendText("13142025891", "★★★★★" + ex, false); } return(1); }); }