本帖最后由 zmoli775 于 2023-12-14 15:33 编辑
新版NTQQ通过API获取已登录QQ号.txt
(3.34 KB, 下载次数: 65)
感谢 “bianyuan456” 帖友指点。代码块已更新。
[JavaScript] 纯文本查看 复制代码 void Main()
{
string
pt_local_tk = string.Empty,
url_01 = "https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=0&target=self&s_url=https://im.qq.com/loginSuccess";
var ret1 = t07.qq_int775Async(url_01); var Cookies = ret1.Result.Cookies;
pt_local_tk = Cookies["pt_local_token"];
Console.WriteLine($"获取到pt_local_tk值为:{pt_local_tk}\r\n");
Dictionary<string, string> header = new Dictionary<string, string>
{
{ "Cookie",$"pt_local_token={pt_local_tk}"},
{ "Referer","https://xui.ptlogin2.qq.com"},
{ "User-Agent", "curl/8.4.0" }
};
string url_02 = $"https://localhost.ptlogin2.qq.com:4301/pt_get_uins?callback=ptui_getuins_CB&pt_local_tk={pt_local_tk}";
var ret2 = t07.qq_int775Async(url_02, header);
if (ret2.Result != null)
{
Console.WriteLine($"返回数据:\r\n{ret2.Result.ResString}");
string s="var_sso_uin_list=",e=";";
Match match = Regex.Match(ret2.Result.ResString, $"(?<=({s}))[.\\s\\S]*?(?=({e}))", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);
s = match.Success ? match.Value : string.Empty;
if (!string.IsNullOrEmpty(s))
{
Console.WriteLine($"{s}\r\n");
var userInfo = JsonSerializer.Deserialize<UserInfo[]>(s);
foreach (var user in userInfo)
{
Console.WriteLine($"nickname(昵称):{user.nickname}");
Console.WriteLine($"account(帐号):{user.account}\r\n");
}
}
}
else
{
Console.WriteLine("返回数据失败");
}
}
public class UserInfo
{
public int uin { get; set; }
public int face_index { get; set; }
public int gender { get; set; }
public string nickname { get; set; }
public int client_type { get; set; }
public int uin_flag { get; set; }
public int account { get; set; }
}
public class Res
{
public string ResString { get; set; } = string.Empty;
public Dictionary<string, string> Cookies { get; set; } = new();
}
class t07
{
public static async Task<Res?> qq_int775Async(string url, Dictionary<string, string>? headers = null)
{
CookieContainer cookieContainer = new CookieContainer();
using HttpClient hc = new(new HttpClientHandler() { CookieContainer = cookieContainer }) { Timeout = new TimeSpan(0, 0, 0, 0, 1200) };
if (headers != null && headers.Count > 0) { foreach (var kv in headers) { hc.DefaultRequestHeaders.Add(kv.Key, kv.Value); } }
HttpResponseMessage? res = null;
try { res = await hc.GetAsync(url); } catch (Exception) { return null; }
Res mr = new();
if (res != null && res.IsSuccessStatusCode)
{
CookieCollection cc = cookieContainer.GetCookies(res.RequestMessage.RequestUri);
if (cc != null && cc.Count > 0)
{
foreach (Cookie cookie in cc.Cast<Cookie>())
{
mr.Cookies.Add(cookie.Name, cookie.Value); // Console.WriteLine($"{cookie.Name}={cookie.Value}");
}
}
mr.ResString = await res.Content.ReadAsStringAsync();
}
else
{
Console.WriteLine($"状态码:{res.StatusCode}\r\n请求失败:{res.RequestMessage}");
}
return mr;
}
}
枚举类名获取本机登录QQ号:参考 https://125.confly.eu.org/thread-14805580-1-1.html 支持新旧QQ
补充内容 (2025-4-10 17:22):
优化 -> https://125.confly.eu.org/forum.php?mod ... 82&pid=30132289
补充内容 (2025-4-10 17:24):
少许优化·请跳转到34楼 |