コード例 #1
0
        private static async Task <bool> LoginWithCaptcha(User user, string key)
        {
            string  json;
            JObject result;

            try {
                string captcha;

                captcha = await LoginApi.SolveCaptchaAsync(await LoginApi.GetCaptchaAsync(user));

                json = await LoginApi.LoginAsync(user, key, captcha);

                result = JObject.Parse(json);
            }
            catch (Exception ex) {
                user.LogError("登录失败");
                throw new ApiException(ex);
            }
            if ((int)result["code"] == 0 && (int)result["data"]["status"] == 0)
            {
                // 登录成功,保存数据直接返回
                user.LogInfo("登录成功");
                UpdateLoginData(user, result);
                OnLoginDataUpdated(new LoginDataUpdatedEventArgs(user));
                return(true);
            }
            else
            {
                // 其它错误
                user.LogError("登录失败");
                user.LogError($"错误信息:{Utils.FormatJson(json)}");
                return(false);
            }
        }
コード例 #2
0
        private static async Task <bool> LoginWithCaptcha(User user, string key)
        {
            string     json;
            ResultInfo result;

            try
            {
                string captcha;

                captcha = await LoginApi.SolveCaptchaAsync(await LoginApi.GetCaptchaAsync(user));

                json = await LoginApi.LoginAsync(user, key, captcha);

                if (string.IsNullOrEmpty(json))
                {
                    throw new ApiException(new Exception("登录失败,没有返回的数据。"));
                }
                result = JsonHelper.DeserializeJsonToObject <ResultInfo>(json);
            }
            catch (Exception ex)
            {
                user.LogError("登录失败");
                throw new ApiException(ex);
            }
            if (result.Code == 0 && result.Data.Status == 0)
            {
                // 登录成功,保存数据直接返回
                user.LogInfo("登录成功");
                UpdateLoginData(user, result);
                OnLoginDataUpdated(new LoginDataUpdatedEventArgs(user));
                return(true);
            }
            else
            {
                // 其它错误
                user.LogError("登录失败");
                user.LogError($"错误信息:{Utils.FormatJson(json)}");
                return(false);
            }
        }