博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QQ登陆篇
阅读量:6931 次
发布时间:2019-06-27

本文共 3475 字,大约阅读时间需要 11 分钟。

   前段时间想做个QQ的一个辅助工具,需要登陆QQ,从网上搜索了些资料,自己进行了实践和改造,可以成功登陆qq

如图:

 1、获取登陆验证码,如下,如果获取的验证码为!开头,就可以不用获取图片验证码,否则需要获取图片验证码,地址为:},vc_type为上次获取的验证码,注意:获取这些信息时,必须返回Cookie

 1         
public 
static User getVerifyCodeImg(
string qq)
 2         {
 3             HTTPModel hTTPModel = 
new HTTPModel(
string.Format(
"
http://ptlogin2.qq.com/check?uin={0}&appid=15000101
", qq));
 4             WebHTTPUtil.sendHTTP(hTTPModel);
 5             CookieCollection cookie = hTTPModel.ReturnCookies;
 6             
string value = WebHTTPUtil.GetValue(hTTPModel.ReturnHtml, 
"
','
"
"
'
");
 7             Console.WriteLine(
"
yzm:
" + value);
 8             User user = 
new User();
 9             
if (value.Contains(
"
!
"))
10             {
11                 user.VerifyCode = value;
12             }
13             
else
14             {
15                 
string imgUrl = 
string.Format(
"
http://captcha.qq.com/getimage?aid=1003903&&uin={0}&vc_type={1}
"
qq, value);
16                 user.VerifyCodeUrl = imgUrl;
17             }
18             user.QQNum = qq;
19             user.Cookie = cookie;
20             
return user;
21 
22         }

2、获取验证码图片,设置图片控件的image属性this.verifyImg.Image = WebHTTPUtil.byteArrayToImage(imgUrl, ref cookie);

ExpandedBlockStart.gif
View Code
 1         
public 
static Image byteArrayToImage(
string url, 
ref CookieCollection cookie)
 2         {
 3             Uri requestUri = 
new Uri(url);
 4             WebRequest webRequest = WebRequest.Create(requestUri);
 5             Image result;
 6             
using (WebResponse response = webRequest.GetResponse())
 7             {
 8                 
if (!
string.IsNullOrEmpty(response.Headers[HttpResponseHeader.SetCookie]))
 9                 {
10                     CookieContainer cookieContainer = 
new CookieContainer();
11                     cookie = 
new CookieCollection();
12                     cookieContainer.SetCookies(webRequest.RequestUri, response.Headers[HttpResponseHeader.SetCookie]);
13                     cookie.Add(cookieContainer.GetCookies(webRequest.RequestUri));
14                 }
15                 
using (Stream responseStream = response.GetResponseStream())
16                 {
17                     result = Image.FromStream(responseStream);
18                 }
19             }
20             
return result;
21         }

3.对QQ密码和验证码进行散列,使用MD5

 

        
public 
static 
string binl2hex(
byte[] buffer)
        {
            StringBuilder stringBuilder = 
new StringBuilder();
            
for (
int i = 
0; i < buffer.Length; i++)
            {
                stringBuilder.Append(buffer[i].ToString(
"
x2
"));
            }
            
return stringBuilder.ToString();
        }
        
public 
static 
string md5_3(
string input)
        {
            MD5 mD = MD5.Create();
            
byte[] buffer = mD.ComputeHash(Encoding.Default.GetBytes(input));
            buffer = mD.ComputeHash(buffer);
            buffer = mD.ComputeHash(buffer);
            
return WebHTTPUtil.binl2hex(buffer);
        }
        
public 
static 
string md5(
string input)
        {
            
byte[] buffer = MD5.Create().ComputeHash(Encoding.Default.GetBytes(input));
            
return WebHTTPUtil.binl2hex(buffer);
        }        
ExpandedBlockStart.gif
View Code
 1         
public 
static User LoginQZone(
string qq, 
string pwd, 
string verifyCode, CookieCollection cookie, User u)
 2         {
 3             
//
object password = WebHTTPUtil.GetPassword(pwd, verifyCode);
 4 
            System.Security.Cryptography.MD5 md5 = 
new System.Security.Cryptography.MD5CryptoServiceProvider();
 5             
string QQPwd = Md5(Md5_3(pwd) + verifyCode.ToUpper());
 6             
string loginUrl = 
string.Format(
"
http://ptlogin2.qq.com/login?u={0}&p={1}&verifycode={2}&aid=15000101&u1=http%3A%2F%2Fimgcache.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&h=1&ptredirect=1&ptlang=2052&from_ui=1&dumy=&fp=loginerroralert
", qq, QQPwd, verifyCode);
 7             HTTPModel hTTPModel = 
new HTTPModel(loginUrl);
 8             hTTPModel.Encoding = Encoding.UTF8;
 9             hTTPModel.PostCookies = cookie;
10             WebHTTPUtil.sendHTTP(hTTPModel);
11             User result;
12             Console.WriteLine(QQPwd + 
"
  
" + verifyCode);
13             Console.WriteLine(loginUrl);
14             Console.WriteLine(hTTPModel.ReturnHtml);
15 }

当打印出如下,代表登陆成功

ptuiCB('0','0','http://imgcache.qq.com/qzone/v5/loginsucc.html?para=izone','1','登录成功!', 'heavy');

第一步QQ登陆完成

 

 

转载于:https://www.cnblogs.com/wasp520/archive/2012/04/07/2436659.html

你可能感兴趣的文章
函数传递一维数组
查看>>
WebComponent魔法堂:深究Custom Element 之 从过去看现在
查看>>
Picard 法求方程根
查看>>
c语言中有bool型变量吗?
查看>>
Null值的使用
查看>>
《程序设计与数据结构》 课程教学
查看>>
注册asp.net
查看>>
java.net.ProtocolException: Exceeded stated content-length of: '13824' bytes
查看>>
详解Spring事件驱动模型
查看>>
内存分配有哪些策略
查看>>
WebView与JS的几种交互
查看>>
ffmpeg去logo<转>
查看>>
下载Tomcat时Tomcat网站上的core和deployer的区别
查看>>
imx6 关闭调试串口
查看>>
easyUi datagrid 返回时间格式化操作
查看>>
redis.conf配置详细翻译解析
查看>>
Linux Nano命令
查看>>
线程高级应用-心得4-java5线程并发库介绍,及新技术案例分析
查看>>
linux 弹出光驱失败
查看>>
grep用法详解:grep与正则表达式【转】
查看>>