private void logbtn_Click(object sender, EventArgs e) { //检验学号是否有错 string userID = this.UserIDtxt.Text; string Userpwd = this.pwdtxt.Text; try { logInfo log = new logInfo(userID, Userpwd, "88839057e4cf4dd638d506fc6d5a74b6", "pUFSRNnNDBvXG7Tk" , "142", "lab4", "lab4", "js_xxx", "b1d4cc7a-382c-5a15-4c48-0af29b036f43", "fake"); string json = GetJson(log); //获取Cookies CookieContainer Cookies = Getcookie(json, "https://jxnu.huitu.zhishulib.com/api/1/login"); string content = GetContent(Cookies, "https://jxnu.huitu.zhishulib.com/Station/Station/getUnreadMessageCount?LAB_JSON=1"); //判断是否登录成功 Regex regex = new Regex("\"is_login\":[\\s]true", RegexOptions.None); if (regex.IsMatch(content)) { Regex reg = new Regex("\"uid\":[\\s]\"(?<uid>[\\d]+?)\"", RegexOptions.None); //记录用户登录时的ID string UserID = reg.Match(content).Groups["uid"].Value; if (userFrm == null || userFrm.IsDisposed) { userFrm = new userfrm(); userFrm.Cookie = Cookies; userFrm.userID = UserID; userFrm.Show(); this.RealHide(); } } } catch (Exception ex) { MessageBox.Show(ex.Message + "登录失败"); return; } }
private string GetJson(logInfo log) { JavaScriptSerializer json = new JavaScriptSerializer(); return(json.Serialize(log)); }