http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 217745|回复: 512

[例子] HttpHelper模拟登录腾讯朋友!求精

  [复制链接]
发表于 2013-4-18 13:31:18 | 显示全部楼层 |阅读模式
本帖最后由 幻雪丶逆时光 于 2015-2-4 17:12 编辑

因为前几个月腾讯的登录算法发生更改以至于 之前用的算法 登入失败!!(旧算法---MD5(MD5(密码)+验证码))


貌似在3月份左右? 或者更前? 这不不是重点,腾讯的 算法 更新为 UFXTQ%[QW43GN_ZXMRTAJIH.jpg

这个js 在会用工具 的都可以查看到. 这里不做特别说明

下面 是介绍 飞哥 的HttpHelper 来post 登录腾讯 取得 cookic
---------------------------------------------------------------------------------我是分割线--------------------------------
首先得获取 验证码. 获取验证码必须附上 需要登陆的QQ号 qqName .取出 返回的cookie 是必须的 后面回使用到

(当然 腾讯也支持 自动推送验证码 一般格式是 <!XXX> 这个不需要输入 验证码 登录 也不再讲解范围)
[C#] 纯文本查看 复制代码
/// <summary>
        /// 获取图片
        /// </summary>
        public Image Verify(string qqName, out string cookie)
        {
            item = new HttpItem()
            {
                URL = "http://captcha.pengyou.com/getimage?&uin=" + qqName + "&aid=15004601&0.11248807175794862",
                Method = "GET",
                Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*",
                Encoding = "utf-8",
                ContentType = "application/x-www-form-urlencoded",
                UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MyIE2; Alexa Toolbar; mxie; .NET CLR 1.1.4322)",
                ResultType  = ResultType.Byte
            };
            HttpResult result = http.GetHtml(item);
            cookie = result.Cookie;
            return byteArrayToImage(result.ResultByte);//得到验证图片
            
        }


下面进行POST 服务器 string cookie 这个参数 是刚才 得到的 验证码的参数


[C#] 纯文本查看 复制代码
 public string Login(string qqName, string Password, string Verify,ref string cookie)
        {
            string str = string.Empty;
            str += "u=" + qqName;
            str += "&p=" + QQencryption.MD5_QQ_2_Encrypt(long.Parse(qqName),Password, Verify);
            str += "&verifycode=" + Verify;
            str += "&css=http://imgcache.qq.com/ptcss/b2/qzone/15000101/style.css";
            str += "&mibao_css=m_qzone";
            str += "&aid=15004601";
            str += "&u1=" + System.Web.HttpUtility.UrlEncode("http://www.pengyou.com/index.php?mod=login2&act=qqlogin");
            str += "&ptredirect=1";
            str += "&h=1";
            str += "&from_ui=1";

            str += "&fp=loginerroralert";
            str += "&ptlang=2052";
            
            str += "&dumy=";
            //str += "&login_sig=o2uGOggzs1ppeZD44BwmcEUGyAeC1ZwxDSY-7ftMXgAK10nFbk1cdPiOWBysOlzl";
            str += "&action=1-8-14390";
            str += "&g=1";
            str += "&t=1";

            item = new HttpItem()
            {
                URL = "http://ptlogin2.pengyou.com/login?"+str,
                Method = "GET",
                Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*",
                Encoding = "utf-8",
                ContentType = "application/x-www-form-urlencoded",
                UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MyIE2; Alexa Toolbar; mxie; .NET CLR 1.1.4322)",
                Cookie = cookie
            };
            item.Headersadd("Accept-Encoding", "gzip, deflate");
            item.Headersadd("Accept-Language", "zh-CN");
            HttpResult result = http.GetHtml(item);
            cookie = result.Cookie;
            return result.Html;
        }


----------------------------------------------------------------------------------还是分割线

腾讯服务器应该返回

2R)Z6ECYO%GY@QOL@NRH{PL.jpg


这样 只要 使用 第二次POST 的cookie 去GET 腾讯的网页  便可以了

另外 向飞哥申精!!!!
_________________________________________________________________
以下是DEMO
游客,如果您要查看本帖隐藏内容请回复


补充内容 (2013-6-21 22:41):
伪验证码腾讯推送,达到过验证码效果
http://www.sufeinet.com/thread-3818-1-1.html


_____________________________________
2015.02.04 GET"是否需要验证码" 腾讯已经更新有需要的自己抓包修改

本帖被以下淘专辑推荐:



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2013-4-18 13:43:12 | 显示全部楼层
以下是密码加密算法
[C#] 纯文本查看 复制代码
public static class QQencryption
    {
        public static string MD5_QQ_2_Encrypt(long uin, string password, string verifyCode)
        {

            ByteBuffer buffer = new ByteBuffer();
            buffer.Put(MD5_GetBytes(password));
            //buffer.Put(Encoding.UTF8.GetBytes(password));
            buffer.PutInt(0);
            buffer.PutInt((uint)uin);
            byte[] bytes = buffer.ToByteArray();
            string md5_1 = MD5_Encrypt(bytes);//将混合后的字节流进行一次md5加密
            string result = MD5_Encrypt(md5_1 + verifyCode.ToUpper());//再用加密后的结果与大写的验证码一起加密一次
            return result;

        }

        /// <summary>
        /// 获取文本的md5字节流
        /// </summary>
        /// <param name="md5_str">需要加密成Md5d的文本</param>
        /// <returns></returns>
        private static byte[] MD5_GetBytes(string md5_str)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5CryptoServiceProvider.Create();
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(md5_str);
            return md5.ComputeHash(bytes);


        }

        /// <summary>
        /// 将字节流加密
        /// </summary>
        /// <param name="md5_bytes">需要加密的字节流</param>
        /// <returns></returns>
        private static string MD5_Encrypt(byte[] md5_bytes)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5CryptoServiceProvider.Create();

            byte[] bytes1 = md5.ComputeHash(md5_bytes);
            System.Text.StringBuilder stringBuilder = new StringBuilder();
            foreach (var item in bytes1)
            {
                stringBuilder.Append(item.ToString("x").PadLeft(2, '0'));
            }
            return stringBuilder.ToString().ToUpper();

        }

        /// <summary>
        /// 一次md5加密
        ///http://www.cnblogs.com/uu102
        /// </summary>
        /// <param name="md5_str">需要加密的文本</param>
        /// <returns></returns>
        public static string MD5_Encrypt(string md5_str)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5CryptoServiceProvider.Create();
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(md5_str);
            byte[] bytes1 = md5.ComputeHash(bytes);

            System.Text.StringBuilder stringBuilder = new StringBuilder();
            foreach (var item in bytes1)
            {
                stringBuilder.Append(item.ToString("x").PadLeft(2, '0'));
            }
            return stringBuilder.ToString().ToUpper();
        }
    }





