在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# webqq 登录 例子源码

C# webqq 登录 例子源码

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:3.60M
  • 下载次数:36
  • 浏览次数:636
  • 发布时间:2014-10-29
  • 实例类别:C#语言基础
  • 发 布 人:xxkxef
  • 文件格式:.zip
  • 所需积分:2
 相关标签: WebQQ

实例介绍

【实例简介】 思路可借鉴,现已不能用,应该是网址变了,提示有病毒,不过没病毒 测试过了

【实例截图】

【核心代码】


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("登陆失败");
            }
              

        }

    }
}


标签: WebQQ

实例下载地址

C# webqq 登录 例子源码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警