示例#1
0
        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;
            }
        }
示例#2
0
        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("遇到不规则的数据格式!");
            }
        }
示例#3
0
        /// <summary>
        /// 设置登录状态,检测登录页“F.htm”
        /// </summary>
        /// <returns></returns>
        public async Task <bool> GetRegistStatus()
        {
            try
            {
                var str = await _httpService.SendRequst(loginUri, HttpMethod.Get);

                if (str.Contains("F.htm"))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                throw;
            }
        }
示例#4
0
        //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;
            }
        }
示例#5
0
        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;
            }
        }
示例#6
0
        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;
            }
        }
示例#7
0
        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);
        }
示例#8
0
        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;
            }
        }
示例#9
0
        /// <summary>
        /// 注销
        /// </summary>
        /// <returns></returns>
        public async Task <bool> Logout()
        {
            try
            {
                cancellationTokenSource = new CancellationTokenSource();
                await _httpService.SendRequst(logoutUri, HttpMethod.Get);

                return(true);
            }
            catch (HttpRequestException requestException)
            {
                throw;
            }
        }
示例#10
0
        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;
            }
        }
示例#11
0
        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;
            }
        }
示例#12
0
        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();
            }
        }