[C#] 纯文本查看 复制代码
private void UpdatetextBox4(object str)
{
if (textBox4.InvokeRequired)
{
Action<string> actionDelegate = (x) => { this.textBox4.AppendText(x.ToString() + "\r\n"); };
this.textBox4.Invoke(actionDelegate, str);
}
else
{
this.textBox4.AppendText(str.ToString() + "\r\n");
}
}
static string Url = "http://hnpi.newzhihui.cn";
static string codeImageCookie = "";
private void Form1_Load(object sender, EventArgs e)
{
piccheck();
}
string[] needLearnYear;
void piccheck()
{
string url = "/validate.do";
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = Url + url,
Method = "GET",
Accept = "text/html, application/xhtml+xml, */*",
ContentType = "text/html",
ResultType = ResultType.Byte,//返回数据类型,是Byte还是String
};
HttpResult result = http.GetHtml(item);
codeImageCookie = result.Cookie;
Bitmap bitmap = (Bitmap)byteArrayToImage(result.ResultByte);
pictureBox1.Image = bitmap;
}
private Image byteArrayToImage(byte[] Bytes)
{
MemoryStream ms = new MemoryStream(Bytes);
return Bitmap.FromStream(ms, true);
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox5.Text.Trim().Length == 0)
{
MessageBox.Show("请填写需要学习的年度", "登陆失败");
return;
}
needLearnYear = textBox5.Text.Trim().Split(',');
string request = newCookiePost("/frontLogin.do", $"loginName={textBox1.Text.Trim()}&password={textBox2.Text.Trim()}&roleType=1&vcode={textBox3.Text.Trim()}&unittitle=1&unit_syscode=1&type=1");
JObject jObject = JObject.Parse(request);
if (jObject["result"].ToString() != "success")
{
MessageBox.Show(jObject["error"].ToString(), "登陆失败");
return;
}
string classList = Post("/study.do?action=getStudyList", "studyState=", codeImageCookie);
JObject JclassList = JObject.Parse(classList);
if (JclassList["result"].ToString() != "success")
{
MessageBox.Show("获取课程信息失败", "提醒");
}
else
{
string list = JclassList["list"].ToString();
if (list.Length == 0)
{
MessageBox.Show("没有需要学习的课程", "提醒");
return;
}
JArray JAClassList = JArray.Parse(list);
for (int a = 0; a < JAClassList.Count; a++)
{
string year = JAClassList[a]["year"].ToString();
if (!isusedLearn(year)) continue;
string name = JAClassList[a]["name"].ToString();
string id = JAClassList[a]["id"].ToString();
string userId = JAClassList[a]["userId"].ToString();
UpdatetextBox4($"正在学习{year}年度-:{name}");
ToStudy(id, codeImageCookie);
}
}
UpdatetextBox4("学习完成");
}
bool isusedLearn(string year)
{
for (int a = 0; a < needLearnYear.Length; a++)
{
if (needLearnYear[a] == year) return true;
}
return false;
}
void ToStudy(string id, string _cookie)
{
string Html = Get("/study.do?action=toStudy&id=" + id, _cookie);
string regexStr = "<div class=\"video-info\" onclick=['\"]*(\\S+)[\"']>";
Regex regex = new Regex(regexStr);
MatchCollection matchs = regex.Matches(Html);
foreach (Match match in matchs)
{
string m = match.Groups[1].Value;
string Id_1 = Between(m, "playVideo('", "','");
string Id_2 = Between(m, "','", "')");
int lastLearnTime = 0;
if (!GetVideoTime(Id_1, out lastLearnTime, _cookie)) continue;
int _nowLearn = lastLearnTime / 40;
bool islearnOver = false;
while (!islearnOver)
{
string _data = $"id={Id_1}&itemRate={_nowLearn}&wareRate={_nowLearn}&time={_nowLearn * 40}";
string updateItemRate = Post("/study.do?action=updateItemRate", _data, _cookie, true);
int itemRate = 0;
try
{
JObject JEnd = JObject.Parse(updateItemRate);
itemRate = int.Parse(JEnd["itemRate"].ToString());
UpdatetextBox4("当前进度:" + itemRate);
}
catch (Exception ex)
{
Console.WriteLine();
UpdatetextBox4("网络访问错误,频繁出现此错误的话请退出重登");
}
finally
{
if (itemRate >= 100)
{
islearnOver = true;
}
}
_nowLearn++;
}
}
}
bool GetVideoTime(string id, out int lastlearnTime, string _cookie)
{
lastlearnTime = 0;
string getWareItemDetail = Post("/study.do?action=getWareItemDetail", "id=" + id, _cookie, true);
JObject jobject = JObject.Parse(getWareItemDetail);
string data = jobject["data"].ToString();
JObject jdata = JObject.Parse(data);
int vTime = int.Parse(jdata["vtime"].ToString());
int uTime = int.Parse(jdata["playTime"].ToString());
lastlearnTime = uTime;
if (vTime == 0)
{
lastlearnTime = 0;
return true;
}
return vTime - uTime > 0 ? true : false;
}
string newCookiePost(string _url, string _data)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = Url + _url,
Cookie = codeImageCookie,
Method = "POST",
Accept = "text/html, application/xhtml+xml, */*",
ContentType = "application/x-www-form-urlencoded",
Postdata = _data,
ResultType = ResultType.String,
};
HttpResult result = http.GetHtml(item);
return result.Html;
}
string Post(string _url, string _data, string _cookie = "", bool iswww = false)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = Url + _url,
Postdata = _data,
Method = "POST",
Cookie = _cookie,
Accept = "text/html, application/xhtml+xml, */*",
ContentType = iswww ? "application/x-www-form-urlencoded" : "application/json",
ResultType = ResultType.String,
};
HttpResult result = http.GetHtml(item);
return result.Html;
}
string Get(string _url, string _cookie = "")
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = Url + _url,
Method = "GET",
Cookie = _cookie,
Accept = "text/html, application/xhtml+xml, */*",
ContentType = "application/json",
ResultType = ResultType.String,
};
HttpResult result = http.GetHtml(item);
return result.Html;
}
string Between(string str, string leftstr, string rightstr)
{
try
{
int i = str.IndexOf(leftstr) + leftstr.Length;
string temp = str.Substring(i, str.IndexOf(rightstr, i) - i);
return temp;
}
catch
{
return "";
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
Url = "http://hnpi.newzhihui.cn";
piccheck();
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
Url = "http://hnpizy.newzhihui.cn";
piccheck();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
piccheck();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
Url = "http://hnpi.newzhihui.cn:81";
piccheck();
}
}