首次提交
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using System.Text.Json;
|
||||
using Lagrange.Core.Common;
|
||||
using RoBot.Start.ConstValue;
|
||||
|
||||
namespace RoBot.Start.Keystore
|
||||
{
|
||||
/// <summary>
|
||||
/// 账号登录信息
|
||||
/// </summary>
|
||||
public class KeystoreConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取账号登录信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static async Task<KeystoreInfo> GetBotKeystore()
|
||||
{
|
||||
KeystoreInfo result = new()
|
||||
{
|
||||
ReLogin = false
|
||||
};
|
||||
var botKeystore = File.Exists(Consts.KeystoreConfig)
|
||||
? JsonSerializer.Deserialize<BotKeystore>(await File.ReadAllTextAsync(Consts.KeystoreConfig)) ?? new()
|
||||
: new();
|
||||
result.BotKeystore = botKeystore;
|
||||
if (botKeystore.Session.TempPassword?.Length > 0)
|
||||
{
|
||||
result.ReLogin = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存登录信息
|
||||
/// </summary>
|
||||
/// <param name="botKeystore"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task SaveBotKeystore(BotKeystore botKeystore)
|
||||
{
|
||||
string keystoreJson = JsonSerializer.Serialize(botKeystore);
|
||||
await File.WriteAllTextAsync(Consts.KeystoreConfig, keystoreJson);
|
||||
}
|
||||
}
|
||||
|
||||
public class KeystoreInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// BotKeystore
|
||||
/// </summary>
|
||||
public BotKeystore BotKeystore { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要重新登录
|
||||
/// </summary>
|
||||
public bool ReLogin { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user