第二讲 检查二维码的失效状态
在开发者界面用可以看到很多ptqrlogin开头的 name
我要做的就是 模拟浏览器的操作,把它转换成我们自己的客户端。所以只要是浏览器里有的我们都要模拟。接下来判断二维码失效,两秒一次吧,弄一个Timer
smart 类
#region 第二讲检查二维码状态
private static System.Timers.Timer StatuTimer = new System.Timers.Timer();
public static void Login()
{
StatuTimer.AutoReset = true;
StatuTimer.Elapsed +=StatuTimer_Elapsed;
StatuTimer.Interval = 2000;
StatuTimer.Start();
}
public static string Login_err = "其他";
/// <summary>
/// 检查二维码状态
/// </summary>
public static void Login_GetStatu()
{
string dat;
dat = HTTP.Get(string.Format("https://ssl.ptlogin2.qq.com/ptqrlogin?ptqrtoken={0}&webqq_type=10&remember_uin=1&login2qq=1&aid=501004106&u1=https%3A%2F%2Fw.qq.com%2Fproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&ptredirect=0&ptlang=2052&daid=164&from_ui=1&pttype=1&dumy=&fp=loginerroralert&0-0-157510&mibao_css=m_webqq&t=undefined&g=1&js_type=0&js_ver=10184&login_sig=&pt_randsalt=3", ptqrtoken));
string[] temp = dat.Split('\'');
switch (temp[1])
{
case ("65"): //二维码失效
Login_err = "二维码失效";
break;
case ("66"): //等待扫描
Login_err = "等待扫描";
break;
case ("67"): //等待确认
Login_err = "等待确认";
break;
case ("0"): //已经确认
Login_err = "已经确认";
StatuTimer.Stop();
break;
default: break;
}
}
/// <summary>
/// 每两秒检查一次二维码状态
/// </summary>
private static void StatuTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Login_GetStatu();
}
#endregion
HTTP 类
/// <summary>
/// 带referer的http请求连接
/// </summary>
/// <param name="url"></param>
/// <param name="referer"></param>
/// <param name="timeout"></param>
/// <param name="encode"></param>
/// <param name="NoProxy"></param>
/// <returns></returns>
public static string Get(string url, string referer = "http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2", int timeout = 100000, Encoding encode = null, bool NoProxy = false)
{
string dat;
HttpWebResponse res = null;
HttpWebRequest req;
try
{
req = (HttpWebRequest)WebRequest.Create(url);
req.CookieContainer = cookies;
req.AllowAutoRedirect = false;
req.Timeout = timeout;
req.Referer = referer;
if (NoProxy)
req.Proxy = null;
req.UserAgent = "Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0) Gecko/20100101 Firefox/47.0";
res = (HttpWebResponse)req.GetResponse();
cookies.Add(res.Cookies);
}
catch (HttpException)
{
return "";
}
catch (WebException)
{
return "";
}
StreamReader reader;
reader = new StreamReader(res.GetResponseStream(), encode == null ? Encoding.UTF8 : encode);
dat = reader.ReadToEnd();
res.Close();
req.Abort();
return dat;
}