实例介绍
【实例简介】QQ空间登录代码,提供的是一个思路,测试了下 能获取验证码,但是总提示验证码失败
【实例截图】
【核心代码】
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; namespace QZoneLogin { public partial class LoginForm : Form { public int hasimage = 0; //表示是否含有验证码图片 private string QQ = null; private string password = null; private string verifycode = null; private RetData outcomeFromLogin = new RetData(); private RetData outcomeFromCheck = new RetData(); public LoginForm() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { HttpHelper helper1 = new HttpHelper(); PasswordHelper helper2 = new PasswordHelper(); if (QQ_acount_box.Text == null) { MessageBox.Show("账号不能为空"); } if (QQ_pass_box.Text == null) { MessageBox.Show("密码不能为空"); } if (Vericode_box.Text == null) { MessageBox.Show("验证码不能为空"); } string pass = helper2.GetPassword(this.QQ, this.password, Vericode_box.Text); String forLoginUrl = "http://ptlogin2.qq.com/login?u=" this.QQ "&verifycode=" Vericode_box.Text "&p=" pass "&aid=549000912&u1=http%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=3-21-1397619935139"; outcomeFromLogin = helper1.GetHtml(forLoginUrl, outcomeFromCheck.cookie); String revFromLogin = outcomeFromLogin.str; Return_box.Text = revFromLogin; //打印登录后返回信息 //至此登录成功 } private void QQ_acount_box_TextChanged(object sender, EventArgs e) { this.QQ = QQ_acount_box.Text; } private void QQ_pass_box_TextChanged(object sender, EventArgs e) { this.password = QQ_pass_box.Text; } private void Return_box_TextChanged(object sender, EventArgs e) { } private void Vericode_box_TextChanged(object sender, EventArgs e) { this.verifycode = Vericode_box.Text; } private void QQ_acount_box_Leave_1(object sender, EventArgs e) //当焦点(光标)离开QQ账号输入框是触发此函数,获取验证码 { GetCheck(); } private void LoginForm_Activated(object sender, EventArgs e) { QQ_acount_box.Focus(); } private void pictureBox1_DoubleClick(object sender, EventArgs e) //双击时刷新验证码 { GetCheck(); } private void GetCheck() { //获取验证信息 //验证信息格式为:ptui_checkVC('0','!MIW','\x00\x00\x00\x00\x9a\x65\x0f\xd7') //其中分为三部分,第一个值0或1判断是否需要图片验证码 // 第二个值是默认验证码,若不需要图片验证码,就用此验证码来提交 // 第三部分是所使用的QQ号码的16进制形式 String forCheckUrl = "http://check.ptlogin2.qq.com/check?uin=" this.QQ "&appid=549000912&r=0.10299430438317358"; CookieContainer cookieNull = new CookieContainer(); HttpHelper helper = new HttpHelper(); String receiveFromCheck; outcomeFromCheck = helper.GetHtml(forCheckUrl, cookieNull); receiveFromCheck = outcomeFromCheck.str; //MessageBox.Show(receiveFromCheck); //打印获取的网页内容 //将验证码信息的三部分存入数组 int checkCodePosition = receiveFromCheck.IndexOf("(") 1; String checkCode = receiveFromCheck.Substring(checkCodePosition, receiveFromCheck.LastIndexOf(")") - checkCodePosition); String[] checkNum = checkCode.Replace("'", "").Split(','); //验证码数组 if ("1".Equals(checkNum[0])) //判断是否需要图片验证码 { hasimage = 1; String forImageUrl = "http://captcha.qq.com/getimage?aid=549000912&uin=" QQ "&cap_cd=" checkNum[1]; Stream receiveStream = helper.GetStream(forImageUrl, outcomeFromCheck.cookie); //将获取的图片验证码存入电脑 //System.Drawing.Image.FromStream(receiveStream).Save(@"d:/code.jpg"); Image img = Image.FromStream(receiveStream); pictureBox1.Image = img; //将读取到的图片验证码输出到picture_box面板上 } else //若不需图片验证码,验证码就等于checkNum[1] { hasimage = 0; Vericode_box.Text = checkNum[1]; } } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) //当鼠标在有图片显示的picturebox上移动时提醒可刷新验证码 { if (hasimage==1) { toolTip1.SetToolTip(pictureBox1, "双击可以刷新验证码"); } } } public struct RetData //网页请求返回对象 { public string str; public CookieContainer cookie; } }
标签: QQ空间登录代码
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论