C#模拟百度登录并到指定网站评论回帖(三)
2018-06-18 02:31:05来源:未知 阅读 ()
上次说到怎么获取BAIDUID,这个相信很多人都能够拿到就不多说了,今天一连说两个,获取token和raskey
private Regex _regex = new Regex(@"\{.*\}", RegexOptions.IgnoreCase);
/// <summary>
/// 根据BAIDUID获取token
/// </summary>
public string GetToken()
{
HttpCookie cookie = new HttpCookie("BDRCVFR[gltLrB7qNCt]");
cookie.Value = "mk3SLVN4HKm";
cookie.Expires = DateTime.Now.AddDays(1);
string url_getToken = string.Format("https://passport.baidu.com/v2/api/?getapi&tpl=zongheng&apiver=v3&tt={0}&class=login&gid=0743012-DD22-4632-B84E-B054B933DDA0&logintype=basicLogin&callback=bd__cbs__xjugf7", Utility.GetTimeStamp());
string token_get = helper.GetPageResponse_Get(url_getToken, Utility.UrlDecode("http://passport.zongheng.com/?location=http%3A%2F%2Fwww.zongheng.com%2F"), "*/*");
if (_regex.IsMatch(token_get))
token_get = _regex.Match(token_get).Value;
var resultToken = JsonConvert.DeserializeObject<ResultToken>(token_get);
if (string.IsNullOrEmpty(resultToken.Data.Token))
{
ShowLog("Parameter-:获取token=" + resultToken.Data.Token + "失败\n");
return null;
}
return resultToken.Data.Token;
}
//获取raskey
public string GetRasKey(string token)
{
string url_RasKey = string.Format("https://passport.baidu.com/v2/getpublickey?token={0}&tpl=zongheng&apiver=v3&tt={1}&gid=399423B-A0F5-42A0-B07F-CC5290F8F95D&callback=bd__cbs__xjugf7", token, Utility.GetTimeStamp());
string publicKey = helper.GetPageResponse_Get(url_RasKey, Utility.UrlDecode("http://passport.zongheng.com/?location=http%3A%2F%2Fwww.zongheng.com%2F"), "*/*");
//获取raskey
if (_regex.IsMatch(publicKey))
publicKey = _regex.Match(publicKey).Value;
var result_publicKey = JsonConvert.DeserializeObject<PublicRsaKey>(publicKey);
var rsakey = result_publicKey.Key;
//将密码加密
var pemToXml = RsaHelper.PemToXml(result_publicKey.Pubkey);
pwd = RsaHelper.RSAEncrypt(pemToXml, pwd);
//日志
if (!string.IsNullOrEmpty(rsakey))
return rsakey;
ShowLog("Parameter-:获取publickey=" + result_publicKey.Pubkey + "失败!");
ShowLog("Parameter-:获取raskey=" + rsakey + "失败!");
return null;
}/// <summary>
/// 登录实现
/// </summary>
public LoginStatus Login(string verifycode, string codestring, string token, string raskey, int userIndex)
{
string loginresult = "";
string url_Post = "https://passport.baidu.com/v2/api/?login";
long tt= Utility.GetTimeStamp();
string postData = string.Format("verifycode={0}&username={1}&u=http://zongheng.baidu.com/sendbduss.do?source=0&location=http%3A%2F%2Fwww.zongheng.com%2F&_t={2}&tt={3}&tpl=zongheng&token={4}&staticpage=http://passport.zongheng.com/v3Jump.html&safeflg=0&rsakey={5}&quick_user=0&ppui_logintime=20266&password={6}&mem_pass=on&logLoginType=pc_loginBasic&logintype=basicLogin&loginmerge=true&isPhone=false&gid=0743012-DD22-4632-B84E-B054B933DDA0&detect=1&crypttype=12&codestring={7}&charset=utf-8&callback=parent.bd__pcbs__ok0875&apiver=v3", verifycode, HttpUtility.UrlEncode(userName), tt,tt, HttpUtility.UrlEncode(token), HttpUtility.UrlEncode(raskey), HttpUtility.UrlEncode(pwd), codestring);
loginresult =helper.GetPageResponse_Post(url_Post, postData, Utility.UrlDecode("http://passport.zongheng.com/?location=http%3A%2F%2Fwww.zongheng.com%2F"));
//分析loginresult
string err = @"(?<=err_no=)[^&]+?(?=&)";
Match regx = Regex.Match(loginresult, err);
string codestr = "(?<=codeString=)[^&]+?(?=&)";
string codetype = "(?<=vcodetype=)[^&]+?(?=&)";
Match regx2 = Regex.Match(loginresult, codestr);
Match regx3 = Regex.Match(loginresult, codetype);
string errno = regx.Value;
_codestring = regx2.Value;
vcodeType= regx3.Value;
//根据返回的错误号提示信息,并且请求验证码
switch (errno)
{
case "257":
return LoginStatus.codeGet;
case "7": ShowLog("账号或密码错误...");
ChangeStauts("失败", userIndex);
return LoginStatus.loginFail;;
case "0": ShowLog("登录成功...");
ChangeStauts("成功", userIndex);
break;
default: ShowLog("未知错误...");
ChangeStauts("错误", userIndex);
return LoginStatus.Error;;
}
return LoginStatus.loginSucceed;
}今天就到这里,明天说说验证码的问题,不过很大部分情况下,除非你的密码几次输入错误或者异地登录,不然一般不会让你输入验证码,如有问题欢迎评论交流
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- PC微信获取登录二维码 2020-05-18
- 生产者消费者算法模拟 c++ 2020-03-29
- C++核心技术登录实现 2019-11-19
- 【CSP-S膜你考】即时战略(模拟) 2019-10-17
- NOIP模拟day1-T1(完全背包) 2019-10-12
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash