public static async Task LoginMethod() { PixivCS.Objects.AuthResult res = null; string refreshToken = conf.RefreshToken; try { if (refreshToken != null && !refreshToken.Equals("Invalidation")) { res = await baseAPI.AuthAsync(refreshToken); conf.RefreshToken = res.Response.RefreshToken; var currentUser = res.Response.User; pixiv = new Pixiv(baseAPI, currentUser); frame.Navigate(typeof(MainPage), new ValueTuple <Pixiv, Conf>(pixiv, conf)); lp.webView.Visibility = Visibility.Collapsed; } else { lp.webView.Navigate(baseAPI.GenerateWebViewUri()); lp.webView.Visibility = Visibility.Visible; } } catch (Exception) { conf.RefreshToken = "Invalidation"; lp.webView.Navigate(baseAPI.GenerateWebViewUri()); lp.webView.Visibility = Visibility.Visible; } }
public static async Task LoginMethod() { PixivCS.Objects.AuthResult res = null; string refreshToken = conf.RefreshToken; try { if (refreshToken != null && !refreshToken.Equals("Invalidation")) { res = await baseAPI.AuthAsync(refreshToken); conf.RefreshToken = res.Response.RefreshToken; var currentUser = res.Response.User; pixiv = new Pixiv(baseAPI, currentUser); frame.Navigate(typeof(MainPage), new ValueTuple <Pixiv, Conf>(pixiv, conf)); } else { lp.webView.Source = baseAPI.GenerateWebViewUri(); lp.webView.Visibility = Visibility.Visible; } } catch (Exception) { //refreshToken失效或是代理+去除SNI导致的认证失败 try { baseAPI.ExperimentalConnection = false; res = await baseAPI.AuthAsync(refreshToken); conf.RefreshToken = res.Response.RefreshToken; var currentUser = res.Response.User; pixiv = new Pixiv(baseAPI, currentUser); frame.Navigate(typeof(MainPage), new ValueTuple <Pixiv, Conf>(pixiv, conf)); } catch (Exception e) { Console.WriteLine(e.Message); conf.RefreshToken = "Invalidation"; lp.webView.Source = baseAPI.GenerateWebViewUri(); lp.webView.Visibility = Visibility.Visible; } } }