public void DoCourse(SafetreeTask SafetreeCourse) { foreach (var req in SafetreeCourse.ReqList) { var r = client.Simple(req).Content; Colorful.WriteLine($"#Response: {r.Substring(0, Math.Min(80, r.Length))}"); //Thread.Sleep(200); } }
static void Main(string[] args) { Console.WriteLine(); if (args.Length == 0) { Colorful.LogError("命令行参数错误"); return; } var taskname = args[0]; var taskdir = $"./{taskname}/"; var taskList = new List <SafetreeTask>(); try { foreach (var f in Directory.GetFiles(taskdir, "*.har")) { //todo: course activity var t = SafetreeTask.ParseCourse(File.ReadAllText(f)); taskList.Add(t); } var infotxt = Directory.GetFiles(taskdir, "$*.txt")[0]; foreach (var a in File.ReadAllLines(infotxt)) { Console.WriteLine(); var strs = a.Replace(" ", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var username = ""; var password = ""; try { username = strs[0]; if (strs.Length <= 1) { password = "******"; } else { password = strs[1]; } } catch (Exception) { Colorful.LogWarning($"处理账号中的某一行发生错误:'{a}' "); continue; } var client = new SafetreeClient(); var district = new FileInfo(infotxt).Name.TrimStart(new char[] { '$' }).Replace(".txt", ""); var LoginRes = client.Login(username, password, district); if (LoginRes) { Colorful.LogSuccess($"登陆成功: {username}"); } else { Colorful.LogWarning($"登陆失败: {username}"); continue; } foreach (var t in taskList) { client.DoCourse(t); } } } catch (Exception ee) { Colorful.LogWarning(ee.Message); return; } }
public static SafetreeTask ParseCourse(string HAR) { string[] Containing = { "_method=SkillCheckName", "_method=TemplateIn2", "_method=Skill_ThirdRecord", "SubmitTest", "Step=1", }; var har = HAR.FromJSON <HARFile>(); var reqs = from p in har.log.entries select p.request; var t = new SafetreeTask(); foreach (var req in reqs) { foreach (var con in Containing) { if (req.url.Contains(con)) { t.AddRequest(req.ToRequest()); if (con == "Step=1") { var clone = req; clone.url = clone.url.Replace("Step=1", "Step=2"); t.AddRequest(clone.ToRequest()); } break; } } } /* * try * { * var H_CheckCourse = (from p in reqs where p.method == "POST" && p.url.Contains("_method=SkillCheckName") select p).ToArray()[0]; * var Req_CheckCourse = H_CheckCourse.ToRequest(); * t.ReqList.Add(Req_CheckCourse); * } * catch { } * * try * { * var H_Exercise = (from p in reqs where p.method == "POST" && p.url.Contains("_method=TemplateIn2") select p).ToArray()[0]; * var Req_Exercise = H_Exercise.ToRequest(); * t.ReqList.Add(Req_Exercise); * } * catch { } * * try * { * var H_SubmitTest=(from p in reqs where p.method == "POST" && p.url.Contains("SubmitTest") select p).ToArray()[0]; * t.ReqList.Add(H_SubmitTest.ToRequest()); * } * catch { } * * try * { * var H_step1 = (from p in reqs where p.method == "GET" && p.url.Contains("Step=1") select p).ToArray()[0]; * t.ReqList.Add(H_step1.ToRequest()); * * H_step1.url = H_step1.url.Replace("Step=1", "Step=2"); * t.ReqList.Add(H_step1.ToRequest()); * } * catch { } */ return(t); }