[C#] 纯文本查看 复制代码
    public class ByteBuffer
    {
        private byte[] _buffer;
        /// <summary>
        /// 获取同后备存储区连接的基础流
        /// </summary>
        public Stream BaseStream;

        /// <summary>
        /// 构造函数
        /// </summary>
        public ByteBuffer()
        {
            this.BaseStream = new MemoryStream();
            this._buffer = new byte[0x10];
        }

        /// <summary>
        /// 设置当前流中的位置
        /// </summary>
        /// <param name="offset">相对于origin参数字节偏移量</param>
        /// <param name="origin">System.IO.SeekOrigin类型值,指示用于获取新位置的参考点</param>
        /// <returns></returns>
        public virtual long Seek(int offset, SeekOrigin origin)
        {
            return this.BaseStream.Seek((long)offset, origin);
        }



        /// <summary>
        /// 检测是否还有可用字节
        /// </summary>
        /// <returns></returns>
        public bool Peek()
        {
            return BaseStream.Position >= BaseStream.Length ? false : true;
        }

        /// <summary>
        /// 将整个流内容写入字节数组,而与 Position 属性无关。
        /// </summary>
        /// <returns></returns>
        public byte[] ToByteArray()
        {
            long org = BaseStream.Position;
            BaseStream.Position = 0;
            byte[] ret = new byte[BaseStream.Length];
            BaseStream.Read(ret, 0, ret.Length);
            BaseStream.Position = org;
            return ret;
        }


        #region "写流方法"
        /// <summary>
        /// 压入一个布尔值,并将流中当前位置提升1
        /// </summary>
        /// <param name="value"></param>
        public void Put(bool value)
        {
            this._buffer[0] = value ? (byte)1 : (byte)0;
            this.BaseStream.Write(_buffer, 0, 1);
        }

        /// <summary>
        /// 压入一个Byte,并将流中当前位置提升1
        /// </summary>
        /// <param name="value"></param>
        public void Put(Byte value)
        {
            this.BaseStream.WriteByte(value);
        }
        /// <summary>
        /// 压入Byte数组,并将流中当前位置提升数组长度
        /// </summary>
        /// <param name="value">字节数组</param>
        public void Put(Byte[] value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            this.BaseStream.Write(value, 0, value.Length);
        }
        /// <summary>
        /// Puts the int.
        /// </summary>
        /// <param name="value">The value.</param>
        public void PutInt(int value)
        {
            PutInt((uint)value);
        }
        /// <summary>
        /// 压入一个int,并将流中当前位置提升4
        /// </summary>
        /// <param name="value"></param>
        public void PutInt(uint value)
        {
            this._buffer[0] = (byte)(value >> 0x18);
            this._buffer[1] = (byte)(value >> 0x10);
            this._buffer[2] = (byte)(value >> 8);
            this._buffer[3] = (byte)value;
            this.BaseStream.Write(this._buffer, 0, 4);
        }
        /// <summary>
        /// Puts the int.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="value">The value.</param>
        public void PutInt(int index, uint value)
        {
            int pos = (int)this.BaseStream.Position;
            Seek(index, SeekOrigin.Begin);
            PutInt(value);
            Seek(pos, SeekOrigin.Begin);
        }

        #endregion

        #region "读流方法"

        /// <summary>
        /// 读取Byte值,并将流中当前位置提升1
        /// </summary>
        /// <returns></returns>
        public byte Get()
        {
            return (byte)BaseStream.ReadByte();
        }

        #endregion

    }
发表于 2023-3-10 17:25:42 | 显示全部楼层
2222222222222
发表于 2023-1-31 15:54:51 | 显示全部楼层
强烈支持楼主ing……
发表于 2021-6-21 22:43:23 | 显示全部楼层
本主题由 站长苏飞 于 2020-9-21 18:31 删除回本主题由 站长苏飞 于 2020-9-21 18:31 删除回本主题由 站长苏飞 于 2020-9-21 18:31 删除回
发表于 2020-2-3 14:31:19 | 显示全部楼层
强烈支持楼主ing……
发表于 2020-1-6 14:07:49 | 显示全部楼层

真是难得给力的帖子啊,强烈支持楼主。
发表于 2019-12-13 11:56:36 | 显示全部楼层
看看
回复

使用道具 举报

发表于 2019-6-24 16:48:22 | 显示全部楼层
学习一下是如何打开网站登录的
发表于 2019-6-10 22:26:25 | 显示全部楼层
棒棒哒
回复

使用道具 举报

发表于 2019-1-15 14:36:47 | 显示全部楼层
强烈支持楼主ing……
发表于 2019-1-4 09:23:49 | 显示全部楼层
真棒 学习到了~!
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-3-28 18:46

© 2014-2021

快速回复 返回顶部 返回列表