admin管理员组

文章数量:1530844

2023年12月14日发(作者:)

QQ--模拟登录

QQ--模拟登录

使用PC端模拟登录,主要使用的QQ空间登录地址测试。

首先,QQHelper的创建。

1 #region Helper

2 ///

3 /// Helper

4 ///

5 public class Helper

6 {

7 private static string contentType = "application/x-www-form-urlencoded";

8 private static string accept = "text/html, application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";

9 private static string userAgent = "Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn; R815T Build/JOP40D) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/4.5 Mobile Safari/533.1";

10 private static string referer = "";

11

12 private HttpWebRequest httpWebRequest = null;

13 private HttpWebResponse httpWebResponse = null;

14

15 #region Methods

16

17 public string Get(string url, CookieContainer cookieContainer)

18 {

19 string result = null;

20 try

21 {

22 httpWebRequest = (HttpWebRequest)(url);

23 Container = cookieContainer;

24 tType = contentType;

25 r = referer;

26 = accept;

27 ent = userAgent;

28 = "GET";

29 tionLimit = ue;

30 utoRedirect = false;

31

32 httpWebResponse = (HttpWebResponse)ponse();

33 Stream responseStream = ponseStream();

34 StreamReader streamReader = new StreamReader(responseStream, 8);

35 string html = End();

36

37 result = html;

38 ();

39 ();

40 ();

41 ();

42

43 return result;

44 }

45 catch (Exception)

46 {

47 return result;

48 }

49 }

50 public string Post(string url, string postString, CookieContainer cookieContainer)

51 {

52 string result = null;

53 try

54 {

55 byte[] postData = es(postString);

56

57 httpWebRequest = (HttpWebRequest)(url);

58 Container = cookieContainer;

59 tType = contentType;

60 r = referer;

61 = accept;

62 ent = userAgent;

63 = "POST";

64 tionLimit = ue;

65 utoRedirect = false;

66 tLength = ;

67 using (Stream requestStream = uestStream())

68 {

69 (postData, 0, );

70 }

71

72 httpWebResponse = (HttpWebResponse)ponse();

73 Stream responseStream = ponseStream();

74 StreamReader streamReader = new StreamReader(responseStream, 8);

75 string html = End();

76

77 result = html;

78 ();

79 ();

80 ();

81 ();

82

83 return result;

84 }

85 catch (Exception)

86 {

87 return result;

88 }

89 }

90 public string Post(string url, byte[] postData, CookieContainer cookieContainer)

91 {

92 string result = null;

93 try

94 {

95 httpWebRequest = (HttpWebRequest)(url);

96 Container = cookieContainer;

97 tType = "multipart/form-data; boundary=dnpbajwbhbccmrkegkhtrdxgnppkncfv";

98 r = referer;

99 = "";

100 = "*/*";

101 ent = userAgent;

102 = "POST";

103 tionLimit = ue;

104 utoRedirect = false;

105 tLength = ;

106 ("X-Requested-With", "ShockwaveFlash/16.0.0.257");

107 using (Stream requestStream = uestStream())

108 {

109 (postData, 0, );

110 }111

112 httpWebResponse = (HttpWebResponse)ponse();113 Stream responseStream = ponseStream();114 StreamReader streamReader = new StreamReader(responseStream, 8);115 string html = End();116

117 result = html;118 ();119 ();120 ();121 ();122

123 return result;124 }125 catch (Exception)126 {127 return result;128 }129 }130 public Stream GetStream(string url, CookieContainer cookieContaner)131 {132 try133 {134 httpWebRequest = (HttpWebRequest)(url);135 Container = cookieContaner;136 tType = contentType;137 r = referer;138 = accept;139 ent = userAgent;140 = "GET";141 tionLimit = ue;142

143 httpWebResponse = (HttpWebResponse)ponse();144 Stream responseStream = ponseStream();145

146 return responseStream;147 }148 catch (Exception)149 {150 return null;151 }152 }153

154

155

156 public string Get(string url, CookieContainer cookieContainer, out CookieContainer responseCookie)157 {158 string result = null;159 try160 {161 httpWebRequest = (HttpWebRequest)(url);162 Container = cookieContainer;163 tType = contentType;164 r = referer;165 = accept;166 ent = userAgent;167 = "GET";168 tionLimit = ue;169 utoRedirect = false;170

171 httpWebResponse = (HttpWebResponse)ponse();172 Stream responseStream = ponseStream();173 StreamReader streamReader = new StreamReader(responseStream, 8);174 string html = End();175

176 result = html;177 responseCookie = Container;178 ();179 ();180 ();181 ();182

183 return result;184 }185 catch (Exception)186 {187 responseCookie = null;188 return result;189 }190 }191 public string Post(string url, string postString, CookieContainer cookieContainer, out CookieContainer responseCookie)192 {193 string result = null;194 try195 {196 byte[] postData = es(postString);197

198 httpWebRequest = (HttpWebRequest)(url);199 Container = cookieContainer;200 tType = contentType;201 r = referer;202 = accept;203 ent = userAgent;204 = "POST";205 tionLimit = ue;206 utoRedirect = false;207 tLength = ;208 using (Stream requestStream = uestStream())209 {210 (postData, 0, );211 }212

213 httpWebResponse = (HttpWebResponse)ponse();214 Stream responseStream = ponseStream();215 StreamReader streamReader = new StreamReader(responseStream, 8);216 string html = End();217

218 result = html;219 responseCookie = Container;220 ();221 ();222 ();223 ();224

225 return result;226 }227 catch (Exception)228 {229 responseCookie = null;230 return result;231 }232 }233 public string Post(string url, byte[] postData, CookieContainer cookieContainer, out CookieContainer responseCookie)234 {

235 string result = null;

236 try

237 {

238 httpWebRequest = (HttpWebRequest)(url);

239 Container = cookieContainer;

240 tType = "multipart/form-data; boundary=dnpbajwbhbccmrkegkhtrdxgnppkncfv";

241 r = referer;

242 = "";

243 = "*/*";

244 ent = userAgent;

245 = "POST";

246 tionLimit = ue;

247 utoRedirect = false;

248 tLength = ;

249 ("X-Requested-With", "ShockwaveFlash/16.0.0.257");

250 using (Stream requestStream = uestStream())

251 {

252 (postData, 0, );

253 }

254

255 httpWebResponse = (HttpWebResponse)ponse();

256 Stream responseStream = ponseStream();

257 StreamReader streamReader = new StreamReader(responseStream, 8);

258 string html = End();

259

260 result = html;

261 responseCookie = Container;

262 ();

263 ();

264 ();

265 ();

266

267 return result;

268 }

269 catch (Exception)

270 {

271 responseCookie = null;

272 return result;

273 }

274 }

275 public Stream GetStream(string url, CookieContainer cookieContainer, out CookieContainer responseCookie)

276 {

277 try

278 {

279 httpWebRequest = (HttpWebRequest)(url);

280 Container = cookieContainer;

281 tType = contentType;

282 r = referer;

283 = accept;

284 ent = userAgent;

285 = "GET";

286 tionLimit = ue;

287

288 httpWebResponse = (HttpWebResponse)ponse();

289 Stream responseStream = ponseStream();

290

291 responseCookie = Container;

292 return responseStream;

293 }

294 catch (Exception)

295 {

296 responseCookie = null;

297 return null;

298 }

299 }

300

301

302 #endregion

303

304 #region 核心算法

305 #region 账号+密码+验证码加密

306 public string GetPassword(string qqNum, string password, string verifycode)

307 {

308 //uin为QQ号码转换为16位的16进制

309 int qq;

310 se(qqNum, out qq);

311

312 qqNum = ng("x");

313 qqNum = t(16, '0');

314

315 String P = hexchar2bin(md5(password));

316 String U = md5(P + hexchar2bin(qqNum)).ToUpper();

317 String V = md5(U + r()).ToUpper();

318 return V;

319 }

320

321 public static string md5(string input)

322 {

323 byte[] buffer = ().ComputeHash(oding("ISO-8859-1").GetBytes(input));

324 return binl2hex(buffer);

325 }

326

327 public static string binl2hex(byte[] buffer)

328 {

329 StringBuilder builder = new StringBuilder();

330 for (int i = 0; i < ; i++)

331 {

332 (buffer[i].ToString("x2"));

333 }

334 return ng();

335 }

336

337 public static string hexchar2bin(string passWord)

338 {

339 StringBuilder builder = new StringBuilder();

340 for (int i = 0; i < ; i = i + 2)

341 {

342 ((32(ing(i, 2), 16)));

343 }

344 return ng();

345 }

346 #endregion

347

348 #region g_tk加密

349 public string GetGtk(string skey)

350 {

351 //@VkbCxNHmR

352 long hash = 5381;

353 for (int o = 0; o < ; o++)

354 {

355 hash += (hash << 5) + skey[o];

356 }357 hash = hash & 0x7fffffff;//hash就是算出的g_tk值了.

358 return ng();

359 }

360 #endregion

361 #endregion

362

363 }

