Expose qrcode url to user

This commit is contained in:
TheSnowfield 2023-10-17 12:09:56 +08:00
parent 9967ee18f7
commit 9062298220
No known key found for this signature in database
GPG Key ID: FD105917CE48A742
4 changed files with 9 additions and 9 deletions

View File

@ -36,7 +36,7 @@ public class WtLoginTest
var qrCode = await bot.FetchQrCode();
if (qrCode != null)
{
await File.WriteAllBytesAsync("qr.png", qrCode);
await File.WriteAllBytesAsync("qr.png", qrCode.Value.QrCode);
await bot.LoginByQrCode();
}
}

View File

@ -7,9 +7,9 @@ public static class BotExt
/// <summary>
/// Fetch the qrcode for QRCode Login
/// </summary>
/// <returns>the byte of QRCode, usually in the form of PNG</returns>
public static async Task<byte[]?> FetchQrCode(this BotContext bot)
=> await bot.ContextCollection.Business.WtExchangeLogic.FetchQrCode();
/// <returns>return url and qrcode image in PNG format</returns>
public static Task<(string Url, byte[] QrCode)?> FetchQrCode(this BotContext bot)
=> bot.ContextCollection.Business.WtExchangeLogic.FetchQrCode();
/// <summary>
/// Use this method to login by QrCode, you should call <see cref="FetchQrCode"/> first
@ -20,8 +20,8 @@ public static class BotExt
/// <summary>
/// Use this method to login by password, EasyLogin may be preformed if there is sig in <see cref="BotKeystore"/>
/// </summary>
public static async Task<bool> LoginByPassword(this BotContext bot)
=> await bot.ContextCollection.Business.WtExchangeLogic.LoginByPassword();
public static Task<bool> LoginByPassword(this BotContext bot)
=> bot.ContextCollection.Business.WtExchangeLogic.LoginByPassword();
/// <summary>
/// Submit the captcha of the url given by the <see cref="EventInvoker.OnBotCaptchaEvent"/>

View File

@ -56,7 +56,7 @@ internal class WtExchangeLogic : LogicBase
/// <para>1. resolve wtlogin.trans_emp CMD0x31 packet</para>
/// <para>2. Schedule wtlogin.trans_emp CMD0x12 Task</para>
/// </summary>
public async Task<byte[]?> FetchQrCode()
public async Task<(string, byte[])?> FetchQrCode()
{
Collection.Log.LogInfo(Tag, "Connecting Servers...");
if (!await Collection.Socket.Connect()) return null;
@ -73,7 +73,7 @@ internal class WtExchangeLogic : LogicBase
Collection.Keystore.Session.QrUrl = @event.Url;
Collection.Log.LogInfo(Tag, $"QrCode Fetched, Expiration: {@event.Expiration} seconds");
return @event.QrCode;
return (@event.Url, @event.QrCode);
}
return null;
}

View File

@ -72,7 +72,7 @@ public class LagrangeApp : IHost
var qrCode = await Instance.FetchQrCode();
if (qrCode != null)
{
QrCodeHelper.Output(Instance.ContextCollection.Keystore.Session.QrUrl ?? "");
QrCodeHelper.Output(qrCode.Value.Url ?? "");
await Instance.LoginByQrCode();
}
}