wu
2024-03-26 e9b0059e5ee9551f7b9b81c9358ce3d42886ae9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.mes.tools;
 
import cn.hutool.core.date.DateUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
 
import java.util.Date;
 
public class TokenTools {
 
    /**
     * 生成token
     * @return
     */
    public  static String getToken(String userid,String sign){
        return JWT.create().withAudience(userid) // 将 user id 保存到 token 里面,作为载荷
                .withExpiresAt(DateUtil.offsetHour(new Date(), 24)) // 2小时后token过期
                .sign(Algorithm.HMAC256(sign)); // 以 password 作为 token 的密钥
 
    }
}