/// <summary> /// 刷新Token /// </summary> /// <param name="user">用户</param> /// <returns></returns> public static async Task <string> RefreshTokenAsync(User user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } QueryCollection queries; queries = new QueryCollection { { "access_key", user.LoginData["access_key"] }, { "refresh_token", user.LoginData["refresh_token"] }, { "ts", ApiUtils.GetTimeStamp().ToString() } }; queries.AddRange(user.LoginData["cookie"].Split(';').Select(item => { string[] pair; pair = item.Split('='); return(new KeyValuePair <string, string>(pair[0], pair[1])); })); queries.AddRange(General); queries.SortAndSign(); using (HttpResponseMessage response = await user.Client.SendAsync(HttpMethod.Post, OAUTH2_REFRESH_TOKEN_URL, queries, user.AppHeaders)) return(await response.Content.ReadAsStringAsync()); }
/// <summary> /// 获取信息 /// </summary> /// <param name="user">用户</param> /// <returns></returns> public static async Task <string> GetInfoAsync(User user) { try { if (user == null) { throw new ArgumentNullException(nameof(user)); } QueryCollection queries; queries = new QueryCollection { { "access_key", user.Data.AccessKey }, { "ts", ApiUtils.GetTimeStamp().ToString() } }; queries.AddRange(user.Data.Cookie.Split(';').Select(item => { string[] pair; pair = item.Split('='); return(new KeyValuePair <string, string>(pair[0], pair[1])); })); queries.AddRange(General); queries.SortAndSign(); using HttpResponseMessage response = await user.Handler.SendAsync(HttpMethod.Get, OAUTH2_INFO_URL, queries, user.AppHeaders); return(await response.Content.ReadAsStringAsync()); } catch { return(null); } }
/// <summary> /// 获取信息 /// </summary> /// <param name="user">用户</param> /// <returns></returns> public static async Task <string> GetInfo(User user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } FormUrlEncodedCollection parameters; parameters = new FormUrlEncodedCollection { { "access_key", user.LoginData["access_key"] }, { "ts", ApiUtils.GetTimeStamp().ToString() } }; parameters.AddRange(user.LoginData["cookie"].Split(';').Select(item => { string[] pair; pair = item.Split('='); return(new KeyValuePair <string, string>(pair[0], pair[1])); })); parameters.AddRange(General); parameters.SortAndSign(); using (HttpResponseMessage response = await user.Client.SendAsync(HttpMethod.Get, OAUTH2_INFO_URL, parameters, user.AppHeaders)) return(await response.Content.ReadAsStringAsync()); }