/// <summary> /// 登录 /// </summary> /// <param name="user">用户</param> /// <param name="jsonKey">Key</param> /// <param name="captcha">验证码</param> /// <returns></returns> public static async Task <string> LoginAsync(User user, string jsonKey, string captcha) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (string.IsNullOrEmpty(jsonKey)) { throw new ArgumentNullException(nameof(jsonKey)); } JToken loginKey; string rsaKey; RSAParameters rsaParameters; QueryCollection queries; loginKey = JObject.Parse(jsonKey)["data"]; rsaKey = (string)loginKey["key"]; rsaParameters = ApiUtils.ParsePublicKey(rsaKey); queries = new QueryCollection { { "username", user.Account }, { "password", ApiUtils.RsaEncrypt(loginKey["hash"] + user.Password, rsaParameters) }, { "captcha", captcha ?? string.Empty } }; queries.AddRange(General); queries.SortAndSign(); using (HttpResponseMessage response = await user.Handler.SendAsync(HttpMethod.Post, OAUTH2_LOGIN_URL, queries, null)) { return(await response.Content.ReadAsStringAsync()); } }
/// <summary> /// 登录 /// </summary> /// <param name="user">用户</param> /// <param name="jsonKey">Key</param> /// <param name="captcha">验证码</param> /// <returns></returns> public static async Task <string> Login(User user, string jsonKey, string captcha) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (string.IsNullOrEmpty(jsonKey)) { throw new ArgumentNullException(nameof(jsonKey)); } JToken loginKey; string rsaKey; RSAParameters rsaParameters; FormUrlEncodedCollection parameters; loginKey = JObject.Parse(jsonKey)["data"]; rsaKey = loginKey["key"].ToString(); rsaKey = rsaKey.Replace("\n", string.Empty).Substring(26, rsaKey.Length - 56); rsaParameters = ApiUtils.ParsePublicKey(rsaKey); parameters = new FormUrlEncodedCollection { { "username", user.Account }, { "password", ApiUtils.RsaEncrypt(loginKey["hash"] + user.Password, rsaParameters) }, { "captcha", captcha ?? string.Empty } }; parameters.AddRange(General); parameters.SortAndSign(); using (HttpResponseMessage response = await user.Client.SendAsync(HttpMethod.Post, OAUTH2_LOGIN_URL, parameters, null)) return(await response.Content.ReadAsStringAsync()); }