fix: 使用新版登录api修复登录失败的问题

pull/896/head
yaobiao 8 months ago
parent 3331737494
commit e63b24309c

@ -23,7 +23,7 @@ namespace DownKyi.Core.BiliApi.Login
string getLoginUrl = "https://passport.bilibili.com/qrcode/getLoginUrl";
string referer = "https://passport.bilibili.com/login";
string response = WebClient.RequestWeb(getLoginUrl, referer);
Console.Out.WriteLine(response);
try
{
var loginUrl = JsonConvert.DeserializeObject<LoginUrlOrigin>(response);
@ -56,7 +56,7 @@ namespace DownKyi.Core.BiliApi.Login
string response = WebClient.RequestWeb(url, referer, "POST", parameters);
var loginInfo = new LoginStatus();
Console.Out.WriteLine(response);
try
{
if (response.Contains("\"code\":0") || response.Contains("\"code\": 0"))

@ -179,6 +179,9 @@
<Compile Include="BiliApi\History\Models\ToViewData.cs" />
<Compile Include="BiliApi\History\Models\ToViewList.cs" />
<Compile Include="BiliApi\History\ToView.cs" />
<Compile Include="BiliApi\LoginNew\LoginQR.cs" />
<Compile Include="BiliApi\LoginNew\Models\LoginStatus.cs" />
<Compile Include="BiliApi\LoginNew\Models\LoginUrl.cs" />
<Compile Include="BiliApi\Login\LoginHelper.cs" />
<Compile Include="BiliApi\Models\BaseModel.cs" />
<Compile Include="BiliApi\BiliUtils\BvId.cs" />

@ -45,7 +45,7 @@ namespace DownKyi.Core.Utils
if (name == "Expires" || name == "gourl") { continue; }
// 添加cookie
cookieContainer.Add(new Cookie(name, value, "/", ".bilibili.com") { Expires = dateTime });
cookieContainer.Add(new Cookie(name, value.Replace(",","%2c"), "/", ".bilibili.com") { Expires = dateTime });
Debugging.Console.PrintLine(name + ": " + value + "\t" + cookieContainer.Count);
}

@ -1,4 +1,4 @@
using DownKyi.Core.BiliApi.Login;

using DownKyi.Core.Logging;
using DownKyi.Events;
using DownKyi.Images;
@ -11,6 +11,8 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using DownKyi.Core.BiliApi.Login;
using LoginQR = DownKyi.Core.BiliApi.LoginNew.LoginQR;
namespace DownKyi.ViewModels
{
@ -103,7 +105,7 @@ namespace DownKyi.ViewModels
var loginUrl = LoginQR.GetLoginUrl();
if (loginUrl == null) { return; }
if (loginUrl.Status != true)
if (loginUrl.Code != 0)
{
ExecuteBackSpace();
return;
@ -119,7 +121,7 @@ namespace DownKyi.ViewModels
Core.Utils.Debugging.Console.PrintLine(loginUrl.Data.Url + "\n");
LogManager.Debug(Tag, loginUrl.Data.Url);
GetLoginStatus(loginUrl.Data.OauthKey);
GetLoginStatus(loginUrl.Data.QrcodeKey);
}
catch (Exception e)
{
@ -141,24 +143,24 @@ namespace DownKyi.ViewModels
var loginStatus = LoginQR.GetLoginStatus(oauthKey);
if (loginStatus == null) { continue; }
Core.Utils.Debugging.Console.PrintLine(loginStatus.Code + "\n" + loginStatus.Message + "\n" + loginStatus.Url + "\n");
Core.Utils.Debugging.Console.PrintLine(loginStatus.Data.Code + "\n" + loginStatus.Data.Message + "\n" + loginStatus.Data.Url + "\n");
switch (loginStatus.Code)
switch (loginStatus.Data.Code)
{
case -1:
// 没有这个oauthKey
// 发送通知
eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("LoginKeyError"));
LogManager.Info(Tag, DictionaryResource.GetString("LoginKeyError"));
// 取消任务
tokenSource.Cancel();
// 创建新任务
PropertyChangeAsync(new Action(() => { Task.Run(Login, (tokenSource = new CancellationTokenSource()).Token); }));
break;
case -2:
// case -1:
// // 没有这个oauthKey
//
// // 发送通知
// eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("LoginKeyError"));
// LogManager.Info(Tag, DictionaryResource.GetString("LoginKeyError"));
//
// // 取消任务
// tokenSource.Cancel();
//
// // 创建新任务
// PropertyChangeAsync(new Action(() => { Task.Run(Login, (tokenSource = new CancellationTokenSource()).Token); }));
// break;
case 86038:
// 不匹配的oauthKey超时或已确认的oauthKey
// 发送通知
@ -171,10 +173,10 @@ namespace DownKyi.ViewModels
// 创建新任务
PropertyChangeAsync(new Action(() => { Task.Run(Login, (tokenSource = new CancellationTokenSource()).Token); }));
break;
case -4:
case 86010:
// 未扫码
break;
case -5:
case 86090:
// 已扫码,未确认
PropertyChangeAsync(new Action(() =>
{
@ -192,7 +194,7 @@ namespace DownKyi.ViewModels
// 保存登录信息
try
{
bool isSucceed = LoginHelper.SaveLoginInfoCookies(loginStatus.Url);
bool isSucceed = LoginHelper.SaveLoginInfoCookies(loginStatus.Data.Url);
if (!isSucceed)
{
eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("LoginFailed"));

Loading…
Cancel
Save