|  |  |  | 
|---|
|  |  |  | package com.doumee.config.jwt; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemDictData; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.HttpsUtil; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | 
|---|
|  |  |  | .signWith(SignatureAlgorithm.HS512, jwtProperties.getSecret()) | 
|---|
|  |  |  | .compact(); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(Constants.REDIS_TOKEN_KEY+token,JSONObject.toJSONString(userInfo),jwtProperties.getExpiration(), TimeUnit.MILLISECONDS); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String userTokenJsonStr = (String) redisTemplate.opsForValue().get(Constants.REDIS_USER_KEY+userInfo.getId()); | 
|---|
|  |  |  | if(StringUtils.isEmpty(userTokenJsonStr)){ | 
|---|
|  |  |  | redisTemplate.opsForValue().set(Constants.REDIS_USER_KEY+userInfo.getId(),Constants.REDIS_TOKEN_KEY+token); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | List<String> list  = Arrays.asList(userTokenJsonStr.split(",")); | 
|---|
|  |  |  | SystemDictData jointAccount = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.OPEN_JOINT_ACCOUNT); | 
|---|
|  |  |  | //关闭共用账户 需要清空其他token信息 | 
|---|
|  |  |  | if(Objects.nonNull(jointAccount)&&Constants.equalsInteger(Integer.valueOf(jointAccount.getCode()),Constants.ONE)){ | 
|---|
|  |  |  | for (String s:list) { | 
|---|
|  |  |  | redisTemplate.delete(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | redisTemplate.delete(Constants.REDIS_USER_KEY+userInfo.getId()); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(Constants.REDIS_USER_KEY+userInfo.getId(),Constants.REDIS_TOKEN_KEY+token); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | Boolean isHave = false; | 
|---|
|  |  |  | for (String s:list) { | 
|---|
|  |  |  | if(s.equals(Constants.REDIS_TOKEN_KEY+token)){ | 
|---|
|  |  |  | isHave = true; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!isHave){ | 
|---|
|  |  |  | redisTemplate.opsForValue().set(Constants.REDIS_USER_KEY+userInfo.getId(),userTokenJsonStr + "," + Constants.REDIS_TOKEN_KEY+token); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return token; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|