private void webBrowserLogin_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //加载完成 if (webBrowserLogin.Url.Host.ToLower() == "qun.qq.com") { if (webBrowserLogin.Document.Cookie != null) { //Config.myCookieContainer = null; Config.cookies = webBrowserLogin.Document.Cookie; string[] cookies = webBrowserLogin.Document.Cookie.Split(‘;‘); foreach (string str in cookies) { string[] keyvalue = str.Trim().Split(‘=‘); Cookie ck = new Cookie(keyvalue[0], keyvalue[1]); ck.Domain = ".qq.com"; Config.myCookieContainer.Add(ck); if (keyvalue[0].ToLower().Equals("skey")) { string value = keyvalue[1]; Config.bkn = SkeyToBkn(value); } if (keyvalue[0].ToLower().Equals("uin")) { Config.uin = GetUin(keyvalue[1]); } } this.DialogResult = DialogResult.OK; } } } /// <summary> /// skey转bkn /// </summary> /// <param name="str"></param> /// <returns></returns> private string SkeyToBkn(string str) { int hash = 5381; for (int i = 0; i < str.Length; ++i) { hash += (hash << 5) + (int)str[i]; } return (hash & 2147483647).ToString(); } /// <summary> /// 通过uin获取QQ号 /// </summary> /// <param name="str"></param> /// <returns></returns> private string GetUin(string str) { for (int i = 0; i < str.Length; i++) { if (str[i] != ‘o‘ && str[i] != ‘0‘) { return str.Substring(i, str.Length - i); } } return null; }
时间: 2024-10-06 03:55:33