QQ群成员导出工具_v1.2_Release(附源码)(接口已被腾讯和谐)

7次阅读
没有评论

前几天·坛子里面·看到一帖·QQ群导出工具·很不错·所以闲来无事·自己研究了一下下...

原贴:http://www.52pojie.cn/thread-586323-1-2.html

原理很简单·就是利用自动登录授权后·读取Cookies·访问群成员列表·JSON反序列化后导出...

程序下载:

(Ps:“鼠标右键”可打开导出文件)
[Asm] 纯文本查看 复制代码

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace _000_窗体程序测试
{
/*
http://ui.ptlogin2.qq.com/cgi-bin/login?appid=549000912&daid=5&style=12&s_url=http%3A%2F%2Fqun.qzone.qq.com%2Fgroup%23!%2F336100817%2Fmember //固定群成员导出
https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=73&pt_no_auth=1&s_url=http%3A%2F%2Fqun.qq.com%2F //指定群号导出
*/
public partial class M : Form
{
/// <summary>
/// 定义QQ群号输入状态
/// </summary>
private static bool QQGroupInputState;
/// <summary>
/// 定义QQ群号
/// </summary>
private static string GropNum = string.Empty;
/// <summary>
/// 设置QQ认证页面
/// </summary>
private string url_Login_Group = "https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=73&pt_no_auth=1&s_url=http%3A%2F%2Fqun.qq.com%2F";
//private string url_Login_Group = "http://ui.ptlogin2.qq.com/cgi-bin/login?appid=549000912&daid=5&style=12&s_url=http%3A%2F%2Fqun.qzone.qq.com%2Fgroup%23!%2F336100817%2Fmember";
public M()
{
InitializeComponent();
//设置导出QQ成员listBox为隐藏
listBox_0.Visible = false;
//设置界面按钮为灰色不可点击
button_M.Enabled = false;
//设置文本框为不可输入
textBox0.Enabled = false;
//载入QQ认证页面
this.webBrowser_Login.Navigate(url_Login_Group, false);
}
private void M_Load(object sender, EventArgs e)
{
}
/// <summary>
/// webBrowserDocumentTitleChanged事件
/// </summary>
private void webBrowser_Login_DocumentTitleChanged(object sender, EventArgs e)
{
//获取网页<title>字符串</title>
string TitleStr = webBrowser_Login.DocumentTitle;
//如果<title>字符串</title>包含"QQ群官网"则说明认证成功`隐藏webBrowser控件
if (TitleStr.Contains("QQ群官网"))
{
//隐藏webBrowser控件
webBrowser_Login.Visible = false;
//设置文本框可用
textBox0.Enabled = true;
//显示导出QQ成员listBox
listBox_0.Visible = true;
//设置界面按钮提示文本
button_M.Text = "提示:请输入QQ群号码!";
}
/*
if (TitleStr.Contains("群成员")) //固定群成员导出
{
string cookie = GetCookies(url_Login_Group);
using (StreamWriter sw = new StreamWriter("Save_group_member_cookie.txt"))//将获取的内容写入文本
{
sw.Write(cookie);
}
string skey = Regex.Match(cookie, @"(?i)(?<=skey=).*?(?=;)").Value, _qpsvr_localtk = Regex.Match(cookie, @"(?i)(?<=_qpsvr_localtk=).*?(?=;)").Value;
webBrowser_Login.Navigate("http://qun.qzone.qq.com/cgi-bin/get_group_member?uin=261081467&groupid=336100817&random=" + _qpsvr_localtk + "&g_tk=" + Getg_tk(skey) + "", false);
button_M.Enabled = true;
button_M.Text = "点击按钮导出群成员...";
}
*/
}
/// <summary>
/// 读取Cookie数据
/// </summary>
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref System.UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved);
private static string GetCookies(string url)
{
uint datasize = 1024;
StringBuilder cookieData = new StringBuilder((int)datasize);
if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x2000, IntPtr.Zero))
{
if (datasize < 0)
return null;
cookieData = new StringBuilder((int)datasize);
if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, IntPtr.Zero))
return null;
}
return cookieData.ToString();
}
/// <summary>
/// 获取g_tk()
/// </summary>
public static int Getg_tk(string str)
{
int hash = 5381, s = 0;
while (s < str.Length)
{
hash += (hash << 5) + (str[s++]);
}
///////////////2147483648
return (hash & 0x7FFFFFFF);
}
/// <summary>
/// 文本框文本变化事件
/// </summary>
private void textBox0_TextChanged(object sender, EventArgs e)
{
//限制文本框只能为0-9数字
var reg = new Regex("^[0-9]*$");
//移除所有空白字符
var str = textBox0.Text.Trim();
var sb = new StringBuilder();
if (!reg.IsMatch(str))
{
for (int i = 0; i < str.Length; i++)
{
if (reg.IsMatch(str[i].ToString()))
{
sb.Append(str[i].ToString());
}
}
textBox0.Text = sb.ToString();
//定义输入焦点在最后一个字符
textBox0.SelectionStart = textBox0.Text.Length;
}
//赋值QQ群号
GropNum = textBox0.Text;
//设置界面按钮提示文本
button_M.Text = "提示:输入QQ群号后,请点击确认...";
//设置界面按钮可点击
button_M.Enabled = true;
//设置QQ群号输入状态
QQGroupInputState = true;
}
private void button_M_Click(object sender, EventArgs e)
{
if (QQGroupInputState)//判断QQ群号输入状态
{
string QQGroupMemberUrl = "http://qun.qq.com/member.html#gid=" + GropNum + "";
webBrowser_Login.Navigate(QQGroupMemberUrl, false);//
//string cookie = GetCookies(url_Login_Group);
string cookie = GetCookies(QQGroupMemberUrl);
//using (StreamWriter sw = new StreamWriter("Save_group_member_cookie.txt"))//将获取的内容写入文本
//{
// sw.Write(cookie);
//}
//定义、获取Cookie值
string skey = Regex.Match(cookie, @"(?i)(?<=skey=).*?(?=;)").Value, _qpsvr_localtk = Regex.Match(cookie, @"(?i)(?<=_qpsvr_localtk=).*?(?=;)").Value, QQnum = Regex.Match(cookie, @"(?i)(?<=pt2gguin=o0).*?(?=;)").Value;
//载入QQ群成员列表
webBrowser_Login.Navigate("http://qun.qzone.qq.com/cgi-bin/get_group_member?uin=" + QQnum + "&groupid=" + GropNum + "&random=" + _qpsvr_localtk + "&g_tk=" + Getg_tk(skey) + "", false);
button_M.Enabled = true;
button_M.Text = "提示:请再次点击按钮导出群成员...";
QQGroupInputState = false;
}
else if (textBox0.Text != string.Empty)
{
listBox_0.Items.Clear();
button_M.Enabled = false;
System.Timers.Timer Timer = new System.Timers.Timer(3000);
string JSONstr = this.webBrowser_Login.DocumentText;
string group_memberNum = Regex.Match(JSONstr, "(?i)(?<=\\\"total\\\":).*?(?=},\\\"default\\\")").Value;//正则表达式直接取出群成员数
JSONstr = Regex.Match(JSONstr, "(?i)(?<=\\\"item\\\":).*?(?=,\\\"level\\\")").Value;//正则表达式直接取出JSON字符串数组
listBox_0.Items.Add("群主\t群管理\t 群成员数:" + group_memberNum + "\t 时间:" + DateTime.Now.ToString() + "");
listBox_0.Items.Add("------------------------------------------------------------------");
button_M.Enabled = true;
try
{
if (group_memberNum != "0")
{
//反序列化JSON字符串数组
JArray jarry = (JArray)JsonConvert.DeserializeObject(JSONstr);
//将反序列化的JSON字符串转换成对象
//JObject jobject = (JObject)jarry[0];
//读取对象中的各项值
//Console.WriteLine(jobject["iscreator"]);
//Console.WriteLine(jobject["ismanager"]);
//Console.WriteLine(jobject["nick"]);
//Console.WriteLine(jobject["uin"]);
using (StreamWriter sw = new StreamWriter("Save_group_member.txt", true))//将获取的内容写入文本
{
sw.Write("--------------------------------------------------------\r\n");
sw.Write("群主\t群管理\t群成员数:" + group_memberNum + "\t时间:" + DateTime.Now.ToString() + "");
sw.Write("\r\n--------------------------------------------------------\r\n");
//遍历反序列化JSON字符串数组
for (int i = 0; i < jarry.Count; i++)
{
listBox_0.Items.Add(jarry[i]["iscreator"] + "\t" + jarry[i]["ismanager"] + "\t " + jarry[i]["uin"]);
sw.Write(jarry[i]["iscreator"] + "\t" + jarry[i]["ismanager"] + "\t" + jarry[i]["uin"] + "\r\n");
}
}
button_M.Text = "提示:导出群成员成功![Save_group_member.txt]...";
}
else { button_M.Text = "提示:导出群成员失败!"; }
}
catch { button_M.Text = "提示:导出群成员失败!"; }
}
else { button_M.Text = "提示:请输入QQ群号码!"; }
}
/// <summary>
/// 界面按钮鼠标右键、中键按钮事件
/// </summary>
private void button_M_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
try { System.Diagnostics.Process.Start(Directory.GetCurrentDirectory() + "/Save_group_member.txt"); }
catch { }
}
if (e.Button == MouseButtons.Middle)
System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
}
}
}

正文完
 0
116博客
版权声明:本篇文章由 116博客 于2024-12-28发表,共计6673字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码