QQ农场助手,仿QQ伴侣界面,简单的功能已经可以用,VS 2005开发的。分析http请求工具,可以用HttpAnalyzer。

关键代码:

登录代码

#region QQ登陆时必备函数
publicstaticstring binl2hex(byte[] buffer)
{
StringBuilder builder =new StringBuilder();
for (int i =0; i < buffer.Length; i++)
{
builder.Append(buffer[i].ToString("x2"));
}
return builder.ToString();
}
publicstaticstring md5_3(string input)
{
MD5 md = MD5.Create();
byte[] buffer = md.ComputeHash(Encoding.Default.GetBytes(input));
buffer = md.ComputeHash(buffer);
buffer = md.ComputeHash(buffer);
return binl2hex(buffer);
}

publicstaticstring md5(string input)
{
byte[] buffer = MD5.Create().ComputeHash(Encoding.Default.GetBytes(input));
return binl2hex(buffer);
}
#endregion

///<summary>
/// 获取加密后的密码
///</summary>
///<param name="password"></param>
///<param name="verifycode"></param>
///<returns></returns>
publicstaticstring getPassword(string password, string verifycode)
{
return md5(md5_3(password).ToUpper() + verifycode.ToUpper()).ToUpper();
}

///<summary>
/// //QQ农场的farmTime
///</summary>
///<returns></returns>
publicstaticint GetfarmTime()
{
TimeSpan t = DateTime.Now.Subtract(DateTime.Parse("1970-1-1 08:00:00"));
return (int)t.TotalSeconds;
}
/// 获得FarmKey
publicstaticstring GetFarmKey(string farmTime)
{
return md5(farmTime +"sdoit78sdopig7w34057".Substring(Convert.ToInt32(farmTime) %10));
}

Unix时间戳

///<summary>
/// 得到某个时间增加某个小时后的Unix时间戳
///</summary>
///<param name="dt"></param>
///<param name="hours"></param>
///<returns></returns>
publicstaticstring GetUnixtimeStamp(DateTime dt, int hours)
{
double temp =double.Parse(hours.ToString());
dt = dt.AddHours(temp);
return GetUnixTimeStamp(dt);
}
///<summary>
/// 得到某个时间的Unix时间戳
///</summary>
///<param name="dt"></param>
///<returns></returns>
publicstaticstring GetUnixTimeStamp(DateTime dt)
{
DateTime unixStartTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
TimeSpan timeSpan = dt.Subtract(unixStartTime);
string timeStamp = timeSpan.Ticks.ToString();

return timeStamp.Substring(0, timeStamp.Length -7);
}
///<summary>
/// 得到QQ验证码
///</summary>
///<returns></returns>
public Stream GetValidateCode()
{
int random =new Random().Next(10000, 1000000);
Stream s = httpHelper.GetStream("http://ptlogin2.qq.com/getimage?aid=15000102&"+ random, CookieMng.CurrentCookie);
return s;
}

Json数据处理

///<summary>
/// 处理json数据,返回Dictionary对象
///</summary>
///<param name="jsondata"></param>
///<returns></returns>
publicstatic Dictionary<string, object> Deserialize(string jsondata)
{
JavaScriptSerializer serializer =new JavaScriptSerializer();
Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(jsondata);
return json;
}
///<summary>
/// 处理json数据,返回object对象
///</summary>
///<param name="jsondata"></param>
///<returns></returns>
publicstaticobject[] DeserializeToObject(string jsondata)
{
JavaScriptSerializer serializer =new JavaScriptSerializer();
object[] json = (object[])serializer.DeserializeObject(jsondata);
return json;
}

Cookie的管理

public staticclass CookieMng
{
privatestatic CookieContainer ccontainer;

///<summary>
/// 静态构造函数
///</summary>
static CookieMng()
{
ccontainer =new CookieContainer();
}
///<summary>
/// 获取当前的cookie
///</summary>
publicstatic CookieContainer CurrentCookie
{
get { return ccontainer; }
set { ccontainer = value; }
}
}

HttpHelper类