364 #endregion

接着,QQModel的创建

1 #region Model

2 public class Context

3 {

4 public string ResponseString { get; set; }

5 public CookieContainer CookieContainer { get; set; }

6 public Context()

7 {

8 CookieContainer = new CookieContainer();

9 }

10 }

11

12

13 #region

14 public class CodeModel

15 {

16 public int HasImage { get; set; }

17 public Stream VerifyStream { get; set; }

18 public string VerifyString { get; set; }

19 }

20 public class LoginModel

21 {

22 public int IsSuccess { get; set; }

23 public string Text { get; set; }

24 public string NickName { get; set; }

25 public string QQ { get; set; }

26 public string Sid { get; set; }

27 }

28

29 public class Model

30 {

31 public string ResponseString { get; set; }

32 public CookieContainer CookieContainer { get; set; }

33 public CodeModel Code { get; set; }

34 public LoginModel Login { get; set; }

35

36 public Model()

37 {

38 CookieContainer = new CookieContainer();

39 Code = new CodeModel();

40 Login = new LoginModel();

41 }

42 }

43 #endregion

44 #endregion

接着,QQMethods的创建

#region Methods

public Model GetCheck(string qq)

{

//获取验证信息

//验证信息格式为:ptui_checkVC('0','!MIW','x00x00x00x00x9ax65x0fxd7')

//其中分为三部分,第一个值0或1判断是否需要图片验证码

// 第二个值是默认验证码,若不需要图片验证码,就用此验证码来提交

// 第三个是所使用的QQ号码的16进制形式

string url = "/check?uin=" + qq + "&appid=549000912&r=0.17358";

Model model = new Model();

CookieContainer cookieContainer;

seString = new Helper().Get(url, Container, out cookieContainer);

Container = cookieContainer;

//将验证码信息的三部分存入数组

int checkCodePosition = f("(") + 1;

string checkCode = ing(checkCodePosition, dexOf(")") - checkCodePosition);

string[] checkNum = e("'", "").Split(','); //验证码数组

if (checkNum[0] == "1") //判断是否需要图片验证码

{

String urlImage = "/getimage?aid=549000912&uin=" + qq + "&cap_cd=" + checkNum[1];

Stream responseStream = new Helper().GetStream(urlImage, Container, out cookieContainer);

Container = cookieContainer;

ge = 1;

Stream = responseStream;

}

else //若不需图片验证码,验证码就等于checkNum[1]

{

ge = 0;

String = checkNum[1];

}

return model;

}

