实例介绍
【实例简介】
【实例截图】
【实例截图】
【核心代码】
using MSScriptControl; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DotNet4.Utilities; using System.Text.RegularExpressions; using System.Web; using NS_SnsSigCheck; using Newtonsoft.Json.Linq; using System.Web.Script.Serialization; using System.Threading; namespace BOYAPOKER { public partial class Form1 : Form { public Form1() { InitializeComponent(); } HttpHelper http = new HttpHelper(); HttpResult HtmlResult; String receiveFromCheck; String forCheckUrl; String forImageUrl; public int hasimage = 0; //表示是否含有验证码图片 public int Enter_state=0; //表示是否含 有验证码 String checkCode; String[] checkNum; string md5pass,md5pwd; string JsonStr; int checkCodePosition; string gtk,skey,jscommd,cookiestr; HttpItem item = new HttpItem() { URL = "http://qqapp.qq.com/app/23006.html",//URL 必需项 Method = "get",//URL 可选项 默认为Get IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写 Cookie = "",//字符串Cookie 可选项 Referer = "",//来源URL 可选项 Postdata = "",//Post数据 可选项GET时不需要写 Timeout = 100000,//连接超时时间 可选项默认为100000 ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000 UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值 ContentType = "text/html",//返回类型 可选项有默认值 Allowautoredirect = false,//是否根据301跳转 可选项 //CerPath = "d:\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数 //Connectionlimit = 1024,//最大连接数 可选项 默认为1024 ProxyIp = "",//代理服务器ID 可选项 不需要代理 时可以不设置这三个参数 //ProxyPwd = "123456",//代理服务器密码 可选项 //ProxyUserName = "administrator",//代理服务器账户名 可选项 ResultType = ResultType.String }; /// <summary> /// 将账号16进制化 /// </summary> /// <returns></returns> public string hexchar2bin(string uin) { string[] strarry=new string [8]; string str16,str=null; int xstrnum = 0; long u; u = Convert.ToInt64(uin); str16 = u.ToString("X"); if (str16.Length<16) { int a = str16 .Length/ 2; for (int n = 0; n < a; n ) { str16 = "00" str16; } } for (int i = 0; i < str16.Length-1; i=i 2) { strarry[xstrnum]="\\x" str16.Substring(i,2); xstrnum ; } for (int i = 0; i < strarry.Length; i ) { str=str strarry[i]; } return str; } /// <summary> /// 获取时间戳 /// </summary> /// <returns></returns> public string timestring() { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); DateTime dtNow = DateTime.Parse(DateTime.Now.ToString()); TimeSpan toNow = dtNow.Subtract(dtStart); string timeStamp = toNow.Ticks.ToString(); timeStamp = timeStamp.Substring(0, timeStamp.Length - 7); return timeStamp; } /// <summary> /// 将Dictionary重新按key进行字典升序排列 /// </summary> /// <param name="param">Dictionary数据</param> /// <returns></returns> public Dictionary<string, object> sortJson(Dictionary<string, object> param) { Dictionary<string, object> query_string = new Dictionary<string, object>(); List<KeyValuePair<string, object>> myList = new List<KeyValuePair<string, object>>(param); myList.Sort(delegate(KeyValuePair<string, object> s1, KeyValuePair<string, object> s2) { return s1.Key.CompareTo(s2.Key); }); foreach (KeyValuePair<string, object> pair in myList) { query_string[pair.Key] = pair.Value; } return query_string; } /// <summary> /// 将json数据反序列化为Dictionary /// </summary> /// <param name="jsonData">json数据</param> /// <returns></returns> public Dictionary<string, object> JsonToDictionary(string jsonData) { //实例化JavaScriptSerializer类的新实例 JavaScriptSerializer jss = new JavaScriptSerializer(); try { //将指定的 JSON 字符串转换为 Dictionary<string, object> 类型的对象 return jss.Deserialize<Dictionary<string, object>>(jsonData); } catch (Exception ex) { throw new Exception(ex.Message); } } /// <summary> /// 将Dictionary序列化为json数据 /// </summary> /// <param name="jsonData">json数据</param> /// <returns></returns> public string DictionaryToJson(Dictionary<string, object> dic) { //实例化JavaScriptSerializer类的新实例 JavaScriptSerializer jss = new JavaScriptSerializer(); try { //将指定的 JSON 字符串转换为 Dictionary<string, object> 类型的对象 return jss.Serialize(dic); } catch (Exception ex) { throw new Exception(ex.Message); } } private void button1_Click(object sender, EventArgs e) { FileStream fs = new FileStream("PASS.JS", FileMode.Open); StreamReader m_streamReader = new StreamReader(fs); m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin); string strLine = m_streamReader.ReadLine(); m_streamReader.Close(); m_streamReader.Dispose(); fs.Close(); fs.Dispose(); ScriptControlClass js = new ScriptControlClass(); js.Language = "JScript"; js.AddCode(strLine); if (pass.Text==null||uin.Text==null||veriycode==null) { MessageBox.Show("登陆参数不完整!","提示"); Enter_state = 1; } if (Enter_state==0) { md5pass = "md5js(\"" pass.Text "\",\"" veriycode.Text "\",\"" hexchar2bin(uin.Text) "\")"; md5pwd = js.Eval(md5pass).ToString(); forCheckUrl = "http://ptlogin2.qq.com/login?u=" uin.Text "&p=" md5pwd "&verifycode=" veriycode.Text "&aid=15000101&u1=http%3A%2F%2Fwww.qq.com%2Fqq2012%2FloginSuccess.htm&h=1&ptredirect=0&ptlang=2052&from_ui=1&dumy=&low_login_enable=0®master=&fp=loginerroralert&action=23-40&mibao_css=&t=1&g=1&js_ver=10041&js_type=1"; item.URL = forCheckUrl; item.Referer = "http://qzone.qq.com/"; HtmlResult = http.GetHtml(item); item.Cookie = HtmlResult.Cookie; receiveFromCheck = HtmlResult.Html; checkCodePosition = receiveFromCheck.IndexOf("(") 1; checkCode = receiveFromCheck.Substring(checkCodePosition, receiveFromCheck.LastIndexOf(")") - checkCodePosition); checkNum = checkCode.Replace("'", "").Split(','); //验证码数组 if (checkNum[0]=="0") { textBox2.Text = "登陆成功!"; skey = item.Cookie.Substring(item.Cookie.IndexOf("skey=", 0) 5, 10); jscommd = "getGTK(\"" skey "\")"; gtk = js.Eval(jscommd).ToString(); item.URL = "http://appsupport.qq.com/cgi-bin/qzapps/userapp_addapp.cgi?uin=" uin.Text "&g_tk=" gtk; item.Referer = "http://ctc.qzs.qq.com/qzone/v5/toolpages/fp_utf8.html"; item.Method = "post"; item.Postdata = "uin=" uin.Text "&g_tk=" gtk "&appid=23006&via=\"\"&detail=\"\"&qzreferrer=http://my.qzone.qq.com/app/23006.html#jump=http%3a%2f%2frc.qzone.qq.com%2f23006"; HtmlResult = http.GetHtml(item); receiveFromCheck = HtmlResult.Html; item.Method = "GET"; item.URL = "http://my.qzone.qq.com/app/23006.html"; HtmlResult = http.GetHtml(item); receiveFromCheck = HtmlResult.Html; //string A = MidContent(receiveFromCheck, "\"no\" src=\"", "\" width=\"780\""); //item.URL = A; //HtmlResult = http.GetHtml(item); //receiveFromCheck = HtmlResult.Html; string PostData = MidContent(receiveFromCheck, "\"openid\":\"", "\",\"openkey\""); //JObject obj = JObject.Parse("{\"api\":\"65\",\"langtype\":\"1\",\"method\":\"Members.Create\",\"mid\":\"0\",\"mtkey\":\"\",\"param\":{\"ANPSetting\":\"4\",\"APNSToken\":\"APA91bEsQTnR66YLBr2dzIzydJJtixolsRsv9XUbFhDkRJWpHp5I7-zfGl-zUbkIOvyjGWywhZmDWtUx9qfhBTgV22favyR-nHlOvIXQ6hZknrQxoxFPvgahVai2QZIAoyPC-SwH5TWbOtMZ_-LIWOU5Y3Qh3aQw6Q\",\"appid\":\"100029\",\"appkey\":\"c4b6eaa30ad2bd635a1154b34549b3d7\",\"mnick\":\"Lan998\",\"sitemid\":\"000000000000000000000000848CF5B5\",\"token\":\"1637E6D9BC1A21DA4C171A33391CE837\"},\"protocol\":\"1\",\"sid\":\"93\",\"time\":\"1400763756\",\"unid\":\"196\",\"version\":\"4.6.2\",\"vkey\":\"\",\"vmid\":\"\"}"); Dictionary<string, object> sortedDic = new Dictionary<string, object>(); sortedDic.Add("api", "65"); sortedDic.Add("langtype", "1"); sortedDic.Add("method", "Members.Create"); sortedDic.Add("mid", "0"); sortedDic.Add("mtkey", ""); sortedDic.Add("param", "{\"ANPSetting\":\"4\",\"appid\":\"0\",\"appkey\":\"init\",\"mnick\":\"\",\"sitemid\":" PostData ",\"token\":\"\"}"); sortedDic.Add("protocol", "1"); sortedDic.Add("sid", "93"); sortedDic.Add("time", timestring()); sortedDic.Add("unid", "196"); sortedDic.Add("version", "4.5.2"); sortedDic.Add("vkey", ""); sortedDic.Add("vmid", ""); //FileStream fs1 = new FileStream("api.txt", FileMode.Open); //StreamReader m_streamReader1 = new StreamReader(fs1, UnicodeEncoding.GetEncoding("GB2312")); //string line; //if (!File.Exists("设置分ID.txt")) //{ // FileStream fs4 = new FileStream("设置分ID.txt", FileMode.Create, FileAccess.Write);//创建写入文件 // StreamWriter m_streamWrite2 = new StreamWriter(fs4, UnicodeEncoding.GetEncoding("GB2312")); //while ((line = m_streamReader1.ReadLine()) != null) //{ string sig = SnsSigCheck.MakeSig("post", "/v3/user/get_multi_info", sortedDic, "c9152e99a2d6487fb0bfd02adec3aa16&"); if (sortedDic.ContainsKey("sig") == false) { sortedDic.Add("sig", sig); } else { sortedDic["sig"] = sig; } item.URL = "http://app23006-1.qzoneapp.com/api/api.php"; item.Referer = ""; //item.Cookie = ""; item.Method = "post"; item.PostEncoding = System.Text.Encoding.UTF8; item.ContentType = "application/x-www-form-urlencoded; Charset=UTF-8"; item.Header.Add("X-TUNNEL-VERIFY", "2.0.0&2b7&buCTsYDX6SWA0YDg1uBUKjlUkyKmORhUY1SSOSKT4L3gk7cl4NbgGKbgveCTt7fRs DW4BumIrP4npL9gHOFhNtj 8yxk4X44L3gk7e3/Z7X4NbgzD9UP2vgveAKJbFZk1tO4NbgG6EbORimIiJUa8yhOWvMoaFUGKEYY4CTzKEYkhhUCjngveAK yVboFmTW07g1uA5a2uAgBuea1SmCqaAkioiYwobkhsbphtrCsyeKqFUnuC94CXq u7pgJ774Nbgt07psZ7gveAl6vpM3bee4Nbgk7GA1 klgOC94CXq v2e1 DW4GM/Y C94G2TkviAgNfg1uBJVNaOsNbra9azItahVNaOa C94G2TktGz4NbgOZKToYCTVCpjOcxUY2trkqE5zGsqa6ZrY6GTzJPMzMzgveAvgCWA4NbgoabMzMymOTnMzFRjYxih4L3gHvqenoDg1uA5KqbgveAeGSWA4Nbga AM&6FCpjg 7mAlUZdmZ4d1K5d7pKag="); //JsonStr = "api=" SnsSigCheck.JSONEncoding(DictionaryToJson(sortJson(sortedDic))); //item.Postdata = JsonStr; item.Postdata="api=" DictionaryToJson(sortJson(sortedDic)); HtmlResult = http.GetHtml(item); receiveFromCheck = HtmlResult.Html; textBox1.Text =textBox1.Text receiveFromCheck "\n"; //m_streamWrite2.WriteLine(receiveFromCheck); //Thread.Sleep(10 * 1000); //} m_streamReader.Close(); fs.Close(); //m_streamWrite2.Close(); //fs4.Close(); //} //else //{ // textBox2.Text = "删除相关文件"; //} } else { MessageBox.Show("网页错误"); } } } private void Form1_Load(object sender, EventArgs e) { } /// <summary> /// 字节数组生成图片 /// </summary> /// <param name="Bytes">字节数组</param> /// <returns>图片</returns> private Image byteArrayToImage(byte[] Bytes) { MemoryStream ms = new MemoryStream(Bytes); return Bitmap.FromStream(ms, true); } /// <summary> /// 删除cookie中的域名信息 /// </summary> /// <param name="Bytes">字符串</param> /// <returns>字符串</returns> public static string FormatCookie(string cookie) { string tmpcookie = string.Empty; foreach (string strtemp in Regex.Split(cookie, ",")) { Match match = Regex.Match(strtemp, @"^\w[^=] =[^;] "); if (match.Success) { tmpcookie = tmpcookie match.Value ";"; } } return tmpcookie; } //取中间字符 public string MidContent(string s, string s1, string s2) { int IndexofA = s.IndexOf(s1) s1.Length; int IndexofB = s.IndexOf(s2); return s.Substring(IndexofA , IndexofB - IndexofA ); } private void GetCheck() { //获取验证信息 //验证信息格式为:ptui_checkVC('0','!MIW','\x00\x00\x00\x00\x9a\x65\x0f\xd7') //其中分为三部分,第一个值0或1判断是否需要图片验证码 // 第二个值是默认验证码,若不需要图片验证码,就用此验证码来提交 // 第三部分是所使用的QQ号码的16进制形式 forCheckUrl = "http://check.ptlogin2.qq.com/check?uin=" uin.Text "&appid=15000101&r=" new Random().NextDouble(); item.URL = forCheckUrl; HtmlResult = http.GetHtml(item); item.Cookie = HtmlResult.Cookie; receiveFromCheck = HtmlResult.Html; //MessageBox.Show(receiveFromCheck); //打印获取的网页内容 //将验证码信息的三部分存入数组 if (receiveFromCheck != null) { checkCodePosition = receiveFromCheck.IndexOf("(") 1; checkCode = receiveFromCheck.Substring(checkCodePosition, receiveFromCheck.LastIndexOf(")") - checkCodePosition); checkNum = checkCode.Replace("'", "").Split(','); //验证码数组 if ("1".Equals(checkNum[0])) //判断是否需要图片验证码 { hasimage = 1; forImageUrl = "http://captcha.qq.com/getimage?aid=15000101&uin=" uin.Text "&cap_cd=" checkNum[1]; item.URL = forImageUrl; item.ResultType = ResultType.Byte; HtmlResult = http.GetHtml(item); item.Cookie = HtmlResult.Cookie; //将获取的图片验证码存入电脑 //System.Drawing.Image.FromStream(HtmlResult.ResultByte).Save(@"d:/code.jpg"); pictureBox1.Image = byteArrayToImage(HtmlResult.ResultByte); //将读取到的图片验证码输出到picture_box面板上 } else //若不需图片验证码,验证码就等于checkNum[1] { hasimage =0; item.Cookie = FormatCookie(item.Cookie); veriycode.Text = checkNum[1]; } } else { MessageBox.Show("检查验证码错误,网络有故障", "提示"); } } private void uin_Leave(object sender, EventArgs e) { GetCheck(); } private void button2_Click(object sender, EventArgs e) { Dictionary<string, object> sortedDic = new Dictionary<string, object>(); Dictionary<string, object> Dic = new Dictionary<string, object>(); sortedDic.Add("api", "65"); sortedDic.Add("langtype", "1"); sortedDic.Add("method", "Members.Create"); sortedDic.Add("mid", "0"); sortedDic.Add("mtkey", ""); sortedDic.Add("param", "{\"ANPSetting\":\"4\",\"APNSToken\":\"APA91bEsQTnR66YLBr2dzIzydJJtixolsRsv9XUbFhDkRJWpHp5I7-zfGl-zUbkIOvyjGWywhZmDWtUx9qfhBTgV22favyR-nHlOvIXQ6hZknrQxoxFPvgahVai2QZIAoyPC-SwH5TWbOtMZ_-LIWOU5Y3Qh3aQw6Q\",\"appid\":\"100029\",\"appkey\":\"c4b6eaa30ad2bd635a1154b34549b3d7\",\"mnick\":\"Lan998\",\"sitemid\":\"000000000000000000000000848CF5B5\",\"token\":\"1637E6D9BC1A21DA4C171A33391CE837\"}"); sortedDic.Add("protocol", "1"); sortedDic.Add("sid", "93"); sortedDic.Add("time", "1400763756"); sortedDic.Add("unid", "196"); sortedDic.Add("version", "4.6.2"); sortedDic.Add("vkey", ""); sortedDic.Add("vmid", ""); string aa = "{\"api\":\"65\",\"langtype\":\"1\",\"method\":\"Members.phoneContinuous\",\"mid\":\"6952837\",\"mtkey\":\"321ba46f8c765de454c1b819a657e77a\",\"param\":{\"test\":\"0\"},\"protocol\":\"1\",\"sid\":\"93\",\"sig\":\"43544efc717d99075612d72b844f427f\",\"time\":\"1400757961\",\"unid\":\"196\",\"version\":\"3.8\",\"vkey\":\"dfcb187a0a02795c739477cbd77e6520\",\"vmid\":\"6952837\"}"; Dic = JsonToDictionary(aa); string sig = SnsSigCheck.MakeSig("POST", textBox2.Text, sortedDic, "5158fd7156240bb70d02fd94&"); sortedDic.Add("sig", sig); string bb = (string)sortedDic["api"]; MessageBox.Show(sig); } } }
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)