每天定时去女友空间留言工具

luomingui 2014-02-12 04:26:00
加精
1:定时每天自动给固定QQ空间发布不同的留言。
功能列表:
1:定时器。
2:登陆QQ空间。
3:给固定QQ空间留言(随机读取预先设定的文本txt)。
现在的问题:
1: 登陆成功了。
2:发布留言的时候提示没有登陆。
全部代码如下:

namespace QQAPI
{
public partial class Form1 : Form
{
public String host = "http://d.web2.qq.com";
public String shost = "http://s.web2.qq.com";
private Random rd = new Random();
private String get = "get";
private CookieContainer cookies = new CookieContainer();
private String refer = "http://d.web2.qq.com/proxy.html?v=20110331002&callback=2";
private String userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)";
private String accept = "*/*";
private String contentType = "application/x-www-form-urlencoded; charset=UTF-8";
private String verifyCode = "";
private String hex16 = "";
private String skey = "";
private String clientid = new Random().Next(100000000) + "";

//默认需要输入验证码
private Boolean isVerify = false;

public Form1()
{
InitializeComponent();
}
private void butLogin_Click(object sender, System.EventArgs e)
{
//登陆
String qq = this.txtQQNumber.Text.Trim();
String pass = this.txtPwd.Text.Trim();
verifyCode = this.txtcode.Text.Trim();
String md5pass = GetPassword(hex16, pass, verifyCode);
LoginQzone(qq, md5pass, verifyCode);
}
public void GetQzoneVCode()
{
//QQ空间_是否要验证码
String qq = this.txtQQNumber.Text.Trim();
String url = "http://check.ptlogin2.qq.com/check?uin=" + qq + "&appid=549000912&ptlang=2052&js_type=2&js_ver=10009&r=0." + DateTime.Now.Ticks.ToString().Substring(7, 7);
String result = getHtml(url, get, null);
if (result.IndexOf("!") < 0)
{
//需要验证图片
String verifyUrl = "http://captcha.qq.com/getimage?aid=1003903&uin=" + qq + "&r=" + rd.NextDouble();
Stream img = getStream(verifyUrl, get);
Image codeImage = Image.FromStream(img);
this.picbox_code.Image = codeImage;
isVerify = true;
}
else
{
this.verifyCode = result.Substring(result.IndexOf("!"), 4);
this.hex16 = result.Substring(result.IndexOf("\\"), 32);
this.hex16 = this.hex16.Replace("\\x", "");
}
}
public void LoginQzone(string qq, string md5pass, string verifyCode)
{
// QQ空间_登录空间
String loginUrl = "http://ptlogin2.qq.com/login?ptlang=2052&u=" + qq + "&p=" + md5pass + "&verifycode=" + verifyCode + "&css=http://imgcache.qq.com/ptcss/b2/sjpt/549000912/qzonelogin_ptlogin.css&mibao_css=m_qzone&aid=549000912&u1=http%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&ptredirect=1&h=1&from_ui=1&dumy=&fp=loginerroralert&action=10-77-43469&g=1&t=1&dummy=&js_type=2&js_ver=10009";
String loginResult = getHtml(loginUrl, "get", null);
MessageBox.Show(loginResult);
int isLogin = loginResult.IndexOf("登录成功");
if (isLogin > 0)
{
butMessage.Enabled = true;
String cks = cookies.GetCookieHeader(new Uri(loginUrl));
this.skey = getMidStr(cks, "skey=");
}
else
{
MessageBox.Show("登陆失败");
butMessage.Enabled = false;
}
}
public bool QzoneMessage(int qqnum, string message)
{
try
{
int gtk = GetGTK(this.skey);
string num = txtQQNumber.Text.Trim();

WebClient _client = new WebClient();
string host = "http://m.qzone.qq.com/cgi-bin/new/add_msgb?ref=qzone&g_tk=" + gtk + "";

string postValues = "qzreferrer=http%3A%2F%2Fcnc.qzs.qq.com%2Fqzone%2Fmsgboard%2Fmsgbcanvas.html%23uin%3D123456%26pfid%3D2%26qz_ver%3D6%26appcanvas%3D0%26qz_style%3Dv6%2F18%26params%3D%26entertime%3D1356580709748%26canvastype%3D&content="
+ message + "&hostUin=" + qqnum + "&uin=" + num + "&format=fs&g_tk=" + gtk + "&ref=qzone&json=1&inCharset=gbk&outCharset=gbk&iNotice=1";

byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postValues);
byte[] pageData = _client.UploadData(host, "POST", byteArray);
string s = Encoding.Default.GetString(pageData);
this.txtMessage.Text = s;
return true;
}
catch (Exception)
{
return false;
}
}
public string getMidStr(string cks, string flg)
{
string temp = "";
string[] cksall = cks.Split(';');
for (int i = 0; i < cksall.Length; i++)
{
if (cksall[i].Contains(flg))
{
temp = cksall[i].Replace(flg, "").Trim();
break;
}
}
return temp;
}
private void butMessage_Click(object sender, System.EventArgs e)
{
if (QzoneMessage(int.Parse(txtPeerQQ.Text), txtMessage.Text))
{
MessageBox.Show("留言成功");
}
else
{
MessageBox.Show("留言失败");
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
butMessage.Enabled = false;
}
public int GetGTK(string skey)
{
int gtk = 0;
int hash = 5381;
string str = skey;
for (int i = 0, len = str.Length; i < len; ++i)
{
hash += (hash << 5) + str.ElementAt(i);
}
gtk = hash & 0x7fffffff;
return gtk;
}
public string GetPassword(string qq, string password, string verifycode)
{
String P = hexchar2bin(md5(password));
//String U = md5(P + hexchar2bin(qq.Replace("\\x", ""))).ToUpper();
String U = md5(P + hexchar2bin(qq)).ToUpper();
String V = md5(U + verifycode.ToUpper()).ToUpper();
return V;
}
private 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();
}
private string md5(string input)
{
byte[] buffer = MD5.Create().ComputeHash(Encoding.GetEncoding("ISO-8859-1").GetBytes(input));
return binl2hex(buffer);
}
private string hexchar2bin(string passWord)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < passWord.Length; i = i + 2)
{
try
{
builder.Append(Convert.ToChar(Convert.ToInt32(passWord.Substring(i, 2), 16)));
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
return builder.ToString();
}
private String getHtml(String url, String method, String data)
{
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.UserAgent = this.userAgent;
request.Accept = this.accept;
request.ContentType = this.contentType;
request.Method = method;
request.Referer = this.refer;
request.CookieContainer = this.cookies;
if (method.Equals("post"))
{
byte[] byteRequest = Encoding.Default.GetBytes(data);
Stream rs = request.GetRequestStream();
rs.Write(byteRequest, 0, byteRequest.Length);
rs.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies.Add(response.Cookies);
Stream resultStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resultStream, Encoding.UTF8);
string html = sr.ReadToEnd();
sr.Close();
resultStream.Close();
request.Abort();
response.Close();
return html;
}
private Stream getStream(String url, String method)
{
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.UserAgent = this.userAgent;
request.Accept = this.accept;
request.ContentType = this.contentType;
request.Method = method;
request.Referer = this.refer;
request.CookieContainer = this.cookies;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
foreach (Cookie cookie in response.Cookies)
{
cookies.Add(cookie);
}
Stream s = response.GetResponseStream();
return s;
}
private void txtQQNumber_Click(object sender, EventArgs e)
{
GetQzoneVCode();
}
}
}
...全文
35351 292 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
292 条回复
切换为时间正序
请发表友善的回复…
发表回复
bugdream2 2016-09-26
  • 打赏
  • 举报
