|
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 DotNet.Utilities;
using System.Threading;
namespace Baidu_login
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Thread Login;
private void Form1_Load(object sender, EventArgs e)
{
}
public static string GetCookie()
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "www.baidu.com",
Method = "get",
};
string html = http.GetHtml(item);
string cookie = item.Cookie;
return cookie;
}
public static string GetToken(string cookie)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "https://passport.baidu.com/v2/api/?getapi&tpl=mn&apiver=v3&tt=1389498197148&class=login&logintype=dialogLogin&callback=bd__cbs__uchygg",
Cookie = cookie,
Method = "get",
};
string html = http.GetHtml(item);
//MessageBox.Show(html);
int i = html.IndexOf("token\" : \"", 1);
string token = html.Substring(i, 42);
token = token.Replace("token\" : \"", "");
return token;
//return "";
}
public static void Baidu_Login()
{
string cookie = GetCookie();
string token = GetToken(cookie);
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "https://passport.baidu.com/v2/api/?login",
Cookie = cookie,
Method = "POST",
Postdata = "staticpage=http%3A%2F%2Fwww.baidu.com%2Fcache%2Fuser%2Fhtml%2Fv3Jump.html&charset=utf-8&token=" + token + "&tpl=mn&apiver=v3&tt=1389498223980&codestring=&safeflg=0&u=http%3A%2F%2Fwww.baidu.com%2F&isPhone=false&quick_user=0&loginmerge=true&logintype=dialogLogin&splogin=rate&username=Linda%E7%9A%84%E5%A4%A9%E4%BD%BF&password=shanzhu&verifycode=&mem_pass=on&ppui_logintime=26832&callback=parent.bd__pcbs__fhf2px",
Referer = "http://www.baidu.com/",
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
};
string html = http.GetHtml(item);
if (html.Contains("err_no=400032") || html.Contains("err_no=0"))
{
MessageBox.Show("登录成功!");
}
else
{
MessageBox.Show("登录失败!");
}
}
private void button1_Click(object sender, EventArgs e)
{
Login = new Thread(Baidu_Login);
Login.Start();
}
}
}
|
|