fix: 添加缺失的文件

pull/896/head
yaobiao 8 months ago
parent 28f1c1e724
commit 8bd51907d1

@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Media.Imaging;
using DownKyi.Core.BiliApi.LoginNew.Models;
using DownKyi.Core.Logging;
using Newtonsoft.Json;
namespace DownKyi.Core.BiliApi.LoginNew
{
public static class LoginQR
{
/// <summary>
/// 申请二维码URL及扫码密钥web端
/// </summary>
/// <returns></returns>
public static LoginUrlOrigin GetLoginUrl()
{
string getLoginUrl = "https://passport.bilibili.com/x/passport-login/web/qrcode/generate";
string response = WebClient.RequestWeb(getLoginUrl);
Console.Out.WriteLine(response);
try
{
return JsonConvert.DeserializeObject<LoginUrlOrigin>(response);
}
catch (Exception e)
{
Utils.Debugging.Console.PrintLine("GetLoginUrl()发生异常: {0}", e);
LogManager.Error("LoginQR", e);
return null;
}
}
/// <summary>
/// 使用扫码登录web端
/// </summary>
/// <param name="qrcodeKey"></param>
/// <param name="goUrl"></param>
/// <returns></returns>
public static LoginStatus GetLoginStatus(string qrcodeKey, string goUrl = "https://www.bilibili.com")
{
string url = "https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=" + qrcodeKey;
string response = WebClient.RequestWeb(url);
try
{
return JsonConvert.DeserializeObject<LoginStatus>(response);
}
catch (Exception e)
{
Utils.Debugging.Console.PrintLine("GetLoginInfo()发生异常: {0}", e);
LogManager.Error("LoginQR", e);
return null;
}
}
/// <summary>
/// 获得登录二维码
/// </summary>
/// <returns></returns>
public static BitmapImage GetLoginQRCode()
{
try
{
string loginUrl = GetLoginUrl().Data.Url;
return GetLoginQRCode(loginUrl);
}
catch (Exception e)
{
Utils.Debugging.Console.PrintLine("GetLoginQRCode()发生异常: {0}", e);
LogManager.Error("LoginQR", e);
return null;
}
}
/// <summary>
/// 根据输入url生成二维码
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static BitmapImage GetLoginQRCode(string url)
{
// 设置的参数影响app能否成功扫码
Bitmap qrCode = Utils.QRCode.EncodeQRCode(url, 10, 10, null, 0, 0, false);
MemoryStream ms = new MemoryStream();
qrCode.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] bytes = ms.GetBuffer();
ms.Close();
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = new MemoryStream(bytes);
image.EndInit();
return image;
}
}
}

@ -0,0 +1,23 @@
using DownKyi.Core.BiliApi.Models;
using Newtonsoft.Json;
namespace DownKyi.Core.BiliApi.LoginNew.Models
{
[JsonObject]
public class LoginStatus : BaseModel
{
[JsonProperty("code")] public int Code { get; set; }
[JsonProperty("message")] public string Message { get; set; }
[JsonProperty("data")] public LoginStatusData Data { get; set; }
}
[JsonObject]
public class LoginStatusData : BaseModel
{
[JsonProperty("url")] public string Url { get; set; }
[JsonProperty("refresh_token")] public string RefreshToken { get; set; }
[JsonProperty("code")] public int Code { get; set; }
[JsonProperty("message")] public string Message { get; set; }
}
}

@ -0,0 +1,26 @@
using DownKyi.Core.BiliApi.Models;
using Newtonsoft.Json;
namespace DownKyi.Core.BiliApi.LoginNew.Models
{
// https://passport.bilibili.com/qrcode/getLoginUrl
[JsonObject]
public class LoginUrlOrigin : BaseModel
{
//public int code { get; set; }
[JsonProperty("data")]
public LoginUrl Data { get; set; }
[JsonProperty("code")]
public int Code { get; set; }
//public long ts { get; set; }
}
[JsonObject]
public class LoginUrl : BaseModel
{
[JsonProperty("qrcode_key")]
public string QrcodeKey { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
}
}

@ -173,7 +173,7 @@ namespace DownKyi.ViewModels
// 创建新任务
PropertyChangeAsync(new Action(() => { Task.Run(Login, (tokenSource = new CancellationTokenSource()).Token); }));
break;
case 86010:
case 86101:
// 未扫码
break;
case 86090:

Loading…
Cancel
Save