无法获取 QRCode
#410
-
请确保您已阅读以上注意事项,并勾选下方的确认框。
Lagrange项目Core 所使用/依赖的Lagrange项目对应的commit运行环境Windows 运行架构x64 连接方式None 重现步骤我对Test中的扫码登录进行了微小的修改,运行后弹出QrCode Fetched,然后直接略过所有LoginByQrCode之后的代码退出程序,返回码1 期望的结果是什么?正常登录 实际的结果是什么?生成二维码之后直接退出程序 简单的复现代码/链接(可选)写的比较屎山,全堆在一个文件里了,将就着看下
Logger是自己实现的
``
using BUFBot.Eventlisteners;
using BUFBOt;
using Lagrange.Core;
using Lagrange.Core.Common;
using Lagrange.Core.Common.Interface;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.Core.Event;
using Lagrange.Core.Event.EventArg;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace BUFBot
{
public static class Program
{
public static async Task Main(string[] args)
{
Console.WriteLine("Starting BUF Bot");
Console.WriteLine("Initializing logger");
BUFBOt.Logger logger = new("main");
logger.info("Done");
logger.info("Creating bot instance");
var _deviceInfo = BUFBot.login.login.GetDeviceInfo();
var _keyStore = BUFBot.login.login.LoadKeystore() ?? new BotKeystore();
var config = new BotConfig();
config.
var bot = BotFactory.Create(new BotConfig(), _deviceInfo, _keyStore);
logger.info($"Done,Mac{_deviceInfo.MacAddress.ToString},DName{_deviceInfo.DeviceName}");
var qrCode = await bot.FetchQrCode();
logger.info("正在处理事件订阅");
EventListener el = new EventListener(bot.Invoker, bot);
BUFBot.login.login login = new BUFBot.login.login();
await login.FetchQrCode(bot);
await bot.LoginByQrCode();
Console.ReadLine();
}
}
}
namespace BUFBot.Eventlisteners
{
public class EventListener
{
BotContext bot;
public EventListener(EventInvoker ei, BotContext bot)
{
ei.OnFriendMessageReceived += HandleOnFriendMessageReceviedEvent;
this.bot = bot;
}
public static BUFBOt.Logger logger = new("EL");
public void HandleOnFriendMessageReceviedEvent(BotContext context, FriendMessageEvent @event)
{
logger.info("收到私聊消息:" + @event.EventMessage);
}
}
}
namespace BUFBot.login
{
public class login
{
public async Task FetchQrCode(BotContext bot)
{
bot.Invoker.OnBotLogEvent += (context, @event) =>
{
Logger logger = new Logger("LOGIN");
logger.info(@event.ToString());
};
bot.Invoker.OnBotOnlineEvent += (context, @event) =>
{
Logger logger = new Logger("LOGIN");
logger.info(@event.ToString());
SaveKeystore(bot.UpdateKeystore());
};
var qrCode = await bot.FetchQrCode();
if (qrCode != null)
{
File.Create("./qr.png").Close();
File.WriteAllBytes("./qr.png", qrCode.Value.QrCode);
}
}
public static BotDeviceInfo GetDeviceInfo()
{
if (File.Exists("./DeviceInfo.json"))
{
var info = JsonSerializer.Deserialize<BotDeviceInfo>(File.ReadAllText("./DeviceInfo.json"));
if (info != null) return info;
info = BotDeviceInfo.GenerateInfo();
File.WriteAllText("./DeviceInfo.json", JsonSerializer.Serialize(info));
return info;
}
var deviceInfo = BotDeviceInfo.GenerateInfo();
File.WriteAllText("./DeviceInfo.json", JsonSerializer.Serialize(deviceInfo));
return deviceInfo;
}
public static void SaveKeystore(BotKeystore keystore) =>
File.WriteAllText("./Keystore.json", JsonSerializer.Serialize(keystore));
public static BotKeystore? LoadKeystore()
{
try
{
var text = File.ReadAllText("./Keystore.json");
return JsonSerializer.Deserialize<BotKeystore>(text, new JsonSerializerOptions()
{
ReferenceHandler = ReferenceHandler.Preserve
});
}
catch
{
return null;
}
}
}
}
`` Trace 级别日志记录(可选)No response 补充说明(可选)几次测试的输出日志:
|
Beta Was this translation helpful? Give feedback.
Answered by
ghost
Jun 12, 2024
Replies: 1 comment 13 replies
-
其中第二个方法里面再次 FetchQRCode 了一次 PS. 你的代码似乎有所缺失 var config = new BotConfig();
config.
var bot = BotFactory.Create(new BotConfig(), _deviceInfo, _keyStore); |
Beta Was this translation helpful? Give feedback.
13 replies
Answer selected by
tmdakm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var qrCode = await bot.FetchQrCode();
await login.FetchQrCode(bot);
其中第二个方法里面再次 FetchQRCode 了一次
PS. 你的代码似乎有所缺失