public async Task <string> Force() { if (isLoading) { return("请等待上次操作完成"); } try { isLoading = true; var res = await CXHttp.Connect("http://gw.bnu.edu.cn:803/srun_portal_pc.php") .Data("action", "logout") .Data("ajax", "1") .Data("username", Username) .Data("password", Password) .Post(); var body = await res.Content("UTF-8"); return(body); } catch (Exception e) { return(e.Message); } finally { isLoading = false; } }
public async Task <UserInfo> GetUserInfo() { if (isLoading) { return new UserInfo() { Error = "请等待上次操作完成" } } ; try { isLoading = true; var res = await CXHttp.Connect("http://172.16.202.201:8069/user/status/" + Username).Get(); var body = await res.Content(); var info = JsonConvert.DeserializeObject <UserInfo>(body); return(info); } catch (Exception e) { return(new UserInfo() { Error = e.Message }); } finally { isLoading = false; } }
public async Task <string> Logout() { if (isLoading) { return("请等待上次操作完成"); } try { isLoading = true; if (!localSettings.Values.ContainsKey(AppConstants.GATEWAY_IP)) { return("尚未登录。若实际已登录,请尝试强制离线。"); } var ip = (string)localSettings.Values[AppConstants.GATEWAY_IP]; var res = await CXHttp.Connect("http://gw.bnu.edu.cn:803/srun_portal_pc.php") .Data("action", "auto_logout") .Data("ajax", "1") .Data("info", "") .Data("user_ip", ip) .Post(); return(await res.Content("UTF-8")); } catch (Exception e) { return(e.Message); } finally { isLoading = false; } }
public static async Task <List <Building> > GetBuildings() { var buildings = new List <Building>(); try { var res = await CXHttp.Connect("http://202.112.88.59:8082/buildings").Get(); var body = await res.Content(); body = body.Trim(); if (body == "error" || body == "") { return(buildings); } string[] roomInfo = body.Split(','); for (int i = 0; i < roomInfo.Length; i += 2) { buildings.Add(new Building(roomInfo[i], roomInfo[i + 1])); } } catch { buildings.Add(new Building(null, "获取失败")); } return(buildings); }
private async void LoadQrCode(String usnm) { if (usnm == null) { localSettings.Values.Remove(AppConstants.QRCODE); qrcode.Visibility = Visibility.Visible; qrcodeRow.Height = GridLength.Auto; return; } var res = await CXHttp.Connect("http://xuhongxu.cn/xiaoya/has.php?name=" + usnm) .Get(); var body = await res.Content(); if (body.Contains("TRUE")) { localSettings.Values[AppConstants.QRCODE] = true; qrcode.Visibility = Visibility.Collapsed; qrcodeRow.Height = new GridLength(0); } else { localSettings.Values.Remove(AppConstants.QRCODE); qrcode.Visibility = Visibility.Visible; qrcodeRow.Height = GridLength.Auto; } }
private async void Test1() { textBox.Text += "Test1 Started\n"; var t = await CXHttp.Connect("http://www.baidu.com").Get(); var body = await t.Content(); if (body.Contains("百度")) { textBox.Text += "Test1 Succeed: Get Baidu.com\n"; } else { textBox.Text += "Test1 Failed: Get Baidu.com\n"; } }
private async void Test3() { var URL = "http://cas.bnu.edu.cn/cas/login?service=http%3A%2F%2Fzyfw.bnu.edu.cn%2FMainFrm.html"; textBox.Text += "Test3 Started\n"; var t = await CXHttp.Session("zyfw").Req .Url(URL) .Header("User-Agent", USER_AGENT) .Get(); string body = await t.Content(); Match mc = Regex.Match(body, "input type=\"hidden\" name=\"lt\" value=\"(.*)\""); string lt = mc.Groups[1].Value; mc = Regex.Match(body, "input type=\"hidden\" name=\"execution\" value=\"(.*)\""); string exec = mc.Groups[1].Value; t = await CXHttp.Session("zyfw").Req .Url(URL) .ClearCookies() .Header("User-Agent", USER_AGENT) .Data("username", "用户名") .Data("password", "密码") .Data("code", "code") .Data("lt", lt) .Data("execution", exec) .Data("_eventId", "submit") .Post(); body = await t.Content("GBK"); if (body.Contains("注销")) { textBox.Text += "Test3 Succeed: Session Login BNU 教务\n"; } else { textBox.Text += "Test3 Failed: Session Login BNU 教务\n"; } }
public static async Task <List <Room> > GetRooms(string buildingId) { var room = new List <Room>(); try { var res = await CXHttp.Connect("http://202.112.88.59:8082/building/" + buildingId).Get(); var body = await res.Content(); body = body.Trim(); if (body == "error") { return(room); } string[] roomInfoArr = body.Split(';'); foreach (var info in roomInfoArr) { if (info.Trim() == "") { continue; } string[] roomInfo = info.Trim().Split(','); Room item = new Room(roomInfo[0]); for (int i = 5; i < 17; ++i) { item.HasLecture.Add(roomInfo[i].Trim() == "0"); } item.UpdateColors(); room.Add(item); } } catch { room.Add(new Room("获取失败")); } return(room.OrderBy(o => o.Name).ToList()); }
/// <summary> /// 国际交流合作处 /// </summary> /// <returns></returns> public static async Task <List <News> > GetOIECNews() { List <News> news = new List <News>(); try { var res = await CXHttp.Connect("http://oiec.bnu.edu.cn/zh-hans/jingwaixuexi/") .Get(); var body = await res.Content(); var doc = m_Parser.Parse(body); var programList = doc.GetElementsByClassName("program_list"); if (programList.Length > 0) { var ul = programList[0]; foreach (var div in ul.GetElementsByClassName("title")) { var a = div.GetElementsByTagName("a"); if (a.Length > 0) { var item = a[0]; var uri = new Uri(new Uri("http://oiec.bnu.edu.cn/zh-hans/jingwaixuexi/"), new Uri(item.GetAttribute("href"))); news.Add(new News(item.TextContent.Trim(), "", uri)); } } } if (news.Count == 0) { news.Add(new News("请连接校园网", "", new Uri(@"about:blank"))); } } catch { news.Add(new News("获取失败", "", new Uri(@"about:blank"))); } return(news); }
private async void Test2() { textBox.Text += "Test2 Started\n"; var t = await CXHttp.Connect("http://gw.bnu.edu.cn:803/srun_portal_pc.php?ac_id=1") .Data("action", "login") .Data("ac_id", "1") .Data("username", "学号") .Data("password", "密码") .Post(); var body = await t.Content(); if (body.Contains("成功") || body.Contains("Error")) { textBox.Text += "Test2 Succeed: Post BNU Gateway Login\n"; } else { textBox.Text += "Test2 Failed: Post BNU Gateway Login\n"; } }
/// <summary> /// 教务处 /// </summary> /// <returns></returns> public static async Task <List <News> > GetJWCNews() { List <News> news = new List <News>(); try { var res = await CXHttp.Connect("http://jwc.bnu.edu.cn/tzgg/index.html") .Get(); var body = await res.Content("UTF-8"); var doc = m_Parser.Parse(body); var list = doc.GetElementsByClassName("ul_list"); if (list.Length > 0) { var ul = list[0]; foreach (var li in ul.GetElementsByTagName("li")) { var a = li.GetElementsByTagName("a"); if (a.Length > 0) { var item = a[0]; var timeSpan = li.GetElementsByClassName("newtime"); if (timeSpan.Length > 0) { var uri = new Uri(new Uri(@"http://jwc.bnu.edu.cn/tzgg/index.html"), item.GetAttribute("href")); news.Add(new News(item.TextContent.Trim(), timeSpan[0].TextContent.Trim(), uri)); } } } } } catch { news.Add(new News("获取失败", "", new Uri(@"about:blank"))); } return(news); }
/// <summary> /// 图书馆新闻动态 /// </summary> /// <returns></returns> public static async Task <List <News> > GetLIBNews() { List <News> news = new List <News>(); try { var res = await CXHttp.Connect("http://www.lib.bnu.edu.cn/-") .Get(); var body = await res.Content(); var doc = m_Parser.Parse(body); var list = doc.GetElementsByClassName("item-list"); if (list.Length > 0) { foreach (var li in list[0].GetElementsByTagName("li")) { var a = li.GetElementsByTagName("a"); if (a.Length > 0) { var span = li.LastChild; if (span != null) { var uri = new Uri(new Uri(@"http://www.lib.bnu.edu.cn/-"), a[0].GetAttribute("href")); news.Add(new News(a[0].TextContent.Trim(), span.TextContent.Trim(), uri)); } } } } } catch { news.Add(new News("获取失败", "", new Uri(@"about:blank"))); } return(news); }
public async Task <string> Login() { if (isLoading) { return("请等待上次操作完成"); } try { isLoading = true; var res = await CXHttp.Connect("http://gw.bnu.edu.cn:803/srun_portal_pc.php?ac_id=1&") .Data("action", "login") .Data("ac_id", "1") .Data("user_ip", "") .Data("nas_ip", "") .Data("user_mac", "") .Data("url", "") .Data("ajax", "1") .Data("save_me", "1") .Data("username", Username) .Data("password", Password) .Post(); var body = await res.Content("UTF-8"); var info = body.Split(',')[0]; res = await CXHttp.Connect("http://gw.bnu.edu.cn:803/include/auth_action.php?k=") .Data("action", "get_online_info") .Post(); body = await res.Content("UTF-8"); if (body == "not_online") { return(info); } info += "," + body; var fields = info.Split(','); localSettings.Values[AppConstants.GATEWAY_IP] = fields[6]; int s = Convert.ToInt32(fields[2]); int m = s / 60; s %= 60; int h = m / 60; m %= 60; string ret = "已用流量:" + (Convert.ToDouble(fields[1]) / 1024 / 1024).ToString("0.##MB") + "\n" + "已用时长:" + h + "时" + m + "分" + s + "秒\n" + "账户余额:" + fields[3] + "元\n"; return(ret); } catch (Exception e) { return(e.Message); } finally { isLoading = false; } }
/// <summary> /// Get week number of today for specific semester /// </summary> /// <param name="year">If <c>null</c> is provided, current semester will be used</param> /// <param name="semester"></param> /// <returns></returns> public static async Task <int> GetCurrentWeek(string year = null, string semester = null) { try { if (m_Week != -1 && m_Today.Date != DateTime.Now.Date) { return(m_Week); } m_Today = DateTime.Now; if (year == null) { var res = await CXHttp.Connect("http://zyfw.prsc.bnu.edu.cn/jw/common/showYearTerm.action") .Header("User-Agent", USER_AGENT) .Get(); var body = await res.Content(); Semester s = JsonConvert.DeserializeObject <Semester>(body); year = s.Xn; semester = s.XqM; } var res2 = await CXHttp.Connect("http://zyfw.prsc.bnu.edu.cn/public/getTeachingWeekByDate.action") .Header("User-Agent", USER_AGENT) .Data("xn", year) .Data("xq_m", semester) .Data("hidOption", "getWeek") .Data("hdrq", DateTime.Now.ToString("yyyy-MM-dd")) .Post(); var body2 = await res2.Content(); string[] weeks = body2.Split('@'); m_Week = Convert.ToInt32(weeks[0]); localSettings.Values[AppConstants.TIMETABLE_WEEK] = m_Week; localSettings.Values[AppConstants.TIMETABLE_DATE] = DateTime.Now.ToBinary(); return(m_Week); } catch { if (localSettings.Values.ContainsKey(AppConstants.TIMETABLE_WEEK) && localSettings.Values.ContainsKey(AppConstants.TIMETABLE_DATE)) { m_Week = (int)localSettings.Values[AppConstants.TIMETABLE_WEEK]; var then = DateTime.FromBinary((long)localSettings.Values[AppConstants.TIMETABLE_DATE]); int diffDay = (DateTime.Now - then).Days; for (int i = 0; i < 7; ++i) { if (then.DayOfWeek == WEEKS[i]) { diffDay -= i; } } int diffWeek = diffDay / 7; m_Week += diffWeek; localSettings.Values[AppConstants.TIMETABLE_WEEK] = m_Week; localSettings.Values[AppConstants.TIMETABLE_DATE] = DateTime.Now.ToBinary(); return(m_Week); } return(1); } }