Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

[feature request]扫码登录有计划吗 #180

Open
myderr opened this issue Sep 19, 2022 · 6 comments
Open

[feature request]扫码登录有计划吗 #180

myderr opened this issue Sep 19, 2022 · 6 comments
Assignees

Comments

@myderr
Copy link

myderr commented Sep 19, 2022

现在登录是需要账号密码,而且验证码很难受

@TheSnowfield
Copy link
Member

手錶掃碼在計劃之内。

@lepollo
Copy link

lepollo commented Sep 20, 2022

我的验证码处理方式是这样的,几乎没失误过。
///请订阅bot的OnCaptcha事件,如:_bot.OnCaptcha += Bot_OnCaptcha; //处理验证事件

 /// <summary>
    /// 处理短信验证和滑动码验证,滑动码验证需要在手机app“滑动助手”配合
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Bot_OnCaptcha(object? sender, CaptchaEvent e)
    {
        try
        {
            switch (e.Type)
            {
                case CaptchaEvent.CaptchaType.Sms:
                    Console.WriteLine($"手机验证码已经发送,请输入{e.Phone}接收到的验证码:");
                    _bot.SubmitSmsCode(Console.ReadLine());
                    break;

                case CaptchaEvent.CaptchaType.Slider:
                    string ticket = DoCaptcha(e.SliderUrl);
                    if (string.IsNullOrEmpty(ticket)) Console.WriteLine("认证失败,请检查并重试。");
                    else _bot.SubmitSliderTicket(ticket);
                    break;

                default:
                case CaptchaEvent.CaptchaType.Unknown:
                    Console.WriteLine("未知的验证方式,请联系开发人员");
                    break;
            }
        }
        catch (Exception err) { Console.WriteLine($"处理验证码出错,出错信息:{err.Message}"); }

    }
    /// <summary>
    /// 处理滑动验证,url是登录QQ时由QQ返回的滑动验证链接,返回滑动认证的ticket
    /// </summary>
    /// <param name="url"></param>
    /// <returns></returns>
    public static string DoCaptcha(string url)
    {
        string code, ticket = "";
        try
        {
            url = url.Replace("ssl.captcha.qq.com", "txhelper.glitch.me");
            code = GetUrlInfo(url, "code"); //第一次返回的是4位数字验证码
            if (!string.IsNullOrEmpty(code))
            {
                Console.WriteLine("请在手机app‘滑动验证助手’输入验证码,并手动完成滑动验证:" + code);
                Console.WriteLine("完成滑动验证后在本程序按任意键继续登录。");
                Console.ReadLine();
                ticket = GetUrlInfo(url, "ticket"); //第二次返回的是登录QQ的验证字符串
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("处理验证过程出错,出错信息:"+ex.Message);
        }
        return ticket;
    }

    /// <summary>  
    /// 获取滑动验证链接的code或ticket,需要配合手机“滑动验证助手app”
    /// </summary>  
    /// <param name="url">eg:http://www.apollo.com/index.html </param>  
    public static string GetUrlInfo(string url, string strtype)
    {
        string str = "";
        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri(url);
            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactory-Sample");
            //string result = client.GetStringAsync(url).Result;
            string[] strBuff = client.GetStringAsync(url).Result.Split(":");
            if (strBuff.Length >= 4 && strtype == "code") str = strBuff[2].Substring(0, 4); //获取滑动验证前的代码
            if (strBuff.Length >= 4 && strtype == "ticket") str = strBuff[3].Replace("\"", "").Replace("}",""); //获取滑动验证候的ticket
            Thread.Sleep(1000);
        }
        return str;
    }

@myderr
Copy link
Author

myderr commented Sep 23, 2022