public Model GetResult(string qq, string password, Model model)

{

string pass = new Helper().GetPassword(qq, password, String);

string url = "/login?u=" + qq + "&verifycode=" + String + "&p=" + pass + "&aid=549000912&u1=http%3A%2F%%2Fqzone%2Fv5%%3Fpara%3Dizone&h=1&t=1&g=

CookieContainer cookieContainer;

string result = new Helper().Get(url, Container, out cookieContainer);

seString = result;

Container = cookieContainer;

result = e("rn", "").Replace("ptuiCB(", "").Replace(");", "").Replace("'", "");

string[] rs = (',');//共6个参数

ess = 32(rs[0]);

= rs[4];

if (ess == 0)

{

//登录成功

me = rs[5];

}

else

{

= rs[5];

} return model;

}

#endregion

接着,Action的创建

1,验证码相关两个方法

  Check检测是否有验证码

  Vericode下载验证码

public string Check(string qq)

{

model = new Methods().GetCheck(qq);

if (ge == 1)

{

return "Y";

}

else

{

return "N";

}

}

public ActionResult Vericode(string qq)

{

model = new Methods().GetCheck(qq);

return File(Stream, @"image/jpeg");

}

2,登录验证

static Model model = new Model();

//

// GET: /User/

public ActionResult Index()

{

return View();

}

[HttpPost]

public ActionResult Index(string qq, string password, string vericode)

{

if (!OrEmpty(vericode))

{

String = vericode;

}

model = new Methods().GetResult(qq, password, model);

if (ess == 0)

{

using (XiaoHuaEntities db = new XiaoHuaEntities())

{

//处理QQ信息

User user = (o => == qq).FirstOrDefault();

if (user == null)

{

user = new User();

= qq;

rd = password;

me = me;

= ;

DateTime = ;

//获取签名

= new Methods().GetSign(qq, model);

(user);

anges();

}

else

{

}

}

return Json(new { success = 1, text = , url = "/Home/Index" });

}

else

{

return Json(new { success = 0, text = , url = "" });

}

}

最后,是HTML页面的创建

@{

= "Index";

}

页面效果

输入QQ号且QQ号输入框失去焦点,自动加载验证码。

本文标签: 验证码QQ号登录