基本信息
源码名称:C# QQ空间登录代码下载
源码大小:0.13M
文件格式:.rar
开发语言:C#
更新时间:2015-05-10
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

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;
    }
}