提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.base.auth.jwt.payload; |
懒 |
2 |
|
|
3 |
import lombok.Data; |
|
4 |
|
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
/** |
|
9 |
* jwt的第二部分 |
|
10 |
* |
|
11 |
* @author fengshuonan |
|
12 |
* @Date 2019/7/20 20:45 |
|
13 |
*/ |
|
14 |
@Data |
|
15 |
public class JwtPayLoad { |
|
16 |
|
|
17 |
/** |
|
18 |
* 用户id |
|
19 |
*/ |
|
20 |
private Long userId; |
|
21 |
|
|
22 |
/** |
|
23 |
* 账号 |
|
24 |
*/ |
|
25 |
private String account; |
|
26 |
|
|
27 |
public Long getUserId() { |
|
28 |
return userId; |
|
29 |
} |
|
30 |
|
|
31 |
public void setUserId(Long userId) { |
|
32 |
this.userId = userId; |
|
33 |
} |
|
34 |
|
|
35 |
public String getAccount() { |
|
36 |
return account; |
|
37 |
} |
|
38 |
|
|
39 |
public void setAccount(String account) { |
|
40 |
this.account = account; |
|
41 |
} |
|
42 |
|
|
43 |
public String getUserKey() { |
|
44 |
return userKey; |
|
45 |
} |
|
46 |
|
|
47 |
public void setUserKey(String userKey) { |
|
48 |
this.userKey = userKey; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* 用户的键 |
|
53 |
*/ |
|
54 |
private String userKey; |
|
55 |
|
|
56 |
public JwtPayLoad() { |
|
57 |
} |
|
58 |
|
|
59 |
public JwtPayLoad(Long userId, String account, String userKey) { |
|
60 |
this.userId = userId; |
|
61 |
this.account = account; |
|
62 |
this.userKey = userKey; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* payload转化为map形式 |
|
67 |
* |
|
68 |
* @author fengshuonan |
|
69 |
* @Date 2019/7/20 20:50 |
|
70 |
*/ |
|
71 |
public Map<String, Object> toMap() { |
|
72 |
HashMap<String, Object> map = new HashMap<>(); |
|
73 |
map.put("userId", this.userId); |
|
74 |
map.put("account", this.account); |
|
75 |
map.put("userKey", this.userKey); |
|
76 |
return map; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* payload转化为map形式 |
|
81 |
* |
|
82 |
* @author fengshuonan |
|
83 |
* @Date 2019/7/20 20:50 |
|
84 |
*/ |
|
85 |
public static JwtPayLoad toBean(Map<String, Object> map) { |
|
86 |
if (map == null || map.size() == 0) { |
|
87 |
return new JwtPayLoad(); |
|
88 |
} else { |
|
89 |
JwtPayLoad jwtPayLoad = new JwtPayLoad(); |
|
90 |
|
|
91 |
Object userId = map.get("userId"); |
|
92 |
if (userId instanceof Long) { |
|
93 |
jwtPayLoad.setUserId(Long.valueOf(map.get("userId").toString())); |
|
94 |
} |
|
95 |
|
|
96 |
jwtPayLoad.setAccount((String) map.get("account")); |
|
97 |
jwtPayLoad.setUserKey((String) map.get("userKey")); |
|
98 |
return jwtPayLoad; |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
} |