internal static ResponceModel SharedInfoControl(string type, string query) { try { if (type == "" || query == "") { return(ResponceModel.GetInstanceInvalid()); } else if (type == "user") { return(GetUserInfo(query)); } else if (type == "usermd5") { return(GetUserMD5(query)); } else if (type == "termtime") { return(GetTermTime(query)); } else if (type == "schedule") { return(GetSchedule(query)); } else { return(ResponceModel.GetInstanceInvalid()); } } catch (Exception ex) { return(ResponceModel.GetInstanceError(ex)); } }
/// <summary> /// 获取正方课表 注释:typeof(<see cref="ResponceModel.data"/>)=<see cref="List{T}"/>where T:<see cref="CourseUni"/> /// </summary> /// <returns></returns> internal static ResponceModel GetZfCourse(string username, string password, int year = 2017, int term = 3) { try { string param = $"username={username}&password={password}&year={year}&term={term}"; string result = HttpUtil.get(APIKey.Zf_Course, param); //string result = "{'status':'success','msg':[]}"; JObject jObject = (JObject)JsonConvert.DeserializeObject(result); //正确返回 if (jObject["status"].ToString() == "success") { CourseDataZfedu[] data = jObject["msg"].ToObject <CourseDataZfedu[]>(); //通过扩展方法Map将data转化为sqlData. IEnumerable <CourseUni> sqlData = data.Map((m) => new CourseUni(m, year, term)); return(new ResponceModel(200, "获取正方课表成功", sqlData)); } else { string msg = jObject["msg"].ToString(); return(new ResponceModel(403, "用户名或密码错误")); } } catch (Exception ex) { return(ResponceModel.GetInstanceError(ex)); } }
public static ResponceModel GetResponce(string provider) { try { return(new ResponceModel(200, "获取时间成功", Get(provider))); } catch (Exception ex) { return(ResponceModel.GetInstanceError(ex)); } }
internal static ResponceModel GetTermTime(string query) { if (query == null || query == "") { return(ResponceModel.GetInstanceInvalid()); } else { foreach (var item in App.Current.Configuration.GetTimeConfig()) { if (item.provider == query) { return(new ResponceModel(200, "获取信息成功", item.config)); } } return(new ResponceModel(403, "未找到该提供商的学期信息")); } }
/// <summary> /// 获取课表,此方法用于与外部进行交互,依赖<see cref="UserCredit"/>,<see cref="TermTime"/>,<see cref="UserInfoSql"/>。 /// </summary> /// <param name="credit"></param> /// <returns></returns> internal static ResponceModel GetCourse(string credit, int year, int term) { try { if (UserCredit.CheckUser(credit, out string username)) { UserInfoSql userInfo = new UserInfoSql(username); if (userInfo.TryQuery()) { //if (userInfo.courseserver == "ZJUT") //{ if (UserInfo.GetBindInfo(username, "jh").state != 0) { //说明你绑定过正方账号。 if (UserInfo.GetBindInfo(username, "zfedu").state != 0) { if (JhUser.CheckUser(userInfo.jhpid, userInfo.pwbind_jh).code == 200) { //TermTimeUni time = TermTime.Get(); //TermTimeUni time = new TermTimeUni(2019,3,) var result = GetZfCourse(userInfo.jhpid, userInfo.pwbind_zfedu, year, term); if (result.code == 200) { var data = (List <CourseUni>)result.data; if (data.Count > 0) { foreach (var item in data) { if (!item.Exists()) { item.Add(); } userInfo.Linkedcourse = data.Map((m) => m.courseid); userInfo.UpdateLinkedCourse(); } } //if (data.Count > 0) //{ // foreach (var item in data) // { // //在这里我们假设课表信息从不改变,虽然说绝大多数情况下是这样。 // if (!item.Exists()) // { // item.Add(); // } // userInfo.Linkedcourse = data.Map((m) => m.courseid).ToList(); // userInfo.UpdateLinkedCourse(); // } //} return(new ResponceModel(200, "获取课表成功", data)); } else { return(new ResponceModel(403, "请重新绑定正方")); } } else { return(new ResponceModel(403, "请重新绑定正方")); } } else { //SOLVED BUG 这里曾导致未绑定账号但任然显示重新绑定的错误提示信息。 return(new ResponceModel(403, "你还没有绑定正方")); } } else { return(new ResponceModel(403, "请重新绑定精弘账号")); } //} //else //{ // return new ResponceModel(500, "暂不支持这个提供商"); //} } else { return(new ResponceModel(403, "请绑定精弘账号")); } } else { return(new ResponceModel(403, "自动登录失败,请重新登录")); } } catch (Exception ex) { return(ResponceModel.GetInstanceError(ex)); } }