回复
加几个脚本,目标qq用函数写。 一个广告发布器就出来了
shanNancy 2016-09-12
  • 打赏
  • 举报
回复
这是个好东西 留着给未来男友用了
qq_36102983 2016-09-10
  • 打赏
  • 举报
回复
好东西.~~. 能发我用用么
HW_1549924525 2016-09-06
  • 打赏
  • 举报
回复
求整个项目源码、发给我 谢谢 1549924525@qq.com
幻_影 2016-08-31
  • 打赏
  • 举报
回复
有女朋友,就不要这样zuo了吧!!!
Achu_Sama 2016-06-08
  • 打赏
  • 举报
回复
引用 23楼super_admi 的回复:
这个工具的最大用处,其实是:几十年后,当你死去了,还可以继续每天定时给女友留言。
有道理。
mj_901222 2016-05-30
  • 打赏
  • 举报
回复
引用 2 楼 奥萨马-本-拉登的回复:
灰常好的东西 问题是先要有个女友
哈哈,有备无患啊程序员真是太厉害了,我要坚持自己的想法,找个程序员男票
二十一加一 2016-05-26
  • 打赏
  • 举报
回复
求源码一份,虽然过了这么久,但是对于刚接触c#不到一年时间的我,估计会受用,948679570qq@.com 谢谢!
老猫不萌 2016-04-21
  • 打赏
  • 举报
回复
好东西啊
  • 打赏
  • 举报
回复

周小逝 2016-04-20
  • 打赏
  • 举报
回复
引用 23 楼 super_admi的回复:
这个工具的最大用处,其实是:几十年后,当你死去了,还可以继续每天定时给女友留言。
说的好忧伤也好感动π_π
玩命小刀 2016-04-17
  • 打赏
  • 举报
回复
66666666666666
qq_32706563 2016-04-02
  • 打赏
  • 举报
回复
有个bug啊 哥们 要是哪天 你女友问你发的啥留言 咋也不能现场 拿手机再看看吧 那就穿帮了
OnlyOne88888 2016-03-30
  • 打赏
  • 举报
回复
如果真心喜欢一个人那就天天坚持去向她表达你的爱,干嘛想这些,虽然好用,但显得没诚意! 有木有啊?
sinat_32382135 2016-03-30
  • 打赏
  • 举报
回复
66666,赶紧找个女票来试试。
tylertiger 2016-03-11
  • 打赏
  • 举报
回复
楼主送个女朋友呗
21_XRL 2015-12-01
  • 打赏
  • 举报
回复
没对象的去创建一个对象呗。。哈哈哈。谢谢楼主
  • 打赏
  • 举报
回复
面向对象编程
qq_33211385 2015-12-01
  • 打赏
  • 举报
回复
求整个项目源码、发给我 谢谢 1204692119@qq.com
  • 打赏
  • 举报
回复
对单身汪造成一万点真实伤害。
加载更多回复(272)

111,095

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