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);
}
}
闲来无事写的
感谢分享 牛啊~~~支持 好像是通过检索窗口然后找到的qq号.
好像是通过检索窗口然后找到的qq号. 我的qq账号被盗了,也无法找回。这些方法可以找回么?
{:5_191:}
页:
[1]