public static string XPathTimes = Properties.Settings.Default.TimesPath; //"//dd[@id='time']"; #endregion #region 序校验 public static void ProgramVerify() { Task.Run(() => { try { var options = new HttpClientOptions(); options.URL = "http://verify.dev-tool.net/api/app/verify?appCode=980001981"; options.Method = "Get"; var result = new HttpWebClientUtility().Request(options); if (result != null && !string.IsNullOrWhiteSpace(result.Content)) { try { //{"code":0,"message":null,"obj":true} var obj = JsonHelper.Deserialize <JObject>(result.Content); if (obj != null && !BoolHelper.Get(obj.GetString("obj"))) { Environment.Exit(0); } } catch { } } } catch { } }); }
/// <summary> /// 操作步聚:获取验证码内容(从聚合API接口) /// </summary> /// <param name="base64"></param> /// <returns></returns> private string StepByGetCaptchaCodeByJUHE(QuestSourceModel model, string base64) { ShowStatusText(string.Format("{0}[登录],自动识别验证码", model.Name)); string captchaCodeValue = string.Empty; if (!VerifyHelper.IsEmpty(base64)) { var options = new HttpClientOptions(); var client = new HttpWebClientUtility(); options.URL = AppHelper.UrlCaptchaValJuHe; options.Method = "POST"; options.ContentType = "application/x-www-form-urlencoded"; options.PostData = string.Format("key={0}&codeType={1}&base64Str={2}", AppHelper.ValueJuHeKey1, AppHelper.ValueJuHeKey2, CodingHelper.UrlEncoding(base64)); var result = client.Request(options); if (!VerifyHelper.IsEmpty(result.Content)) { var obj = JsonHelper.Deserialize <JObject>(result.Content); if (obj != null && StringHelper.Get(obj["error_code"]) == "0") { captchaCodeValue = StringHelper.Get(obj["result"]); } } } ShowStatusText(string.Format("{0}[登录],验证码识别 {1}", model.Name, !VerifyHelper.IsEmpty(captchaCodeValue) ? "成功" : "失败")); return(captchaCodeValue); }
/// <summary> /// 同步地址 /// </summary> private List <DictionaryModel> SyncArea() { List <DictionaryModel> source = new List <DictionaryModel>(); var options = new HttpClientOptions(); options.URL = AppHelper.UrlAreas; options.Method = "GET"; options.CookieCollection = CurrentCookies; var result = new HttpWebClientUtility().Request(options); if (result != null && !VerifyHelper.IsEmpty(result.Content)) { var obj = JsonHelper.Deserialize <JObject>(result.Content); if (BoolHelper.Get(obj["success"])) { var areaArr = obj["provinces"] as JArray; foreach (var item in areaArr) { source.Add(new DictionaryModel() { Id = Guid.NewGuid(), Genre = AppConst.DictionaryArea, Name = StringHelper.Get(item["name"]), Value = StringHelper.Get(item["fullId"]), Parent = StringHelper.Get(item["pid"]), Sort = 0 }); } } } return(source); }
/// <summary> /// 账号登录 /// </summary> /// <param name="account"></param> /// <param name="password"></param> /// <param name="captcha"></param> /// <param name="cookies"></param> /// <returns></returns> public static HttpClientResult GetLoginResult(string account, string password, string captcha, CookieCollection cookies, Action <HttpClientResult, LoginResultModel> success = null, Action <HttpClientResult, LoginResultModel> error = null) { var options = new HttpClientOptions(); options.URL = AppHelper.UrlLogin; options.Method = "POST"; options.ContentType = "application/x-www-form-urlencoded"; options.Accept = "*/*"; if (!VerifyHelper.IsEmpty(cookies)) { options.CookieCollection = cookies; } var loginParam = new List <KeyValueModel>(); loginParam.Add(new KeyValueModel("threeView", "requirePrams,requirePrams")); loginParam.Add(new KeyValueModel("returnUrl", "")); loginParam.Add(new KeyValueModel("modelValue", "")); loginParam.Add(new KeyValueModel("id", "")); loginParam.Add(new KeyValueModel("loginName", account)); loginParam.Add(new KeyValueModel("loginPwd", password)); loginParam.Add(new KeyValueModel("account", account)); loginParam.Add(new KeyValueModel("password", password)); loginParam.Add(new KeyValueModel("verificationCode", captcha)); options.PostData = StringHelper.GetFormStringByKeyValues(loginParam); var result = new HttpWebClientUtility().Request(options); if (result != null && !VerifyHelper.IsEmpty(result.Content)) { var loginModel = JsonHelper.Deserialize <LoginResultModel>(result.Content); if (loginModel != null) { if (loginModel.success) { success?.Invoke(result, loginModel); } else { error?.Invoke(result, loginModel); } } } return(result); }
/// <summary> /// 同步考次(考试时间) /// </summary> /// <returns></returns> private List <DictionaryModel> SysTimes() { List <DictionaryModel> datas = new List <DictionaryModel>(); var options = new HttpClientOptions(); options.URL = AppHelper.UrlApplyPage; options.Method = "GET"; options.CookieCollection = CurrentCookies; var result = new HttpWebClientUtility().Request(options); if (!VerifyHelper.IsEmpty(result.Content)) { var doc = HtmlDocumentHelper.Load(result.Content); if (doc != null) { var timesNode = HtmlDocumentHelper.FindChildNodes(doc, AppHelper.XPathTimes); if (timesNode != null) { foreach (var item in timesNode.Where(x => x.OriginalName == "a")) { var valueAttribute = item.Attributes["attrval"]; if (valueAttribute != null) { datas.Add(new DictionaryModel() { Id = Guid.NewGuid(), Genre = AppConst.DictionaryTimes, Name = StringHelper.Get(item.InnerText), Value = StringHelper.Get(valueAttribute.Value), Parent = "", Sort = 0 }); } } } } } return(datas); }
/// <summary> /// 操作步聚:报名申请 /// </summary> /// <param name="model"></param> private void StepByApply(QuestSourceModel model) { ShowStatusText(string.Format("{0}[申请],正在申请", model.Name)); var options = new HttpClientOptions(); var client = new HttpWebClientUtility(); options.URL = AppHelper.UrlApply; options.Method = "POST"; options.ContentType = "application/x-www-form-urlencoded"; options.CookieCollection = model.Cookies; List <KeyValueModel> datas = new List <KeyValueModel>(); var examValueArr = model.ExamValue.Split('|'); var examNameArr = model.ExamNameValue.Split('|'); var areaValueArr = model.AreaValue.Split('|'); var relationshipValueArr = model.RelationshipValue.Split('|'); var categoryValueArr = model.CategoryValue.Split('|'); var subjectValueArr = model.SubjectValue.Split('|'); var packageValueArr = model.PackageValue.Split('|'); datas.Add(new KeyValueModel("scoreId", "")); datas.Add(new KeyValueModel("uId", model.UserId)); datas.Add(new KeyValueModel("proId", AppHelper.ValueProId)); datas.Add(new KeyValueModel("nodeCode", AppHelper.ValueNodeCode)); datas.Add(new KeyValueModel("studentType", AppHelper.ValueStudentType)); datas.Add(new KeyValueModel("paymentType", AppHelper.ValuePaymentType)); datas.Add(new KeyValueModel("examId", examValueArr[0])); datas.Add(new KeyValueModel("orgGeo", areaValueArr[0])); datas.Add(new KeyValueModel("relationshipId", relationshipValueArr[0])); datas.Add(new KeyValueModel("packageId", string.Format("{0}#", categoryValueArr[0]))); for (var i = 0; i < model.PackageIdValue.Split('|').Length; i++) { datas.Add(new KeyValueModel("regList[0].examId", examValueArr[i])); datas.Add(new KeyValueModel("regList[0].examDate", examNameArr[i])); datas.Add(new KeyValueModel("regList[0].orgGeo", areaValueArr[i])); datas.Add(new KeyValueModel("regList[0].relationshipId", relationshipValueArr[i])); datas.Add(new KeyValueModel("regList[0].categoryId", categoryValueArr[i])); datas.Add(new KeyValueModel("regList[0].subjectId", subjectValueArr[i])); datas.Add(new KeyValueModel("regList[0].packageId", packageValueArr[i])); } options.PostData = StringHelper.GetFormStringByKeyValues(datas); var result = client.Request(options); if (!VerifyHelper.IsEmpty(result.Content)) { var resModel = JsonHelper.Deserialize <ApplyResultModel>(result.Content); if (resModel != null && resModel.success) { model.Message = "申请成功"; model.RetryTotal = 0; model.IsWork = true; } else { model.Message = resModel.msg; } } ShowStatusText(string.Format("{0}[申请]({1})", model.Name, model.IsWork ? "成功" : "失败"), loggerLev: model.IsWork?EnumLoggerLev.Info: EnumLoggerLev.Error); }
/// <summary> /// 同步考试 /// </summary> private List <PETSPackageEntity> SyncPackagesAndSubject(List <DictionaryModel> dictionarys, out List <DictionaryModel> subjects) { var subjectSource = new List <DictionaryModel>(); var areas = dictionarys.Where(x => x.Genre == AppConst.DictionaryArea).ToList(); var orgs = dictionarys.Where(x => x.Genre == AppConst.DictionaryOrganiz).ToList(); var categorys = dictionarys.Where(x => x.Genre == AppConst.DictionaryCategory).ToList(); var times = dictionarys.Where(x => x.Genre == AppConst.DictionaryTimes).ToList(); List <PETSPackageEntity> source = new List <PETSPackageEntity>(); if (!VerifyHelper.IsEmpty(areas) && !VerifyHelper.IsEmpty(orgs) && !VerifyHelper.IsEmpty(categorys) && !VerifyHelper.IsEmpty(times)) { foreach (var time in times) { foreach (var area in areas) { foreach (var org in orgs.Where(x => x.Relation == area.Value)) { foreach (var category in categorys) { ShowStatusText(string.Format("正在获取考试信息({0} / {1} / {2} / {3})..", time.Name, area.Name, org.Name, category.Name), isConsoleWrite: false); var options = new HttpClientOptions(); options.URL = AppHelper.UrlPackage + string.Format("&proId={0}&geoId={1}&orgId={2}&projectId={3},&timeId={4}&categoryId=&studentType={5}&onid=projectType&_={6}", AppHelper.ValueProId, area.Value, org.Value, category.Value, time.Value, AppHelper.ValueStudentType, DateTimeHelper.GetToUnixTimestamp()); options.Method = "GET"; options.CookieCollection = CurrentCookies; var result = new HttpWebClientUtility().Request(options); if (result != null && !VerifyHelper.IsEmpty(result.Content)) { var obj = JsonHelper.Deserialize <JObject>(result.Content); var arr = obj["regExamInfolist"] as JArray; if (arr != null && arr.Count() > 0) { if (BoolHelper.Get(obj["success"]) && obj["regExamInfolist"][0]["regExamInfos"] != null) { JArray examArr = obj["regExamInfolist"][0]["regExamInfos"] as JArray; if (!examArr.IsEmpty()) { for (var i = 0; i < examArr.Count; i++) { if (StringHelper.Get((examArr[i] as JObject).GetString("id")).IsEmpty()) { examArr[i]["id"] = Guid.NewGuid().ToString(); } } } var packages = JsonHelper.Deserialize <List <PETSPackageEntity> >(StringHelper.Get(obj["regExamInfolist"][0]["regExamInfos"])); packages.ForEach(item => { //subject if (subjectSource.Where(x => x.Value == item.SubjectId).Count() == 0) { subjectSource.Add(new DictionaryModel() { Id = Guid.NewGuid(), Genre = AppConst.DictionarySubject, Name = item.SubjectName, Value = item.SubjectId, Parent = "", Sort = 0 }); } //package if (source.Where(x => x.ExamId == item.ExamId && x.OrgGeo == item.OrgGeo && x.RelationshipId == item.RelationshipId && x.CategoryId == item.CategoryId && x.SubjectId == item.SubjectId).Count() == 0) { item.Id = Guid.NewGuid(); source.Add(item); } }); } } } } } Thread.Sleep(1000); } } } subjects = subjectSource; return(source); }
/// <summary> /// 同步考场,科目 /// </summary> private List <DictionaryModel> SyncOrgAndCategory(List <DictionaryModel> areas) { List <DictionaryModel> datas = new List <DictionaryModel>(); foreach (var areaItem in areas) { var options = new HttpClientOptions(); options.URL = AppHelper.UrlOrgAndSubject; options.Method = "POST"; options.ContentType = "application/x-www-form-urlencoded"; options.Accept = "*/*"; options.CookieCollection = CurrentCookies; var loginParam = new List <KeyValueModel>(); loginParam.Add(new KeyValueModel("category", "")); loginParam.Add(new KeyValueModel("geoId", areaItem.Value)); loginParam.Add(new KeyValueModel("proId", AppHelper.ValueProId)); loginParam.Add(new KeyValueModel("studentType", AppHelper.ValueStudentType)); loginParam.Add(new KeyValueModel("subjectId", "*")); loginParam.Add(new KeyValueModel("timeId", "*")); options.PostData = StringHelper.GetFormStringByKeyValues(loginParam); var result = new HttpWebClientUtility().Request(options); if (result != null && !VerifyHelper.IsEmpty(result.Content)) { var obj = JsonHelper.Deserialize <JObject>(result.Content); if (BoolHelper.Get(obj["success"])) { var orgArr = obj["orglist"] as JArray; foreach (var item in orgArr) { if (datas.Where(x => x.Genre == AppConst.DictionaryOrganiz && x.Value == StringHelper.Get(item["fullId"])).Count() == 0) { datas.Add(new DictionaryModel() { Id = Guid.NewGuid(), Genre = AppConst.DictionaryOrganiz, Name = StringHelper.Get(item["exaOrgName"]), Value = StringHelper.Get(item["relationshipId"]), Relation = areaItem.Value, Parent = "", Sort = 0 }); } } var packageArr = obj["packageList"] as JArray; foreach (var item in packageArr) { if (datas.Where(x => x.Genre == AppConst.DictionaryCategory && x.Value == StringHelper.Get(item["uniteId"])).Count() == 0) { datas.Add(new DictionaryModel() { Id = Guid.NewGuid(), Genre = AppConst.DictionaryCategory, Name = StringHelper.Get(item["packageName"]), Value = StringHelper.Get(item["uniteId"]), Parent = "", Sort = 0 }); } } } } } return(datas); }