C#實現smartQQ 掃碼登錄分析自動收發消息

       前幾天看到羣裏有個機器人大家各種玩,本人剛好也是做軟件,心想別人能做自己閒着沒事也做個試試。廢話不多說直接進入正題,第一次發帖寫的不好的地方大家可以一起探討。


      首先訪問smartQQ 的最新地址:http://web2.qq.com。
      騰訊可能考慮的安全方便所以現在只能用手機掃描二維碼再授權登錄。之前輸入用戶名密碼那種形式顯然是不行了。不多說還是直接抓包分析吧:
[img=http://img.bbs.csdn.net/upload/201603/29/1459241519_565250.jpg][/img]
本人是用的火狐來進行抓包分析,當然大家也可以用其他的瀏覽器,這個是看個人喜好了,抓包發現瀏覽器會不停的發送請求
https://ssl.ptlogin2.qq.com/ptqrlogin?webqq_type=10&remember_uin=1&login2qq=1&aid=501004106&u1=http://w.qq.com/proxy.html?login2qq=1&webqq_type=10&ptredirect=0&ptlang=2052&daid=164&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=0-2-252603&mibao_css=m_webqq&t=undefined&g=1&js_type=0&js_ver=10152&login_sig=&pt_randsalt=0
直接上代碼吧,本人是用C#寫的,大家也可以用其他語言做做,爲什麼用C#呢,第一當然是會用,第二嘛就是做cs界面比較方便。貼一些代碼供大家參考一下
這個是獲取二維碼的方法,好像也沒什麼好多說的,唯一需要注意的是必須將返回的cookie保留
public static void get_logincs()
        {
            string url = "https://ui.ptlogin2.qq.com/cgi-bin/login?daid=164&target=self&style=16&mibao_css=m_webqq&appid=501004106&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2Fw.qq.com%2Fproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20131024001";
            HttpWebResponse res = null;
            Encoding myEncoding = Encoding.UTF8;
            Stream st = null;
            StreamReader sr = null;
            HttpWebRequest req = null;
            try
            {
                req = (HttpWebRequest)WebRequest.Create(url);
                req.KeepAlive = true;
                req.Method = "GET";
                req.AllowAutoRedirect = true;
                req.CookieContainer = CookieContainers;
                req.ContentType = "application/x-www-form-urlencoded";
                req.UserAgent = IE7;
                req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                req.Timeout = 20000;
                req.Referer = "";
                if (!string.IsNullOrEmpty(""))
                {
                    req.Host = "";
                }
                req.Headers.Add("X-Requested-With", "XMLHttpRequest");
                if (!string.IsNullOrEmpty(""))
                {
                    req.Headers.Add("Origin", "");
                }
                
                System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =>
                {
                    return true;
                };
                if (req.GetResponse() != null)
                {
                    res = (HttpWebResponse)req.GetResponse();
                    st = res.GetResponseStream();
                    if (res.ContentEncoding.ToLower().Contains("gzip"))
                    {
                        st = new GZipStream(st, CompressionMode.Decompress);
                    }
                    sr = new StreamReader(st, myEncoding);
                    if (res.Cookies.Count > 0)
                    {
                        
                        addcookeis(res.Cookies);
                    }
                }
               
            }
            catch (WebException ex)
            {
                string error = string.Empty;
                if (ex.Response != null)
                {
                    res = (HttpWebResponse)ex.Response;
                    st = res.GetResponseStream();
                    sr = new StreamReader(st, myEncoding);
                    error = sr.ReadToEnd();
                }
               
            }


        }
這個是第一次登錄操作,也需要把返回的cookie保存:
public static Stream get_imgshow()
        {
            string url = "https://ssl.ptlogin2.qq.com/ptqrshow?appid=501004106&e=0&l=M&s=5&d=72&v=4&t=0.20737422284902096";
            //HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(url));
            HttpWebResponse res = null;
            Encoding myEncoding = Encoding.UTF8;
            Stream st = null;
            StreamReader sr = null;
            HttpWebRequest req = null;
            try
            {
                req = (HttpWebRequest)WebRequest.Create(url);
                req.KeepAlive = true;
                req.Method = "GET";
                req.AllowAutoRedirect = true;
                req.CookieContainer = CookieContainers;
                req.ContentType = "application/x-www-form-urlencoded";
                req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
                req.Accept = "*/*";
                req.Timeout = 20000;
                req.Headers.Add("X-HttpWatch-RID", " 46990-10314");
                req.Headers.Add("Accept-Language", "zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3");
                req.Referer = "https://ui.ptlogin2.qq.com/cgi-bin/login?daid=164&target=self&style=16&mibao_css=m_webqq&appid=501004106&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2Fw.qq.com%2Fproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20131024001";
                if (!string.IsNullOrEmpty(""))
                {
                    req.Host = "";
                }
                req.Headers.Add("X-Requested-With", "XMLHttpRequest");
                if (!string.IsNullOrEmpty(""))
                {
                    req.Headers.Add("Origin", "");
                }
                req.CookieContainer.Add(qq2016.c1);
                //System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =>
                //{
                //    return true;
                //};
                if (req.GetResponse() != null)
                {
                    res = (HttpWebResponse)req.GetResponse();
                    st = res.GetResponseStream();
                    //if (res.ContentEncoding.ToLower().Contains("gzip"))
                    //{
                    //    st = new GZipStream(st, CompressionMode.Decompress);
                    //}
                    sr = new StreamReader(st, myEncoding);
                    if (res.Cookies.Count > 0)
                    {
                        addcookeis(res.Cookies);
                    }
                }
                return st;


            }
            catch (WebException ex)
            {
                string error = string.Empty;
                if (ex.Response != null)
                {
                    res = (HttpWebResponse)ex.Response;
                    st = res.GetResponseStream();
                    sr = new StreamReader(st, myEncoding);
                    error = sr.ReadToEnd();
                }
                return st;


            }


        }
未驗證返回值是ptuiCB('66','0','','0','二維碼未失效。(1974472612)', '');
授權後返回
ptuiCB('0','0','http://ptlogin4.web2.qq.com/check_sig?pttype=1&uin=3259629949&service=ptqrlogin&nodirect=0&ptsigx=09dfc7cf023d1d3d2e296372461715bde0bf526018aeb13620ccca5db93af0e11a657550d10fb856756b2ddfae36c2b84e5d4652178b2f49619f26cadd96fce1&s_url=http%3A%2F%2Fw.qq.com%2Fproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&f_url=&ptlang=2052&ptredirect=100&aid=501004106&daid=164&j_later=0&low_login_hour=0&regmaster=0&pt_login_type=3&pt_aid=0&pt_aaid=16&pt_light=0&pt_3rd_aid=0','0','登錄成功!', '11111');
這樣就完成了第一次get登錄。
今天先到這裏吧,改天再上post登錄的分析
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章