public static async Task <bool> GetIsBookingGrade(HttpBaseService _httpService, string username) { try { var queryString = $"/{username}"; var re = await _httpService.SendRequst(bookingGradeUri + queryString, HttpMethod.Get); var result = Newtonsoft.Json.JsonConvert.DeserializeObject <BookingGradeResult>(re); switch (result.Code) { case 200: return(true); case 201: return(false); default: return(false); } } catch { throw; } }
public static async Task <IList <Models.SalaryModel> > QuerySalaries(HttpBaseService _httpService, string studentID, string name) { string re = null; try { var dic = new Dictionary <string, string>(); dic.Add("StudentID", studentID); dic.Add("Name", name); re = await _httpService.SendRequst(querySalaryUri, HttpMethod.Post, dic); var json = Newtonsoft.Json.Linq.JObject.Parse(re); var salariesStr = json["salaries"].ToString(); var salaries = Newtonsoft.Json.JsonConvert.DeserializeObject <IList <Models.SalaryModel> >(salariesStr); return(salaries); } catch (HttpRequestException) { throw new Exception("网络请求出现错误"); } catch (Newtonsoft.Json.JsonException) { throw new Exception("遇到不规则的数据格式!"); } }
//public class RegistModel //{ // public string Username { get; set; } // public string Password { get; set; } // public string NickName { get; set; } // public Gender Gender { get; set; } // public int Age { get; set; } // public string EMail { get; set; } // public string PhoneNumber { get; set; } //} public async Task RegistAsync(HttpBaseService httpService, RegistModel model) { try { var passwordHash = Helpers.Utility.GetMD5(model.Password); var dic = new Dictionary <string, string>(); dic.Add("Username", model.Username); dic.Add("Password", passwordHash); dic.Add("Nickname", model.NickName); dic.Add("Gender", model.Gender.ToString()); dic.Add("Age", model.Age.ToString()); dic.Add("College", model.College.ToString()); var re = await httpService.SendRequst(registUri, HttpMethod.Post, dic); if (string.IsNullOrEmpty(re)) { throw new LoginTipException("服务故障"); } var resultModel = Newtonsoft.Json.JsonConvert.DeserializeObject <RegistResultModel>(re); if (resultModel == null) { throw new LoginTipException("服务故障"); } switch (resultModel.Code) { case 200: break; case 300: throw new LoginTipException("该用户名已经注册"); case 400: throw new LoginTipException("注册信息填写错误"); case 500: throw new LoginTipException("服务故障"); default: throw new LoginTipException($"未知异常 Code:{resultModel.Code}"); } } catch (HttpRequestException) { throw new LoginTipException("服务故障"); } catch { throw; } }
public static async Task <BookingGradeResult> UnBookingGrade(HttpBaseService _httpService, string username, string password) { try { var queryString = $"?username={username}&password={password}"; var re = await _httpService.SendRequst(bookingGradeUri + queryString, HttpMethod.Delete); var result = Newtonsoft.Json.JsonConvert.DeserializeObject <BookingGradeResult>(re); return(result); } catch { throw; } }
public async Task <BJUTHelperUserInfo> LoginAsync(HttpBaseService httpService, LoginModel loginModel) { try { var passwordHash = Helpers.Utility.GetMD5(loginModel.Password); var dic = new Dictionary <string, string>(2); dic.Add("Username", loginModel.Username); dic.Add("Password", passwordHash); var re = await httpService.SendRequst(loginUri, HttpMethod.Post, dic); if (string.IsNullOrEmpty(re)) { throw new LoginTipException("服务故障"); } var model = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginResultModel>(re); if (model == null) { throw new LoginTipException("服务故障"); } switch (model.Code) { case 200: model.Data.Token = model.Token; return(model.Data); case 300: throw new LoginTipException("用户名或密码错误"); case 400: throw new LoginTipException("填写的登录信息错误"); case 500: throw new LoginTipException("服务故障"); default: throw new LoginTipException($"未知异常 Code:{model.Code}"); } } catch (HttpRequestException) { throw new LoginTipException("服务故障"); } catch (Exception e) { throw; } }
public async Task <bool> LoginAccountCenter(string username, string password) { if (_accountCenterHttpService == null) { _accountCenterHttpService = new HttpBaseService(); } string result = string.Empty; try { var re = await _accountCenterHttpService.SendRequst(checkcodeUri, HttpMethod.Get); int index = re.IndexOf("checkcode=\""); if (index <= 0) { return(false); } string checkcode = ""; while (re[index + "checkcode=\"".Length] != '\"') { checkcode += re[index + "checkcode=\"".Length]; index++; } //好像没啥意义。。 await _accountCenterHttpService.SendRequst(randomcodeUri, HttpMethod.Get); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("account", username); parameters.Add("password", password); parameters.Add("checkcode", checkcode); result = await _accountCenterHttpService.SendRequst(manageUri, HttpMethod.Post, parameters);//登录管理中心 } catch { return(false); } if (result.Contains("logout")) { return(true); } if (result.Contains("errormsn")) { throw new InvalidUserInfoException("用户名或密码错误"); } return(false); }
protected async override void OnInitialized() { InitializeComponent(); //初始化设置 Models.Settings.InitSetting(); //await NavigationService.NavigateAsync("NavigationPage"); this.MainPage = new Views.NavigationPage(); //await var _httpService = new Services.HttpBaseService(); if (Device.OS == TargetPlatform.Android) { Services.ToolService.CheckUpdate(_httpService); } Services.ToolService.Pant(_httpService); }
public static async Task <BookingGradeResult> BookingGrade(HttpBaseService _httpService, string username, string password) { try { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("username", username); dic.Add("password", password); var re = await _httpService.SendRequst(bookingGradeUri, HttpMethod.Post, dic); var result = Newtonsoft.Json.JsonConvert.DeserializeObject <BookingGradeResult>(re); return(result); } catch { throw; } }
public async Task <BJUTHelperUserInfo> RetrieveAsync(HttpBaseService httpService, RetrieveModel model) { try { var passwordHash = Helpers.Utility.GetMD5(model.Password); var dic = new Dictionary <string, string>(); dic.Add("Username", model.Username); dic.Add("Password", passwordHash); dic.Add("VarifyPassword", model.VarifyPassword); var re = await httpService.SendRequst(retrieveUri, HttpMethod.Post, dic); if (string.IsNullOrEmpty(re)) { throw new LoginTipException("服务故障"); } var result = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginResultModel>(re); if (result == null) { throw new LoginTipException("服务故障"); } switch (result.Code) { case 200: result.Data.Token = result.Token; return(result.Data); default: throw new LoginTipException(result.Msg); } } catch (HttpRequestException) { throw new LoginTipException("服务故障"); } catch { throw; } }
public static async Task <string> GetBookingGradeServerStatus(HttpBaseService _httpService) { try { var queryString = $"/count"; var re = await _httpService.SendRequst(bookingGradeUri + queryString, HttpMethod.Get); var result = Newtonsoft.Json.JsonConvert.DeserializeObject <BookingGradeResult>(re); switch (result.Code) { case 200: return(result.Msg); default: return(string.Empty); } } catch { throw; } }
protected override void OnInitialized() { InitializeComponent(); //初始化设置 Models.Settings.InitSetting(); //await NavigationService.NavigateAsync("NavigationPage"); this.MainPage = new Views.NavigationPage(); //await var _httpService = new Services.HttpBaseService(); switch (Device.RuntimePlatform) { case Device.Android: Services.ToolService.CheckUpdate(_httpService); break; default: break; } Services.ToolService.Pant(_httpService); }
public static async Task Pant(HttpBaseService _httpService) { var version = Xamarin.Forms.DependencyService.Get <Models.IApplicationInfo>().GetVersion(); await _httpService.GetResponseCode($"{pantUri}?device={CrossDeviceInfo.Current.Model}&version={version}"); }
public async Task <BJUTHelperUserInfo> EditUserinfoAsync(HttpBaseService httpService, BJUTHelperUserInfo userinfo, string avatarPath) { FileStream fileStream = null; try { var content = new MultipartFormDataContent(); content.Add(new StringContent(userinfo.Username), "Username"); content.Add(new StringContent(userinfo.NickName), "Nickname"); content.Add(new StringContent(userinfo.Gender.ToString()), "Gender"); content.Add(new StringContent(userinfo.Age.ToString()), "Age"); content.Add(new StringContent(userinfo.College.ToString()), "College"); if (!string.IsNullOrEmpty(avatarPath)) { fileStream = File.Open(avatarPath, FileMode.Open); StreamContent imageContent = imageContent = new StreamContent(fileStream); content.Add(imageContent, "avatar", Path.GetFileName(avatarPath)); } var re = await httpService.SendRequst(infoUri, HttpMethod.Post, content, Authorization : Services.UserService.Instance.Token); if (string.IsNullOrEmpty(re)) { throw new LoginTipException("服务故障"); } var model = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginResultModel>(re); if (model == null) { throw new LoginTipException("服务故障"); } switch (model.Code) { case 200: return(model.Data); case 300: case 400: case 401: throw new LoginTipException(model.Msg); case 500: throw new LoginTipException("服务故障"); default: throw new LoginTipException($"未知异常 Code:{model.Code}"); } } catch (HttpRequestException) { throw new LoginTipException("服务故障"); } catch (Exception e) { throw; } finally { fileStream?.Dispose(); } }
public WifiService(HttpBaseService httpService) { _httpService = httpService; }