QQ模拟发表带图说说

发表说说之前,必须登录。

模拟QQ登录 >> http://www.cnblogs.com/deeround/p/4386629.html

发表带图说说,自然少不了上传图片,我这使用的PC端上传图片

首先,FileHelper的创建

QQ空间上传图片,使用的flash上传图片,所以我们需要在post的时候,提交的数据进行一个转换。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Web;
 6 
 7 namespace Web.QQ
 8 {
 9     class FileHelper
10     {
11         private List<byte> formData;
12         private Encoding encode = Encoding.GetEncoding("UTF-8");
13         public FileHelper()
14         {
15             formData = new List<byte>();
16         }
17         public void Add(string name, string value)
18         {
19             formData.AddRange(encode.GetBytes("--dnpbajwbhbccmrkegkhtrdxgnppkncfv\r\n"));
20             formData.AddRange(encode.GetBytes("Content-Disposition: form-data; name=\"" + name + "\"\r\n"));
21             formData.AddRange(encode.GetBytes("\r\n"));
22             formData.AddRange(encode.GetBytes(value + "\r\n"));
23         }
24         public void Add(string name, string fileName, byte[] fileData)
25         {
26             formData.AddRange(encode.GetBytes("--dnpbajwbhbccmrkegkhtrdxgnppkncfv\r\n"));
27             formData.AddRange(encode.GetBytes("Content-Disposition: form-data; name=\"filename\"; filename=\"" + fileName + "\"\r\n"));
28             formData.AddRange(encode.GetBytes("Content-Type: application/octet-stream\r\n"));
29             formData.AddRange(encode.GetBytes("\r\n"));
30             formData.AddRange(fileData);
31             formData.AddRange(encode.GetBytes("\r\n"));
32         }
33         public void Add()
34         {
35             formData.AddRange(encode.GetBytes("--dnpbajwbhbccmrkegkhtrdxgnppkncfv--"));
36         }
37         public List<byte> GetFormData()
38         {
39             Add();
40             return formData;
41         }
42     }
43 }


接着,一个生产图片提交的数据方法

 1         public string UploadImage(string qq, string filePath, Model model)
 2         {
 3             string skey = GetCookieString(model.CookieContainer, "skey");
 4 
 5             FileStream file = new FileStream(filePath, FileMode.Open);
 6             byte[] bb = new byte[file.Length];
 7             file.Read(bb, 0, (int)file.Length);
 8             file.Close();
 9 
10             FileHelper form = new FileHelper();
11             form.Add("hd_quality", "96");
12             form.Add("hd_height", "10000");
13             form.Add("filename", "filename");
14             form.Add("upload_hd", "1");
15             form.Add("hd_width", "2048");
16             form.Add("charset", "utf-8");
17             form.Add("output_type", "xml");
18             form.Add("uin", qq);
19             form.Add("output_charset", "utf-8");
20             form.Add("albumtype", "7");
21             form.Add("exif_info", "extendXml:");
22             form.Add("skey", skey);
23             form.Add("zzpaneluin", qq);
24             form.Add("refer", "shuoshuo");
25             form.Add("uploadtype", "1");
26             form.Add("photoData", "filename");
27             form.Add("Filename", Path.GetFileName(filePath));
28             form.Add("filename", Path.GetFileName(filePath), bb);
29             form.Add("Upload", "Submit Query");
30             form.GetFormData();
31 
32             string url = "http://shup.photo.qq.com/cgi-bin/upload/cgi_upload_image";
33             string html = new Helper().Post(url, form.GetFormData().ToArray(), model.CookieContainer);
34 
35             return html;
36         }

接着,发表说说的方法

 1 #region 空间动作
 2         public void PublishShuoShuo(string qq,Model model)
 3         {
 4             string gtk = new Helper().GetGtk(GetCookieString(model.CookieContainer, "skey"));
 5             string url = "http://taotao.qq.com/cgi-bin/emotion_cgi_publish_v6?g_tk=" + gtk;
 6             string content = "我是机器人,请不要为我点赞~~";
 7             string postData = "qzreferrer=http%3A%2F%2Fuser.qzone.qq.com%2F" + qq + "&syn_tweet_verson=1&paramstr=1&pic_template=&richtype=&richval=&special_url=&subrichtype=&con=" + HttpUtility.UrlEncode(content) + "&feedversion=1&ver=1&ugc_right=1&to_tweet=0&to_sign=0&hostuin=" + qq + "&code_version=1&format=fs";
 8 
 9             string html = new Helper().Post(url, postData, model.CookieContainer);
10         }
11         public void PublishShuoShuo(string qq, string filePath, Model model)
12         {
13             //先上传图片
14             string html = UploadImage(qq, filePath, model);
15 
16             IDictionary<string, string> data = new Dictionary<string, string>();
17             string[] lines = html.Replace("\n", "|").Split('|');
18             foreach (var line in lines)
19             {
20                 Regex regex = new Regex("<(.+)>(.*)</.+>");
21                 MatchCollection mc = regex.Matches(line);
22                 foreach (Match m in mc)
23                 {
24                     if (m.Groups.Count > 1)
25                     {
26                         data.Add(m.Groups[1].Value, m.Groups[2].Value);
27                     }
28                 }
29             }
30 
31             string gtk = new Helper().GetGtk(GetCookieString(model.CookieContainer, "skey"));
32             string url = "http://taotao.qq.com/cgi-bin/emotion_cgi_publish_v6?g_tk=" + gtk;
33             string richval = string.Format(",{0},{1},{2},{3},{4},{5},,{4},{5}", data["albumid"], data["lloc"], data["sloc"], data["type"], data["height"], data["width"]);
34             string picbo = string.Format("{0}    {1}", data["pre"].Substring(data["pre"].IndexOf("bo=") + 3), data["url"].Substring(data["url"].IndexOf("bo=") + 3));
35             string content = "我是机器人,请不要为我点赞~~";
36             string postData = "qzreferrer=http%3A%2F%2Fuser.qzone.qq.com%2F" + qq + "&syn_tweet_verson=1&paramstr=1&pic_template=&richtype=1&richval=" + HttpUtility.UrlEncode(richval) + "&special_url=&subrichtype=1&pic_bo=" + HttpUtility.UrlEncode(picbo) + "&con=" + content + "&feedversion=1&ver=1&ugc_right=1&to_tweet=0&to_sign=0&hostuin=" + qq + "&code_version=1&format=fs";
37 
38             string html1 = new Helper().Post(url, postData, model.CookieContainer);
39         }
40 
41 
42 
43         #endregion

最后,如何调用

new Methods().PublishShuoShuo(qq, "D:\\1.png", model);

到此结束,目前只能发送一张图,发表多图说说的话,应该是多执行几次UploadImage,同时生产post数据也需要相应的修改,不过这个还没做。

原文地址:https://www.cnblogs.com/deeround/p/4386693.html