幻苍秋 发表于 2022-6-27 14:56

C#取本机在线QQ号源码

本帖最后由 幻苍秋 于 2022-6-27 17:39 编辑

运行环境: WIN10
涉及工具: VS2022
编程语言: C#

以下为主题内容:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Net;
using System.IO;

namespace GetQQNumber
{
    public class GetQQNumber
    {
      private static List<string> QQnumber = new List<string>();
      private static List<string> WinClass = new List<string>();
      private static List<string> WinTitle = new List<string>();
                //本机在线QQ
      public static List<string> GetQQnumbers()
      {
            GetWindowInformation();
            for (int i = 0; i < WinClass.Count; i++)
            {
                if (WinClass == "5B3838F5-0C81-46D9-A4C0-6EA28CA3E942")
                {
                  int index = WinTitle.LastIndexOf("_") + 1;
                  QQnumber.Add(WinTitle.Substring(index, WinTitle.Length - index));
                  //Console.WriteLine(QQnumber);
                }
            }
            return QQnumber;
      }
                //QQ头像
                public static void DownloadQQAvatar(string qqnumber, string Filepath)
      {
            string http = "https://qlogo1.store.qq.com/qzone/" + qqnumber + "/" + qqnumber + "/100?1655721377";
            WebClient client = new WebClient();
            client.Credentials = CredentialCache.DefaultCredentials;
            client.Encoding = Encoding.UTF8;
            client.DownloadFile(http, Filepath);
      }
                //昵称
                public static string GetQQName(string qqnumber)
      {
            string html = ApiGET("https://v.api.aa1.cn/api/qqnicheng/index.php?qq=" + qqnumber);
            int index = html.IndexOf(":") + 1;
            return html.Substring(index, html.Length - index - 10);
      }
      private static bool GetWindowInformation()
      {
            return EnumWindows(new EnumWindowsProc(Enuming), IntPtr.Zero);
      }

      private static void Enuming(IntPtr hWnd, IntPtr lParam)
      {
            // Console.WriteLine("WinClass:{0} \nWinTitle::{1} ", new string[] { GetClass(hWnd), GetTitle(hWnd)} );
            WinClass.Add(GetClass(hWnd));
            WinTitle.Add(GetTitle(hWnd));
      }
      private static string GetClass(IntPtr hWnd)
      {
            StringBuilder sb = new StringBuilder(256);//类名最大长度256
            GetClassName(hWnd, sb, sb.Capacity);
            return sb.ToString();

      }
      private static string GetTitle(IntPtr hWnd)
      {
            int length = GetWindowTextLength(hWnd);
            StringBuilder sb = new StringBuilder(length + 1);
            GetWindowText(hWnd, sb, sb.Capacity);
            return sb.ToString();
      }
                private static string ApiGET(string url)
      {
            try
            {
                Encoding charset = Encoding.UTF8;
                HttpWebRequest request = null;
                request = WebRequest.Create(url.Trim()) as HttpWebRequest;
                request.ProtocolVersion = HttpVersion.Version10;
                request.Method = "Get";
                request.ContentType = "application/x-www-form-urlencoded";
                request.UserAgent = DefaultUserAgent;
                HttpWebResponse response = (request.GetResponse() as HttpWebResponse);
                Stream htmlStream = response.GetResponseStream();
                StreamReader sr = new StreamReader(htmlStream);
                return sr.ReadToEnd();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return e.Message;
            }
      }

      
      
      private static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
      
      private static extern int GetClassName(IntPtr hWnd,StringBuilder lpClassName, int nMaxCount);
      
      private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
      
      private static extern int GetWindowTextLength(IntPtr hWnd);

      private delegate void EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
    }
}

闲来无事写的

2276980 发表于 2022-7-6 08:18

sjtkxy 发表于 2022-9-30 05:32

吾爱稀饭 发表于 2022-10-11 23:30

感谢分享

2386222844 发表于 2022-10-18 08:42

牛啊~~~支持

望峰息心 发表于 2023-1-4 14:16

好像是通过检索窗口然后找到的qq号.

流行格调 发表于 2023-3-18 06:51


好像是通过检索窗口然后找到的qq号.

天理兄 发表于 2023-3-18 10:21

我的qq账号被盗了,也无法找回。这些方法可以找回么?
{:5_191:}
页: [1]
查看完整版本: C#取本机在线QQ号源码