|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Collections;
苍海国际 www.258ch.com 更多精品源码分享
namespace webqq
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
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 ptwebqq = "";
private String psessionid = "";
private String vfwebqq = "";
private String skey = "";
private String clientid =new Random().Next(100000000)+"";
//默认需要输入验证码
private Boolean isVerify = false;
private void txt_pass_Click(object sender, EventArgs e)
{
}
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 btn_login_Click(object sender, EventArgs e)
{
}
/// <summary>
/// 你懂的
/// </summary>
/// <param name="buffer"> 你懂的</param>
/// <returns></returns>
public static string binl2hex(byte[] buffer)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < buffer.Length; i++)
{
builder.Append(buffer.ToString("x2"));
}
return builder.ToString();
}
/// <summary>
/// 你懂的
/// </summary>
/// <param name="input"> 你懂的</param>
/// <returns></returns>
public static string md5(string input)
{
byte[] buffer = MD5.Create().ComputeHash(Encoding.GetEncoding("ISO-8859-1").GetBytes(input));
return binl2hex(buffer);
}
/// <summary>
/// 你懂的
/// </summary>
/// <param name="passWord">QQ密码</param>
/// <returns></returns>
public static 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();
}
/// <summary>
/// 获取最新空间加密的方法
/// </summary>
/// <param name="qq">http://check.ptlogin2.qq.com/check?uin={0}&appid=15000101&r={1} 返回的第三个参数</param>
/// <param name="password">QQ密码</param>
/// <param name="verifycode">验证码</param>
/// <returns></returns>
public static 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 void txt_pass_TextChanged(object sender, EventArgs e)
{
}
private void txt_pass_Click_1(object sender, EventArgs e)
{
//
String qq = this.txt_qq.Text.Trim();
//String url = "http://ptlogin2.qq.com/check?appid=1003903&uin=" + qq + "&r=" + rd.NextDouble();
string url = "http://check.ptlogin2.qq.com/check?uin="+qq+"&appid=1003903&r=0.5058025715431";
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","");
}
}
private void button1_Click(object sender, EventArgs e)
{
//登陆
String qq = this.txt_qq.Text.Trim();
if (qq.Equals(""))
{
MessageBox.Show("请输入QQ号码!");
return;
}
String pass = this.txt_pass.Text.Trim();
if (pass.Equals(""))
{
MessageBox.Show("请输入QQ密码!");
return;
}
if (isVerify)
{
verifyCode = this.txt_code.Text.Trim();
if (verifyCode.Equals(""))
{
MessageBox.Show("请输入验证码!");
}
}
String md5pass = GetPassword(hex16, pass, verifyCode);
String loginUrl = "http://ptlogin2.qq.com/login?u=" + qq + "&p=" + md5pass + "&verifycode=" + verifyCode + "&webqq_type=Callme&remember_uin=1&login2qq=1&aid=1003903&u1=http%3A%2F%2Fweb.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&h=1&ptredirect=0&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=1-24-89939&mibao_css=m_webqq&g=1";
//登陆
String loginResult = getHtml(loginUrl, "get", null);
MessageBox.Show(loginResult);
int isLogin = loginResult.IndexOf("登录成功");
if (isLogin > 0)
{
// MessageBox.Show("登录成功");
/*
String cks = cookies.GetCookieHeader(new Uri(loginUrl));
this.ptwebqq = PassUtil.getPtWebqq(cks, "ptwebqq=");
this.skey = PassUtil.getMidStr(cks, "skey=");
String channelLoginUrl = this.host + "/channel/login2";
String postData = String.Format("r=%7B%22status%22%3A%22online%22%2C%22ptwebqq%22%3A%22{0}%22%2C%22passwd_sig%22%3A%22%22%2C%22clientid%22%3A%22{1}%22%2C%22psessionid%22%3Anull%7D&clientid={2}&psessionid=null", this.ptwebqq, this.clientid, this.clientid);
String login3 = getHtml(channelLoginUrl, "post", postData);
//得到vfwebqq和psessionid
this.vfwebqq = PassUtil.getVfWebqqOrPsessionid(login3, "vfwebqq", "psessionid");
this.psessionid = PassUtil.getVfWebqqOrPsessionid(login3, "psessionid", "user_state");
*
*
//打开主窗体
*/
}
else
{
MessageBox.Show("登陆失败");
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
|
|