public static Friendlist GetFriendsList(string result) { Friendlist TheFriendlist = new Friendlist(); Regex group = new Regex("({\"index\":)(?<index>[0-9]{1,2}?)(,\"name\":\")(?<name>.+?)(\"})"); Group g0 = new Group(); g0.name = "在线"; g0.groupindex = 0; TheFriendlist.Groups.Add("100", g0); Group g1 = new Group(); g1.name = "我的好友"; g1.groupindex = 1; TheFriendlist.Groups.Add("0", g1); int i = 2; foreach (Match item in group.Matches(result)) { Group g = new Group(); g.name = Converts.ConvertUnicodeStringToChinese(item.Groups["name"].Value); g.groupindex = i; TheFriendlist.Groups.Add(item.Groups["index"].Value, g); i++; } TheFriendlist.groupnum = i; Regex friend = new Regex("({\"uin\":)(?<uin>[0-9]{5,11}?)(,\"categories\":)(?<id>[0-9]{1,2}?)(})"); foreach (Match item in friend.Matches(result)) { Friend f = new Friend(); f.uin = item.Groups["uin"].Value; f.groupid = item.Groups["id"].Value; f.groupindex = TheFriendlist.Groups[f.groupid].groupindex; TheFriendlist.Friends.Add(f.uin, f); } Regex info = new Regex("({\"uin\":)(?<uin>[0-9]{5,11}?)(,\"nick\":)(?<nick>.+?)(\",\"face\":)(?<face>.+?)(,\"flag\":)(?<flag>.+?)(})"); foreach (Match item in info.Matches(result)) { TheFriendlist.Friends[item.Groups["uin"].Value].name = Converts.ConvertUnicodeStringToChinese(item.Groups["nick"].Value.Substring(1)); TheFriendlist.Friends[item.Groups["uin"].Value].face = Convert.ToInt32(item.Groups["face"].Value); } return(TheFriendlist); }
/// <summary> /// 登录流程 /// </summary> private void login() { if (QQUser.Verifycode == "") { if (QQUser.isNeedVerifyCode()) { VerifyPic = QQUser.getVerifyCodePicStream(); Invoke((MethodInvoker) delegate { Button_LoginQQ.Enabled = true; textBox_QQ.Enabled = true; textBox_PWD.Enabled = true; Button_LoginQQ.Text = "登陆"; pictureBox_verifypic.Image = Image.FromStream(VerifyPic); pictureBox_verifypic.Visible = true; textBox_verifycode.Visible = true; textBox_verifycode.Enabled = true; label3.Visible = true; }); Thread.CurrentThread.Abort(); } } QQUser.QQPassword = textBox_PWD.Text.Trim(); string loginstate = QQUser.loginWebQQ(checkBox_offline.Checked); if (loginstate != "登录成功") { MessageBox.Show(loginstate); QQUser.Verifycode = ""; Invoke((MethodInvoker) delegate { Button_LoginQQ.Enabled = true; textBox_QQ.Enabled = true; textBox_PWD.Enabled = true; Button_LoginQQ.Text = "登陆"; }); Thread.CurrentThread.Abort(); return; } ptwebqq = QQUser.Cookie.GetCookies(ckuri)["ptwebqq"].Value; var getretcode = new Regex("(retcode\":)(?<retcode>.+?)(,)"); Invoke((MethodInvoker) delegate { Button_LoginQQ.Text = "登录成功"; }); string tempvalue = QQUser.loginGetValue(ptwebqq); if (!getretcode.Match(tempvalue).Success || getretcode.Match(tempvalue).Groups["retcode"].Value != "0") { MessageBox.Show("登录取值失败"); QQUser.Verifycode = ""; Invoke((MethodInvoker) delegate { Button_LoginQQ.Enabled = true; textBox_QQ.Enabled = true; textBox_PWD.Enabled = true; Button_LoginQQ.Text = "登陆"; }); Thread.CurrentThread.Abort(); return; } var regexvalue = new Regex("(vfwebqq\":\")(?<vfwebqq>.+?)(\",\"psessionid\":\")(?<psessionid>.+?)(\"}})"); QQUser.Vfwebqq = regexvalue.Match(tempvalue).Groups["vfwebqq"].Value; QQUser.Psessionid = regexvalue.Match(tempvalue).Groups["psessionid"].Value; string tempfriendonline = string.Empty; Invoke((MethodInvoker) delegate { Button_LoginQQ.Text = "获取个人信息"; }); string tempmyinfo = QQUser.getfriendinfo(QQUser.Uin); if (!getretcode.Match(tempmyinfo).Success || getretcode.Match(tempmyinfo).Groups["retcode"].Value != "0") { MessageBox.Show("获取个人信息失败"); QQUser.Verifycode = ""; Invoke((MethodInvoker) delegate { Button_LoginQQ.Enabled = true; textBox_QQ.Enabled = true; textBox_PWD.Enabled = true; Button_LoginQQ.Text = "登陆"; }); Thread.CurrentThread.Abort(); return; } Invoke((MethodInvoker) delegate { Button_LoginQQ.Text = "获取好友列表"; }); string tempfriend = QQUser.getFriend(); if (!getretcode.Match(tempfriend).Success || getretcode.Match(tempfriend).Groups["retcode"].Value != "0") { MessageBox.Show("获取好友列表失败"); QQUser.Verifycode = ""; Invoke((MethodInvoker) delegate { Button_LoginQQ.Enabled = true; textBox_QQ.Enabled = true; textBox_PWD.Enabled = true; Button_LoginQQ.Text = "登陆"; }); Thread.CurrentThread.Abort(); return; } Invoke((MethodInvoker) delegate { Button_LoginQQ.Text = "获取群列表"; }); string tempqqgroup = QQUser.getgroup(); if (!getretcode.Match(tempqqgroup).Success || getretcode.Match(tempqqgroup).Groups["retcode"].Value != "0") { MessageBox.Show("获取群列表失败"); QQUser.Verifycode = ""; Invoke((MethodInvoker) delegate { Button_LoginQQ.Enabled = true; textBox_QQ.Enabled = true; textBox_PWD.Enabled = true; Button_LoginQQ.Text = "登陆"; }); Thread.CurrentThread.Abort(); return; } thefriendlist = GetFriendlists.GetFriendsList(tempfriend); thefriendlist.OnLineFriends = GetFriendlists.GetOnlineFriend(tempfriendonline); thefriendlist.QQGroups = GetFriendlists.GetGroupList(tempqqgroup); thefriendlist.setmyinfo(QQUser.Uin, tempmyinfo); td = new Thread(GetMessage); td.Start(); Thread.CurrentThread.Abort(); }