基本信息
源码名称:C# webqq 登录 例子源码
源码大小:3.60M
文件格式:.zip
开发语言:C#
更新时间:2014-10-29
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
思路可借鉴,现已不能用,应该是网址变了,提示有病毒,不过没病毒 测试过了
思路可借鉴,现已不能用,应该是网址变了,提示有病毒,不过没病毒 测试过了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using TestQQ.com.my.util;
namespace TestQQ
{
public partial class FrmLogin : Form
{
public FrmLogin()
{
InitializeComponent();
}
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 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)
{
String qq = this.txt_qq.Text.Trim();
String url = "http://ptlogin2.qq.com/check?appid=1003903&uin=" qq "&r=" rd.NextDouble();
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);
}
}
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)
{
//登陆
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 = PassUtil.getQQPwd(pass, verifyCode);
String loginUrl = "http://ptlogin2.qq.com/login?u=" qq "&p=" md5pass "&verifycode=" verifyCode "&webqq_type=10&remember_uin=1&login2qq=0&aid=1003903&u1=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&h=1&ptredirect=0&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert";
//登陆
String loginResult= getHtml(loginUrl, "get",null);
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("登陆失败");
}
}
}
}