|
|
@ -1,9 +1,8 @@ |
|
|
|
package com.lh.until; |
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.extra.spring.SpringUtil; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.lh.bean.RespBean; |
|
|
|
import com.lh.bean.dto.TokenDTO; |
|
|
|
import com.lh.exception.MyException; |
|
|
@ -15,23 +14,31 @@ import org.apache.http.entity.StringEntity; |
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import java.io.IOException; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Component |
|
|
|
public class Utils { |
|
|
|
@Resource |
|
|
|
private StringRedisTemplate stringRedisTemplate; |
|
|
|
// 编码Token |
|
|
|
static String url; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void initAnalysisTokenUrl() { |
|
|
|
boolean isProd = Arrays.asList(SpringUtil.getActiveProfiles()).contains("prod"); |
|
|
|
if (isProd) { |
|
|
|
url = SpringUtil.getProperty("homilychart.token.analysis.url.prod"); |
|
|
|
} else { |
|
|
|
url = SpringUtil.getProperty("homilychart.token.analysis.url.test"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 获取token中的信息 |
|
|
|
public TokenDTO analysisToken(String token) throws IOException { |
|
|
|
// 编码Token |
|
|
|
String url = "http://39.101.133.168:8828/hljw/api/v2/member/info"; |
|
|
|
// 创建HttpClient实例 |
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|
|
|
// 创建POST请求 |
|
|
@ -44,15 +51,13 @@ public class Utils { |
|
|
|
// 发送请求并获取响应 |
|
|
|
try (CloseableHttpResponse response = httpClient.execute(postRequest)) { |
|
|
|
int responseCode = response.getStatusLine().getStatusCode(); // 获取状态码 |
|
|
|
// 检查响应状态 |
|
|
|
if (responseCode != 200) { |
|
|
|
throw new MyException("Failed : HTTP error code : " + responseCode); |
|
|
|
} |
|
|
|
|
|
|
|
// 读取响应体 |
|
|
|
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); |
|
|
|
log.info("[Utils] exec analysisToken url:{}, requestBody:{}, responseCode:{}, responseBody:{}", url, token, responseCode, responseBody); |
|
|
|
|
|
|
|
// 获取不到用户状态 |
|
|
|
if (StrUtil.isEmpty(responseBody)) { |
|
|
|
if (responseCode != 200 || StrUtil.isEmpty(responseBody)) { |
|
|
|
throw new MyException("用户状态获取失败"); |
|
|
|
} |
|
|
|
|
|
|
|