| | |
| | | package com.doumee.config.jwt; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.HttpsUtil; |
| | | import io.jsonwebtoken.Jwts; |
| | | import io.jsonwebtoken.SignatureAlgorithm; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.client.HttpClient; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.impl.client.HttpClientBuilder; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class JwtTokenUtil { |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String,Object> redisTemplate; |
| | | @Resource |
| | | private JwtProperties jwtProperties; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz ; |
| | | |
| | | /** |
| | | * 生成token令牌 |
| | |
| | | */ |
| | | public void logout(String token) { |
| | | try { |
| | | //登出海康系统数据 |
| | | LoginUserInfo loginUserInfo = this.getUserInfoByToken(token); |
| | | String url = systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_HTTPS).getCode() + |
| | | systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_HOST).getCode() + |
| | | systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.LOGIN_OUT_URL).getCode(); |
| | | if(StringUtils.isNotBlank(loginUserInfo.getHkMenuToken())){ |
| | | log.info("调起海康退出登录=======================>"+url+"?token="+loginUserInfo.getHkMenuToken()); |
| | | // this.hkLoginOut(url+"?token="+loginUserInfo.getHkMenuToken()); |
| | | HttpsUtil.get(url+"?token="+loginUserInfo.getHkMenuToken(),true); |
| | | } |
| | | redisTemplate.delete(Constants.REDIS_TOKEN_KEY+token);//删除老的token |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | public void hkLoginOut(String url){ |
| | | try { |
| | | // 创建HttpClient对象 |
| | | HttpClient httpClient = HttpClientBuilder.create().build(); |
| | | // 创建HttpGet对象,指定要访问的URL地址 |
| | | HttpGet httpGet = new HttpGet(url); |
| | | // 发送GET请求,获取响应 |
| | | HttpResponse response = httpClient.execute(httpGet); |
| | | // 获取响应状态码 |
| | | int statusCode = response.getStatusLine().getStatusCode(); |
| | | // 判断请求是否成功 |
| | | if (statusCode == 200) { |
| | | // 获取响应内容 |
| | | HttpEntity entity = response.getEntity(); |
| | | String responseContent = EntityUtils.toString(entity, "UTF-8"); |
| | | System.out.println(responseContent); |
| | | log.info("调起海康退出登录返回信息=======================>"+responseContent); |
| | | } else { |
| | | System.out.println("请求失败,响应码:" + statusCode); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 验证令牌 |
| | | * |