| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ycl.feign.UYClient; |
| | | import com.ycl.platform.domain.param.UY.UYTokenParam; |
| | | import com.ycl.platform.domain.result.UY.UYLoginResult; |
| | | import com.ycl.utils.redis.RedisCache; |
| | | import feign.RequestInterceptor; |
| | | import feign.RequestTemplate; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | |
| | |
| | | |
| | | @Override |
| | | public void apply(RequestTemplate requestTemplate) { |
| | | System.out.println("wodefa"); |
| | | String uyToken = redisCache.getCacheObject("UY_Token"); |
| | | if (uyToken == null) { |
| | | uyToken = getToken(); |
| | | boolean flag = requestTemplate.headers().containsKey("No-Need-To-Token"); |
| | | if (!flag) { |
| | | String uyToken = redisCache.getCacheObject("UY_Token"); |
| | | if (uyToken == null) { |
| | | uyToken = getToken(); |
| | | } |
| | | requestTemplate.header("Cookie", "token=" + uyToken); |
| | | } |
| | | requestTemplate.header("Cookie", "token"+uyToken); |
| | | } |
| | | |
| | | private String getToken() { |
| | |
| | | param.setPasswd(passwd); |
| | | param.setEmail(email); |
| | | JSONObject jsonObject = uyClient.getToken(param); |
| | | log.info("请求token数据格式" + jsonObject); |
| | | redisCache.setCacheObject("Uy_Token",jsonObject.toJSONString(),3600, TimeUnit.SECONDS); |
| | | return "1"; |
| | | UYLoginResult loginResult = jsonObject.getObject("data", UYLoginResult.class); |
| | | String token = loginResult.getToken(); |
| | | redisCache.setCacheObject("Uy_Token", token, 3600, TimeUnit.SECONDS); |
| | | return token; |
| | | } |
| | | } |