Commit 91783cbb by giaogiao

解析token

parent f688e8ee
package com.wecloud.im.tillo.netty.handler;
import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientService;
import com.wecloud.im.tillo.app_ws.AppImHandler;
import com.wecloud.im.tillo.app_ws.model.Constants;
import com.wecloud.im.tillo.app_ws.model.RequestHeaderConstants;
import com.wecloud.im.tillo.app_ws.utils.FullHttpRequestUtils;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Base64;
import java.util.Map;
/**
......@@ -24,13 +32,20 @@ import java.util.Map;
public class NettyApiRequest {
private final Logger logger = LoggerFactory.getLogger(NettyApiRequest.class);
// @Resource
// private AppUserChannelsService appUserChannelsService;
// @Resource
// private AppUserChannelsService appUserChannelsService;
@Autowired
private StringRedisTemplate redisTemplate;
@Resource
private AppImHandler appImHandler;
@Autowired
private ImClientService imClientService;
@Autowired
private ImApplicationService imApplicationService;
/**
* http请求接收
*
......@@ -76,6 +91,22 @@ public class NettyApiRequest {
String token = paramMap.get(Constants.TOKEN);
String deviceId = paramMap.get(RequestHeaderConstants.DEVICE_ID);
DecodedJWT jwtInfo = JwtUtil.getJwtInfo(token);
String payload = jwtInfo.getPayload();
Base64.Decoder decoder = Base64.getDecoder();
payload = new String(decoder.decode(payload), "UTF-8");
JSONObject jsonObject = JSONObject.parseObject(payload);
String appKey = (String) jsonObject.get("appKey");
String id = (String) jsonObject.get("username");
// redisTemplate.opsForValue().set("client:" + imApplication.getAppKey() + ":" + clientId, generateToken);
// 设置uri前缀
httpRequest.setUri(Constants.APP_WS_URL);
......
......@@ -98,6 +98,7 @@ public class JwtUtil {
// 签发的目标
.withAudience(jwtProperties.getAudience())
.withClaim("test1","ddddddd")
.withClaim("appKey","elLwpel1gWCHDqZy")
// 签名时间
.withIssuedAt(new Date())
// token过期时间
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment