admin
2020-06-17 9d3d08ba960fc739498b0648d57eaf2c50a40fd1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsFormsApp1.entity.tb;
 
namespace WindowsFormsApp1.utils.tb
{
    class TBCookieUtil
    {
        //解析账号
        public static TBAccountLogin parseAccount(String cookie) {
            TBAccountLogin account = new TBAccountLogin();
            string[] condition = { "," };
            String[] sts = cookie.Split(';');
            string[] conditions = { "=" };
            Dictionary<String, String> param = new Dictionary<String, String>();
            foreach (String st in sts) {
                String[] values = st.Split('=');
                param.Add(values[0].Trim(), values[1].Trim());
            }
 
            foreach (String key in param.Keys) {
                Console.WriteLine(key);
            }
 
            if (param.Keys.Contains("lid")) {
                account.NickName = Uri.UnescapeDataString(param["lid"]);
            }
 
            if (param.Keys.Contains("unb"))
            {
                account.TbUid = param["unb"];
            }
 
            if (param.Keys.Contains("login"))
            {
                account.Login = Convert.ToBoolean(param["login"]);
            }
            account.Cookie = cookie;
            return account;
        }
 
        //登录失效
        public static void InvalidLogin(int position) {
            if (Constant.tbAccountMap.ContainsKey(position) && Constant.tbAccountMap[position].Login) {
                Constant.tbAccountMap[position].Login = false;
                Constant.tbAccountMap[position].UpdateTime = new DateTime();
            }
        }
 
        //登录是否有效
        public static bool IsLoginValid(int position){
            return Constant.tbAccountMap.ContainsKey(position) && Constant.tbAccountMap[position].Login;
        }
 
        public static bool updateCookie(int position, String cookies) {
            TBAccountLogin login = parseAccount(cookies);
            if (login != null && login.Login)
            {
                //登录成功
                if (WindowsFormsApp1.utils.Constant.tbAccountMap.ContainsKey(position))
                {
                    WindowsFormsApp1.utils.Constant.tbAccountMap.Remove(position);
                }
                WindowsFormsApp1.utils.Constant.tbAccountMap.Add(position, login);
                //上传Cookie
                ApiUtil.uploadCookie( cookies, null);
                return true;
            }
 
            return false;
        }
 
 
 
 
 
    }
}