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

.Net技术 码拜 9年前 (2016-03-03) 1209次浏览
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();
        }
    }
}
解决方案

10

你的cookie有问题吧,这个是一个正常能发的pt2gguin=o0410235323; uin=o0410235323; skey=@ol33mlFmH; ETK=; superuin=o0410235323; superkey=Ubq7W0QqdelWDwEyiaT*ZpxiJFqljRuhcvZotoXdmHc_; supertoken=3055352254; ptisp=ctc; RK=4QHqJDBk0p; ptuserinfo=63616e6e6f74207772697465; u_410235323=@ol33mlFmH:1392195431:1392195431:63616e6e6f74207772697465:1; ptcz=babee4af2be5f7a29fb3a90a2987a2c78e5c3dcbd16e11fbd87861cce28dd67a; airkey=;

10

引用 84 楼 jtczhouxiang 的回复:

给你一个本人刚整的 然后可以参考本人的 把你的弄完每天定时去女友空间留言工具
下载地址:http://pan.decadework.com/file/2014/2/13/2014021316385067499.zip
界面运行图:
每天定时去女友空间留言工具
本人这个假如操作频繁 会提示输入验证码
其实还有许多BUG 未处理  发上来 只是给你借鉴一下
本人的思路是 直接操作网页 不根据URL去整
每天定时去女友空间留言工具

你这个好像没看见留言啊

10

咳咳、、、虽然俺也不知道女朋友是什么东西,不过。还是把这个帖子给琢磨出来吧,亲测有效!
LZ的问题在于留言时Cookie没有发送成功,只需要在QQ登陆成功之后截取下来,然后留言时再填上去即可。
首先,把LoginQzone的cks改为全局,然后留言时加上一句:
_client.Headers.Add(“Cookie”, this.cks);
给WebClient加上Cookie发送,测试OK了。

10

这里,Cookie没有

        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;
            }
        }

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明每天定时去女友空间留言工具
喜欢 (0)
[1034331897@qq.com]
分享 (0)