1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > C# 登录QQ网站并获取QQ相关信息

C# 登录QQ网站并获取QQ相关信息

时间:2020-12-28 20:25:06

相关推荐

C# 登录QQ网站并获取QQ相关信息

1)首先用谷歌浏览器打开,并用开发人员工具(快捷键:ctrl+shift+i)查看登陆框地址

2)Open link in new tab

到这里我们已经得到独立登陆框的地址了,方便调试和拦截请求。

成果

登录框地址:

http://ui./cgi-bin/login?appid=1006102&hide_title_bar=1&begin_time=1347444392246

&css=http%3A%2F%%2Fptcss%2Fr1%2Fjt%2F1006102%2Fpt_login.css

&f_url=loginerroralert&no_verifyimg=1&qlogin_jumpname=jump&hide_close_icon=1&s_url=/index.html

URL中有很多控制样式的参数,可简化为如下地址:

http://ui./cgi-bin/login?appid=1006102&s_url=/index.html

通过浏览器的开发人员工具或其他HTTP拦截工具获得登录时请求的地址。

1)打开上一步得到的登录地址,并开启浏览器的开发人员工具,用以拦截请求。2)随便输入一个号码、密码、验证码后点击登录,得到如下结果:

我们可以看到一共发送了3个请求:

值得一提的是,通过调试发现点击登录后密码在客户端是通过加密后再传输的(加密方法位于comm.js,有兴趣的可以在JS中查看如下方法)。

var M = C.p.value;var I = hexchar2bin(md5(M));var H = md5(I + pt.uin);var G = md5(H + C.verifycode.value.toUpperCase());

加密方法翻译为C#后如下:

public class PasswordHelper{/// <summary>/// 根据QQ号码和验证码加密密码/// </summary>/// <param name="qqNum">QQ号码</param>/// <param name="password">QQ密码</param>/// <param name="verifycode">验证码</param>/// <returns>密码密文</returns>public static string GetPassword(string qqNum, string password, string verifycode){//uin为QQ号码转换为16位的16进制int qq;int.TryParse(qqNum, out qq);qqNum = qq.ToString("x");qqNum = qqNum.PadLeft(16, '0');String P = hexchar2bin(md5(password));String U = md5(P + hexchar2bin(qqNum)).ToUpper();String V = md5(U + verifycode.ToUpper()).ToUpper();return V;}public static string md5(string input){byte[] buffer = MD5.Create().ComputeHash(Encoding.GetEncoding("ISO-8859-1").GetBytes(input));return binl2hex(buffer);}public static string binl2hex(byte[] buffer){StringBuilder builder = new StringBuilder();for (int i = 0; i < buffer.Length; i++){builder.Append(buffer[i].ToString("x2"));}return builder.ToString();}public static string hexchar2bin(string passWord){StringBuilder builder = new StringBuilder();for (int i = 0; i < passWord.Length; i = i + 2){builder.Append(Convert.ToChar(Convert.ToInt32(passWord.Substring(i, 2), 16)));}return builder.ToString();}

直接用设计器拖一个登录界面出来,并模仿登录操作,使用HttpHelper发送上面的请求。

我所使用的HttpHelper如下,很简单,大家可以自行扩展:

public class HttpHelper{private static string contentType = "application/x-www-form-urlencoded";private static string accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";private static string userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Zune 4.7; BOIE9;ZHCN)";public static string referer = "http://ui./cgi-bin/login?appid=1006102&s_url=/index.html";/// <summary>/// 获取字符流/// </summary>/// <param name="url"></param>/// <param name="cookieContainer"></param>/// <returns></returns>public static Stream GetStream(string url, CookieContainer cookieContainer){HttpWebRequest httpWebRequest = null;HttpWebResponse httpWebResponse = null;try{httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);httpWebRequest.CookieContainer = cookieContainer;httpWebRequest.ContentType = contentType;httpWebRequest.Referer = referer;httpWebRequest.Accept = accept;httpWebRequest.UserAgent = userAgent;httpWebRequest.Method = "GET";httpWebRequest.ServicePoint.ConnectionLimit = int.MaxValue;httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();Stream responseStream = httpWebResponse.GetResponseStream();return responseStream;}catch (Exception){return null;}}/// <summary>/// 获取HTML/// </summary>/// <param name="url"></param>/// <param name="cookieContainer"></param>/// <returns></returns>public static string GetHtml(string url, CookieContainer cookieContainer){HttpWebRequest httpWebRequest = null;HttpWebResponse httpWebResponse = null;try{httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);httpWebRequest.CookieContainer = cookieContainer;httpWebRequest.ContentType = contentType;httpWebRequest.Referer = referer;httpWebRequest.Accept = accept;httpWebRequest.UserAgent = userAgent;httpWebRequest.Method = "GET";httpWebRequest.ServicePoint.ConnectionLimit = int.MaxValue;httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();Stream responseStream = httpWebResponse.GetResponseStream();StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);string html = streamReader.ReadToEnd();streamReader.Close();responseStream.Close();httpWebRequest.Abort();httpWebResponse.Close();return html;}catch (Exception){return string.Empty;}}}

通过拦截请求并分析得出我需要的信息位于如下请求中: /cgi-bin/summary?ldw=f61210b82e57b6a466af5fcabe07b2d6720bf092d69e4eab

注:ldw从登录后的cookie中获取 然后继续发送请求:

自此我们的功能基本上完成了,登录成功后查询其他数据也都很方便了。

在实际操作中需要注意参数的传递和cookie的获取。查询有些数据前必须要先发送一些特定的请求去获取cookie或参数。

祝你成功!只要登录后可以直接获取QQ空间信息或WebQQ中的信息亦或是操作QQ游戏。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。