Compare commits
1 Commits
aslan_test
...
atyou_prod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f2f8b0f6d |
@ -1,7 +1,5 @@
|
||||
package com.red.circle.auth.endpoint;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.red.circle.auth.common.ProcessToken;
|
||||
import com.red.circle.auth.dto.TokenCredentialCO;
|
||||
import com.red.circle.auth.response.AuthErrorCode;
|
||||
@ -32,12 +30,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -68,9 +60,6 @@ public class EndpointRestController {
|
||||
|
||||
private final String LOGIN_WHITE_CONFIG = "LOGIN_WHITE_CONFIG";
|
||||
|
||||
private final String APPCODE_CONFIG = "APPCODE 35493154e8304e47943ca596706da44f";
|
||||
private final String REQUEST_URL = "https://c2ba.api.huachen.cn/ip";
|
||||
|
||||
private final RedisService redisService;
|
||||
|
||||
/**
|
||||
@ -283,44 +272,8 @@ public class EndpointRestController {
|
||||
}
|
||||
|
||||
public String checkIpAddress(String ip) {
|
||||
String redisKey = "IP_KEY:" + ip;
|
||||
String data = redisService.getString(redisKey);
|
||||
JSONObject dataObject = null;
|
||||
if (StringUtils.isNotBlank(data)) {
|
||||
dataObject = JSONObject.parseObject(data);
|
||||
} else {
|
||||
//每一个ip地址只能有一次校验
|
||||
HttpGet httpGet = new HttpGet(REQUEST_URL + "?ip=" + ip);
|
||||
httpGet.addHeader("Authorization", APPCODE_CONFIG);
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(10000).build();
|
||||
|
||||
try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
|
||||
CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
||||
String result = EntityUtils.toString(response.getEntity());
|
||||
|
||||
log.info("请求地址:{},返回信息:{}", REQUEST_URL + "?ip=" + ip, result);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (jsonObject.getInteger("ret").equals(200)) {
|
||||
dataObject = jsonObject.getJSONObject("data");
|
||||
redisService.setString(redisKey, dataObject.toJSONString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("请求地址:{}, 异常信息:{}", REQUEST_URL + "?ip=" + ip, e.getMessage());
|
||||
}
|
||||
}
|
||||
log.info("IP:{}, 国家信息:{}", ip, dataObject);
|
||||
// IP 归属接口超时或返回异常时不能让登录链路 NPE,中港台拦截只在拿到明确国家信息时执行。
|
||||
if (dataObject == null) {
|
||||
log.warn("IP:{} 国家信息获取失败,跳过 IP 国家校验", ip);
|
||||
return null;
|
||||
}
|
||||
if (dataObject != null && "中国".equals(dataObject.getString("country"))) {
|
||||
if (!Arrays.asList("香港", "澳门", "台湾").contains(dataObject.getString("region"))) {
|
||||
ResponseAssert.isTrue(UserErrorCode.REGISTRATION_FAILED, false);
|
||||
}
|
||||
}
|
||||
return dataObject.getString("country_id");
|
||||
log.info("IP:{} 临时跳过 IP 国家校验", ip);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkZone(String reqZone) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user