publicclass HttpHelper
{
#region 私有变量
private CookieContainer cc;
privatestring contentType ="application/x-www-form-urlencoded";
privatestring 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, */*";
privatestring userAgent ="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
private Encoding encoding = Encoding.GetEncoding("utf-8");
privateint delay =3000;
privateint maxTry =3;
privateint currentTry =0;
#endregion

publicstatic FrmValidateCode frmValidateCode;
#region 属性
///<summary>
/// Cookie容器
///</summary>
public CookieContainer CookieContainer
{
get
{
return cc;
}
}

///<summary>
/// 获取网页源码时使用的编码
///</summary>
///<value></value>
public Encoding Encoding
{
get
{
return encoding;
}
set
{
encoding = value;
}
}

publicint NetworkDelay
{
get
{
Random r =new Random();
return (r.Next(delay /1000, delay /1000*2)) *1000;
}
set
{
delay = value;
}
}

publicint MaxTry
{
get
{
return maxTry;
}
set
{
maxTry = value;
}
}
#endregion

#region 构造函数
///<summary>
/// Initializes a new instance of the <see cref="HttpHelper"/> class.
///</summary>
public HttpHelper()
{
cc =new CookieContainer();
}

///<summary>
/// Initializes a new instance of the <see cref="HttpHelper"/> class.
///</summary>
///<param name="cc">The cc.</param>
public HttpHelper(CookieContainer cc)
{
this.cc = cc;
}

///<summary>
/// Initializes a new instance of the <see cref="HttpHelper"/> class.
///</summary>
///<param name="contentType">Type of the content.</param>
///<param name="accept">The accept.</param>
///<param name="userAgent">The user agent.</param>
public HttpHelper(string contentType, string accept, string userAgent)
{
this.contentType = contentType;
this.accept = accept;
this.userAgent = userAgent;
}

///<summary>
/// Initializes a new instance of the <see cref="HttpHelper"/> class.
///</summary>
///<param name="cc">The cc.</param>
///<param name="contentType">Type of the content.</param>
///<param name="accept">The accept.</param>
///<param name="userAgent">The user agent.</param>
public HttpHelper(CookieContainer cc, string contentType, string accept, string userAgent)
{
this.cc = cc;
this.contentType = contentType;
this.accept = accept;
this.userAgent = userAgent;
}
#endregion

#region 公共方法
///<summary>
/// 获取指定页面的HTML代码
///</summary>
///<param name="url">指定页面的路径</param>
///<param name="postData">回发的数据</param>
///<param name="isPost">是否以post方式发送请求</param>
///<param name="cookieCollection">Cookie集合</param>
///<returns></returns>
publicstring GetHtml(string url, string postData, bool isPost, CookieContainer cookieContainer)
{
if (string.IsNullOrEmpty(postData))
{
return GetHtml(url, cookieContainer);
}
currentTry++;
try
{
byte[] byteRequest = Encoding.Default.GetBytes(postData);

HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = contentType;
httpWebRequest.Referer = url;
httpWebRequest.Accept = accept;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.Method = isPost ?"POST" : "GET";
httpWebRequest.ContentLength = byteRequest.Length;

Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();

HttpWebResponse httpWebResponse;
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader =new StreamReader(responseStream, encoding);
string html = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();

currentTry =0;

if (html.Contains("validateCode"))
{
if (string.IsNullOrEmpty(QQ.FriendQQ))
{
QQ.FriendQQ = QQ.CurrentQQ;
}
if (frmValidateCode ==null)
{
frmValidateCode =new FrmValidateCode();//将主窗体对象传递过去
frmValidateCode.ShowDialog();
}
else
{
frmValidateCode.Activate();
if (!frmValidateCode.Visible)
{
frmValidateCode.ShowDialog();
}
}
returnnull;
}
new Log().WriteLog(html); //记录每一次请求的html代码
return html;
}
catch (Exception e)
{
//Console.ForegroundColor = ConsoleColor.Red;
//Console.WriteLine(DateTime.Now.ToString("HH:mm:ss ") + e.Message);
//Console.ForegroundColor = ConsoleColor.White;

//if (currentTry <= maxTry)
//{
// GetHtml(url, postData, isPost, cookieContainer);
//}

//currentTry = 0;
returnstring.Empty;
}
}

///<summary>
/// 获取指定页面的HTML代码
///</summary>
///<param name="url">指定页面的路径</param>
///<param name="cookieCollection">Cookie集合</param>
///<returns></returns>
publicstring GetHtml(string url, CookieContainer cookieContainer)
{
Thread.Sleep(NetworkDelay);

currentTry++;

try
{
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = contentType;
httpWebRequest.Referer = url;
httpWebRequest.Accept = accept;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.Method ="GET";

HttpWebResponse httpWebResponse;
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader =new StreamReader(responseStream, encoding);
string html = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();

currentTry =0;
if (html.Contains("validateCode"))
{
if (string.IsNullOrEmpty(QQ.FriendQQ))
{
QQ.FriendQQ = QQ.CurrentQQ;
}
if (frmValidateCode ==null)
{
frmValidateCode =new FrmValidateCode();//将主窗体对象传递过去
frmValidateCode.ShowDialog();
}
else
{
frmValidateCode.Activate();
if (!frmValidateCode.Visible)
{
frmValidateCode.ShowDialog();
}
}
returnnull;
}
return html;
}
catch (Exception e)
{
//Console.ForegroundColor = ConsoleColor.Red;
//Console.WriteLine(DateTime.Now.ToString("HH:mm:ss ") + e.Message);
//Console.ForegroundColor = ConsoleColor.White;

//if (currentTry <= maxTry)
//{
// GetHtml(url, cookieContainer);
//}

//currentTry = 0;
returnstring.Empty;
}
}

///<summary>
/// 获取指定页面的HTML代码
///</summary>
///<param name="url">指定页面的路径</param>
///<returns></returns>
publicstring GetHtml(string url)
{
return GetHtml(url, cc);
}

///<summary>
/// 获取指定页面的HTML代码
///</summary>
///<param name="url">指定页面的路径</param>
///<param name="postData">回发的数据</param>
///<param name="isPost">是否以post方式发送请求</param>
///<returns></returns>
publicstring GetHtml(string url, string postData, bool isPost)
{
return GetHtml(url, postData, isPost, cc);
}

///<summary>
/// 获取指定页面的Stream
///</summary>
///<param name="url">指定页面的路径</param>
///<param name="postData">回发的数据</param>
///<param name="isPost">是否以post方式发送请求</param>
///<param name="cookieCollection">Cookie集合</param>
///<returns></returns>
public Stream GetStream(string url, CookieContainer cookieContainer)
{
currentTry++;
try
{
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = contentType;
httpWebRequest.Referer = url;
httpWebRequest.Accept = accept;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.Method ="GET";

HttpWebResponse httpWebResponse;
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
currentTry =0;

CookieCollection cc = cookieContainer.GetCookies(new Uri(url));
return responseStream;
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss ") + e.Message);
Console.ForegroundColor = ConsoleColor.White;

if (currentTry <= maxTry)
{
GetHtml(url, cookieContainer);
}

currentTry =0;
returnnull;
}
}
#endregion
}

下载  源代码下载

转载于:https://www.cnblogs.com/lhking/archive/2010/01/10/1643590.html

QQ校友农场助手(有源码)相关推荐

  1. 仿QQ校友DIV模拟窗口

    最近有一个学生信息平台要做,估计也将成为我的毕业设计.打算做成和QQ校友一样,于是便开始了一系列的模仿. 既然是要提高用户体验,ajax当然必不可少,div模拟窗口也是必不可少的了,这次我还是拿那个j ...

  2. java在线支付---13.java在线支付所有源码:

    13.java在线支付所有源码: 创梦综合技术qq交流群:CreDream:251572072 ------------------------------------- a.新建工程payment ...

  3. 计算机毕业设计选题、开题、答辩、模板大全(有源码)

    毕业设计选题五问法: 第一问.自己会什么(一定是自己有一定了解的,那样自己有思路): 第二问,这个是什么: 第三问,为什么要去做: 第四问,该怎么去做: 第五问.创新点是什么. 在做毕业设计的时候,遇 ...

  4. 自已开发IM有那么难吗?手把手教你自撸一个Andriod版简易IM (有源码)

    本文由作者FreddyChen原创分享,为了更好的体现文章价值,引用时有少许改动,感谢原作者. 1.写在前面 一直想写一篇关于im即时通讯分享的文章,无奈工作太忙,很难抽出时间.今天终于从公司离职了, ...

  5. 如何使用正则表达式进行QQ校友的数据采集

    QQ校友里面很多数据是按照学校进行归类的,因此,我们只要知道学校的名称,根据一些条件就可以查找您感兴趣的校友了. QQ校友的数据查看或者查询,是需要登录才行的,QQ校友的登录,可以让用户通过输入验证码 ...

  6. 适合新手:手把手教你用Go快速搭建高性能、可扩展的IM系统(有源码)

    本文为开源工程:"github.com/GuoZhaoran/fastIM"的配套文章,原作者:"绘你一世倾城",现为:猎豹移动php开发工程师,感谢原作者的技 ...

  7. 实用c语言函数源码,C语言编写简单朗读小工具(有源码)

    原标题:C语言编写简单朗读小工具(有源码) 最近不少人在后台留言说学C都是面对枯燥的控制台程序,能不能体现一下C语言的实际用途,今天我们就理论结合实践一把:C语言结合VBS脚本编写一个简单的朗读小工具 ...

  8. Robotium测试没有源码的apk--需重签名apk

    Robotium是基于Instrumentation框架的,其编写的测试脚本与被测程序运行在同一个进程里面,所以这需要测试程序与被测程序拥有相同的签名,否则无法进行通讯. 在只有apk的情况下可以采用 ...

  9. Shiro 核心功能案例讲解 基于SpringBoot 有源码

    Shiro 核心功能案例讲解 基于SpringBoot 有源码 从实战中学习Shiro的用法.本章使用SpringBoot快速搭建项目.整合SiteMesh框架布局页面.整合Shiro框架实现用身份认 ...

最新文章

  1. 用v-for循环动态定位坐标显示元素,并遍历元素的left和top坐标位置(只需要用到元素的宽高、索引、每行显示数量)
  2. Windows下安装python的pip
  3. 斯坦福助理教授马腾宇:ML非凸优化很难,如何破?
  4. PHP的TRUE|FALSE
  5. Android Studio百度地图开发所需参数获取SHA1或MD5的最简单方法(图文教程)
  6. Css Sprites 多张图片整合在一张图片上
  7. 二进制搜索树_将排序的数组转换为二进制搜索树
  8. python全局变量修改_python中全局变量的修改
  9. 在SQL SERVER里面用命令查包含某字段的表
  10. Nginx基本配置备忘
  11. unity性能优化初级入门篇
  12. 硬件工程师成长之路(10.1)——芯片选型
  13. 单片机基础学-按键篇
  14. yylabel html不显示图片,YYLabel富文本
  15. STM32——DCMI接口与OV2640原理与配置
  16. UT000010 Session is Invalid
  17. 编辑网页document.body.contentEditable='true';
  18. oracle数据库latch,关于Oracle数据库latch: cache buffers chains等待事件
  19. 考研的 本科“出身”到底重不重要?
  20. 串口转以太网模块:WIZ125SR数据手册

热门文章

  1. Camera和Image sensor技术基础笔记(10) -- sensor器件适配需要注意的地方
  2. 操作系统文件的逻辑结构及其文件目录
  3. 在linux下配置网桥透明模式防火墙
  4. 开篇 - 麒麟子全方位解读 Cocos Cyberpunk 工程源码
  5. bitlife设置中文_生活模拟器BitLife
  6. PHP——流程控制语句
  7. 找一份好的前端工作,起点很重要
  8. PCA主成分分析(完结)
  9. DA转换器是什么?快来一起学习一下吧
  10. CCS 之 关于TI 28035 SPI的一点问题