我的验证码处理方式是这样的,几乎没失误过。 ///请订阅bot的OnCaptcha事件,如:_bot.OnCaptcha += Bot_OnCaptcha; //处理验证事件

 /// <summary>
    /// 处理短信验证和滑动码验证,滑动码验证需要在手机app“滑动助手”配合
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Bot_OnCaptcha(object? sender, CaptchaEvent e)
    {
        try
        {
            switch (e.Type)
            {
                case CaptchaEvent.CaptchaType.Sms:
                    Console.WriteLine($"手机验证码已经发送,请输入{e.Phone}接收到的验证码:");
                    _bot.SubmitSmsCode(Console.ReadLine());
                    break;

                case CaptchaEvent.CaptchaType.Slider:
                    string ticket = DoCaptcha(e.SliderUrl);
                    if (string.IsNullOrEmpty(ticket)) Console.WriteLine("认证失败,请检查并重试。");
                    else _bot.SubmitSliderTicket(ticket);
                    break;

                default:
                case CaptchaEvent.CaptchaType.Unknown:
                    Console.WriteLine("未知的验证方式,请联系开发人员");
                    break;
            }
        }
        catch (Exception err) { Console.WriteLine($"处理验证码出错,出错信息:{err.Message}"); }

    }
    /// <summary>
    /// 处理滑动验证,url是登录QQ时由QQ返回的滑动验证链接,返回滑动认证的ticket
    /// </summary>
    /// <param name="url"></param>
    /// <returns></returns>
    public static string DoCaptcha(string url)
    {
        string code, ticket = "";
        try
        {
            url = url.Replace("ssl.captcha.qq.com", "txhelper.glitch.me");
            code = GetUrlInfo(url, "code"); //第一次返回的是4位数字验证码
            if (!string.IsNullOrEmpty(code))
            {
                Console.WriteLine("请在手机app‘滑动验证助手’输入验证码,并手动完成滑动验证:" + code);
                Console.WriteLine("完成滑动验证后在本程序按任意键继续登录。");
                Console.ReadLine();
                ticket = GetUrlInfo(url, "ticket"); //第二次返回的是登录QQ的验证字符串
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("处理验证过程出错,出错信息:"+ex.Message);
        }
        return ticket;
    }

    /// <summary>  
    /// 获取滑动验证链接的code或ticket,需要配合手机“滑动验证助手app”
    /// </summary>  
    /// <param name="url">eg:http://www.apollo.com/index.html </param>  
    public static string GetUrlInfo(string url, string strtype)
    {
        string str = "";
        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri(url);
            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactory-Sample");
            //string result = client.GetStringAsync(url).Result;
            string[] strBuff = client.GetStringAsync(url).Result.Split(":");
            if (strBuff.Length >= 4 && strtype == "code") str = strBuff[2].Substring(0, 4); //获取滑动验证前的代码
            if (strBuff.Length >= 4 && strtype == "ticket") str = strBuff[3].Replace("\"", "").Replace("}",""); //获取滑动验证候的ticket
            Thread.Sleep(1000);
        }
        return str;
    }

感谢,非常好用
Console.WriteLine("完成滑动验证后在本程序按任意键继续登录。");
这块其实可以处理成轮训吧,让用户少点一次

@lepollo
Copy link

lepollo commented Sep 23, 2022

好办法,轮询bot是否在线。

@myderr
Copy link
Author

myderr commented Sep 23, 2022

简单写了一下

  Console.WriteLine("请在5分钟内完成滑块");
  var startTime = DateTime.Now;
  var endTime = startTime.AddMinutes(5);
  //是否超时
  bool IsTimeOut = false;
  while (ticket == "" && !IsTimeOut)
  {
      Thread.Sleep(2000);
      ticket = GetUrlInfo(url, "ticket"); //第二次返回的是登录QQ的验证字符串
      IsTimeOut = endTime <= DateTime.Now;
  }
  if (string.IsNullOrEmpty(ticket) && IsTimeOut)
  {
      Console.WriteLine(DateTime.Now);
      throw new Exception("滑动验证超时");
  }

@TheSnowfield TheSnowfield self-assigned this Mar 6, 2023
@q812143836
Copy link

请在手机app‘滑动验证助手’ 这是什么APP 我咋搜索不到呢

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants