懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package cn.stylefeng.guns.base.auth.jwt.payload;
 
import lombok.Data;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * jwt的第二部分
 *
 * @author fengshuonan
 * @Date 2019/7/20 20:45
 */
@Data
public class JwtPayLoad {
 
    /**
     * 用户id
     */
    private Long userId;
 
    /**
     * 账号
     */
    private String account;
 
    public Long getUserId() {
        return userId;
    }
 
    public void setUserId(Long userId) {
        this.userId = userId;
    }
 
    public String getAccount() {
        return account;
    }
 
    public void setAccount(String account) {
        this.account = account;
    }
 
    public String getUserKey() {
        return userKey;
    }
 
    public void setUserKey(String userKey) {
        this.userKey = userKey;
    }
 
    /**
     * 用户的键
     */
    private String userKey;
 
    public JwtPayLoad() {
    }
 
    public JwtPayLoad(Long userId, String account, String userKey) {
        this.userId = userId;
        this.account = account;
        this.userKey = userKey;
    }
 
    /**
     * payload转化为map形式
     *
     * @author fengshuonan
     * @Date 2019/7/20 20:50
     */
    public Map<String, Object> toMap() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId", this.userId);
        map.put("account", this.account);
        map.put("userKey", this.userKey);
        return map;
    }
 
    /**
     * payload转化为map形式
     *
     * @author fengshuonan
     * @Date 2019/7/20 20:50
     */
    public static JwtPayLoad toBean(Map<String, Object> map) {
        if (map == null || map.size() == 0) {
            return new JwtPayLoad();
        } else {
            JwtPayLoad jwtPayLoad = new JwtPayLoad();
 
            Object userId = map.get("userId");
            if (userId instanceof Long) {
                jwtPayLoad.setUserId(Long.valueOf(map.get("userId").toString()));
            }
 
            jwtPayLoad.setAccount((String) map.get("account"));
            jwtPayLoad.setUserKey((String) map.get("userKey"));
            return jwtPayLoad;
        }
    }
 
}