/// <summary> /// 通过QQ号得到验证码加密串 /// </summary> /// <param name="strQQ"></param> /// <returns></returns> private string Login(string strQQ) { //变量声明 string strRequest = null; string strContent = null; string resultString = null; string vc_type = null; string[] arrResult = { }; this.strQQ = strQQ; HTTPproc.Encoding = System.Text.Encoding.UTF8; strRequest = "http://ptlogin2.qq.com/check?uin=" + strQQ + "&appid=1002101&r=" + rnd.GetRandStr(13); strContent = HTTPproc.GetHtml(strRequest); try { resultString = Regex.Match(strContent, @"'\d','.*'").Value.Replace("\'", "");//'0','!MLF' arrResult = resultString.Split(','); } catch (ArgumentException ex) { MessageBox.Show("没有获取到验证码正则出错,请检查!"); MessageBox.Show(ex.ToString()); } vc_type = arrResult[1].ToString(); return(vc_type); }
/// <summary> /// 通过城市名称读取天气预报ID /// </summary> /// <param name="strCity">城市名称</param> /// <returns>城市ID</returns> private string ReadWeatherID(string strCity) { string strResult = null; string strWeatherID = null; string resultString = null; RandStr rndNum = new RandStr(true, false, false, false); string strRequest = "http://toy.weather.com.cn/SearchBox/searchBox?callback=jsonp" + rndNum.GetRandStr(13) + "&_=" + rndNum.GetRandStr(13) + "&language=zh&keyword=" + strCity + ""; HTTPproc.Encoding = System.Text.Encoding.UTF8; strResult = HTTPproc.OpenRead(strRequest); try { resultString = Regex.Replace(strResult, @"jsonp\d{0,13}\(", "").Replace(");", ""); JObject o = JObject.Parse(resultString); JArray WeatherID = (JArray)o["i"]; strWeatherID = (string)WeatherID[0]["i"]; } catch (ArgumentException ex) { strWeatherID = "101120201"; } return(strWeatherID); }
public void Login(string strQQ, string strPwd) { //变量声明 string strMsg = null; string strReMsg = null; string strRequest = null; string strContent = null; string strCookies = null; string strSkey = null; string strPtwebqq = null; string strPost = null; string[] arrResult = { }; HTTPproc.Encoding = System.Text.Encoding.UTF8; this.strQQ = strQQ; strRequest = "http://ptlogin2.qq.com/check?uin=" + strQQ + "&appid=1002101&r=" + rnd.GetRandStr(13); strContent = HTTPproc.GetHtml(strRequest); try { this.resultString = Regex.Match(strContent, @"'\d','.*'").Value.Replace("\'", "");//'0','!MLF' arrResult = this.resultString.Split(','); } catch (ArgumentException ex) { Console.WriteLine("没有获取到验证码正则出错,请检查!"); Console.WriteLine(ex); } Console.WriteLine("获取的验证码:" + arrResult[1]); strCookies = HTTPproc.ResponseHeaders.GetValues(3).GetValue(0).ToString(); try { this.resultString = Regex.Replace(strCookies, ";.*", "").Replace("ptvfsession=", ""); } catch (ArgumentException ex) { // Syntax error in the regular expression } HTTPproc.CookieContainer.Add(new Uri("http://ptlogin2.qq.com"), new Cookie("ptvfsession", this.resultString)); strRequest = "http://ptlogin2.qq.com/login?u=" + strQQ + "&p=" + qqPwdEncrypt.Encrypt(strPwd, arrResult[1]) + "&verifycode=" + arrResult[1] + "&remember_uin=1&aid=1002101&u1=http%3A%2F%2Fweb.qq.com%2Fmain.shtml%3Fdirect__2&h=1&ptredirect=1&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert"; strContent = HTTPproc.GetHtml(strRequest); try { this.resultString = Regex.Match(strContent, @"'\d','.*'").Value.Replace("\'", "");//'3','0','','0','您输入的密码有误,请重试。' arrResult = this.resultString.Split(','); } catch (ArgumentException ex) { Console.WriteLine("没有获取到验证码正则出错,请检查!"); Console.WriteLine(ex); } #region 登录返回值判定 if (arrResult[0] == "0") //0:登录成功! { Console.WriteLine(arrResult[4]); strSkey = HTTPproc.ResponseHeaders.GetValues(1).GetValue(2).ToString(); //strPtcz = HTTPproc.ResponseHeaders.GetValues(1).GetValue(9).ToString(); for (int j = 0; j < HTTPproc.ResponseHeaders.GetValues(1).Length; j++) { if (HTTPproc.ResponseHeaders.GetValues(1).GetValue(j).ToString().IndexOf("ptwebqq") > -1) { strPtwebqq = HTTPproc.ResponseHeaders.GetValues(1).GetValue(j).ToString(); } } } else if (arrResult[0] == "1") //1:系统繁忙,请稍后重试。 { Console.WriteLine(arrResult[4]); } else if (arrResult[0] == "2") //2:已经过期的QQ号码。 { Console.WriteLine(arrResult[4]); } else if (arrResult[0] == "3") //3:您输入的密码有误,请重试。 { Console.WriteLine(arrResult[4]); } else if (arrResult[0] == "4") //4:您输入的验证码有误,请重试。 { Console.WriteLine(arrResult[4]); } else if (arrResult[0] == "5") //5:校验失败。 { Console.WriteLine(arrResult[4]); } else if (arrResult[0] == "6") //6:密码错误。如果您刚修改过密码, 请稍后再登录. { Console.WriteLine(arrResult[4]); } else if (arrResult[0] == "7") //7:您的输入有误, 请重试。 { Console.WriteLine(arrResult[4]); } else //8:您的IP输入错误的次数过多,请稍后再试。 { Console.WriteLine("未知错误!"); } Console.WriteLine(arrResult[1]); #endregion 登录返回值判定 strSkey = Regex.Replace(strSkey, ";.*", "").Replace("skey=", ""); strPtwebqq = Regex.Replace(strPtwebqq, ";.*", "").Replace("ptwebqq=", ""); strPost = this.strQQ + ";22;0;00000000;" + strSkey + ";" + strPtwebqq + ";0;"; strContent = HTTPproc.Post(this.strQQHost, strPost); Console.WriteLine(strContent); string[] arrKey = strContent.Split(';'); this.strKey = arrKey[4].ToString(); //读取用户分组 Console.WriteLine(GetUserGroup()); //读取好友列表 strPost = this.strQQ + ";06;2;" + this.strKey + ";" + this.strQQ + ";" + this.strQQ + ";5c;3;" + this.strKey + ";88;" + this.strQQ + ";67;4;" + this.strKey + ";03;1;" + this.strQQ + ";" + this.strQQ + ";58;5;" + this.strKey + ";0;" + this.strQQ + ";26;6;" + this.strKey + ";0;0;" + this.strQQ + ";3e;7;" + this.strKey + ";4;0;" + this.strQQ + ";65;8;" + this.strKey + ";02;" + this.strQQ + ";" + this.strQQ + ";1d;9;" + this.strKey + ";" + this.strQQ + ";00;10;" + this.strKey + ";"; strContent = HTTPproc.Post(this.strQQHost, strPost); Console.WriteLine(strContent); Run(); #region 老版消息循环 //string[] arrReMsg; //while (i < 100) //{ // Console.WriteLine("正在等待接收消息:{0}", i); // strContent = HTTPproc.Post(this.strQQHost, this.strQQ + ";00;" + this.i.ToString() + ";" + this.strKey + ";"); // arrReMsg = strContent.Split(';'); // if (arrReMsg.Length > 10) // { // if (arrReMsg[1].ToString() == "17") // { // //发送消息 // //this.i++; // strPost = this.strQQ + ";16;" + this.i.ToString() + ";" + this.strKey + ";" + arrReMsg[3].ToString() + ";0b;528;" + UrlEncode(arrReMsg[7].ToString(), "UTF-8") + ";0a00000010%E5%AE%8B%E4%BD%93;"; // strReMsg = HTTPproc.Post(this.strQQHost, strPost); // Console.WriteLine("发送消息:{0}", strReMsg); // //1307364337;16;119;165fad25;182536608;0b;528;%E4%BD%A0%E5%A5%BD;0a00000010%E5%AE%8B%E4%BD%93; // //this.i++; // strPost = this.strQQ + ";17;" + arrReMsg[2].ToString() + ";" + this.strKey + ";" + arrReMsg[3].ToString() + ";" + this.strQQ + ";" + arrReMsg[4].ToString() + ";1;" + arrReMsg[10].ToString() + ";"; // strMsg = HTTPproc.Post(this.strQQHost, strPost);//" + this.strQQ + ";00;" + this.i.ToString() + ";" + this.strKey + ";"); // // // Console.WriteLine("发送确认消息:{0}", strMsg); // } // } // Console.WriteLine(strContent); // this.i++; //} #endregion }