| | |
| | | import com.doumee.dao.business.model.Member; |
| | | import io.jsonwebtoken.*; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | |
| | | public class JwtTokenUtil { |
| | | //Header 名称 |
| | | public static final String HEADER_KEY = "token"; |
| | | //Header 名称 |
| | | public static final String BUSINESS_HEADER_KEY = "business_token"; |
| | | //取值名称 |
| | | public static final String UserId_Name = "AppUserId"; |
| | | //取值名称 |
| | |
| | | return generateToken(jwtPayLoad.getUserId(), expirationDate, jwtPayLoad.toMap()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 生成token,根据userId和默认过期时间 |
| | | */ |
| | | public static String generateTokenForZb(Long userId,String userType,String userInfo,RedisTemplate<String,Object> redisTemplate) { |
| | | Long expiredSeconds = getExpireSeconds(); |
| | | final Date expirationDate = new Date(System.currentTimeMillis() + expiredSeconds * 1000); |
| | | return generateTokenZb(userId,userType,userInfo, expirationDate,redisTemplate); |
| | | } |
| | | |
| | | |
| | | public static String generateTokenZb(Long userId, String userType,String userInfo, Date expiredDate,RedisTemplate<String,Object> redisTemplate) { |
| | | String tokenKey = UUID.randomUUID() + "_" + userId; |
| | | redisTemplate.opsForValue().set(userType + "_" +tokenKey,userInfo); |
| | | return tokenKey; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 验证token是否失效 |
| | | */ |