From 7a1f231891b32770a1b1b9d2e76752c873f5db93 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 19 Mar 2026 22:13:48 +0800 Subject: [PATCH] =?UTF-8?q?ios=E7=BB=BF=E8=89=B2=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sys/query/GameListConfigQryExe.java | 21 ++++- .../rds/service/sys/VersionManageService.java | 2 + .../sys/impl/VersionManageServiceImpl.java | 13 +++ .../other/infra/utils/IpCountryUtils.java | 79 +++++++++++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/IpCountryUtils.java diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/sys/query/GameListConfigQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/sys/query/GameListConfigQryExe.java index d1a4fed0..f2aa6cf5 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/sys/query/GameListConfigQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/sys/query/GameListConfigQryExe.java @@ -10,6 +10,10 @@ import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; import com.red.circle.other.infra.database.cache.service.other.GameListCacheService; import com.red.circle.other.infra.database.rds.service.live.RoomMemberService; import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService; +import com.red.circle.other.infra.database.rds.service.sys.VersionManageService; +import com.red.circle.other.infra.database.rds.service.user.device.LatestMobileDeviceService; +import com.red.circle.other.infra.database.rds.entity.user.user.LatestMobileDevice; +import com.red.circle.other.infra.utils.IpCountryUtils; import com.red.circle.other.inner.enums.live.RoomUserRolesEnum; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.json.JacksonUtils; @@ -40,6 +44,9 @@ public class GameListConfigQryExe { private final GameListCacheService gameListCacheService; private final RoomMemberService roomMemberService; private final GameListConfigService gameListConfigService; + private final VersionManageService versionManageService; + private final LatestMobileDeviceService latestMobileDeviceService; + private final IpCountryUtils ipCountryUtils; public List execute(GameListQryCmd cmd) { List configs = listGameListConfig(cmd); @@ -131,10 +138,22 @@ public class GameListConfigQryExe { } if (cmd.checkIos()) { - return configs.stream() + List iosConfigs = configs.stream() .filter(config -> Objects.equals(config.getClientOrigin(), "IOS") || Objects .equals(config.getClientOrigin(), COMMON)) .toList(); + // iOS 审核中 且 用户 IP 属于美国,只显示 CASUAL 分类 + if (versionManageService.isIosReviewing(cmd.requireReqSysOrigin())) { + LatestMobileDevice device = latestMobileDeviceService.getByUserId(cmd.requiredReqUserId()); + String userIp = Objects.nonNull(device) ? device.getIp() : null; + log.info("GameListConfigQryExe iOS review check userId={} ip={}", cmd.requiredReqUserId(), userIp); + if (ipCountryUtils.isUsIp(userIp)) { + return iosConfigs.stream() + .filter(config -> Objects.equals(config.getCategory(), "CASUAL")) + .toList(); + } + } + return iosConfigs; } return configs.stream() .filter(config -> Objects.equals(config.getClientOrigin(), COMMON)) diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/VersionManageService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/VersionManageService.java index 08fe73c7..09592f88 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/VersionManageService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/VersionManageService.java @@ -17,6 +17,8 @@ public interface VersionManageService extends BaseService { VersionManage getVersion(String sysOrigin, String platform, String channel, Boolean review); + boolean isIosReviewing(String sysOrigin); + PageResult pageVersionManage(VersionManageQryCmd cmd); Boolean saveVersionManage(VersionManage param); diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/impl/VersionManageServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/impl/VersionManageServiceImpl.java index f73fab48..0dbe3c3f 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/impl/VersionManageServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/impl/VersionManageServiceImpl.java @@ -40,6 +40,19 @@ public class VersionManageServiceImpl extends } + @Override + public boolean isIosReviewing(String sysOrigin) { + VersionManage versionManage = query() + .eq(VersionManage::getSysOrigin, sysOrigin) + .eq(VersionManage::getPlatform, "iOS") + .eq(VersionManage::getReview, Boolean.TRUE) + .eq(VersionManage::getDel, Boolean.FALSE) + .orderByDesc(VersionManage::getCreateTime) + .last(PageConstant.LIMIT_ONE) + .getOne(); + return Objects.nonNull(versionManage); + } + @Override public PageResult pageVersionManage(VersionManageQryCmd cmd) { return query() diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/IpCountryUtils.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/IpCountryUtils.java new file mode 100644 index 00000000..61847c8b --- /dev/null +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/IpCountryUtils.java @@ -0,0 +1,79 @@ +package com.red.circle.other.infra.utils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.red.circle.component.redis.service.RedisService; +import com.red.circle.tool.core.text.StringUtils; +import java.util.Objects; +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.stereotype.Component; + +/** + * IP 归属国家查询工具. + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class IpCountryUtils { + + private static final String APPCODE = "APPCODE 35493154e8304e47943ca596706da44f"; + private static final String REQUEST_URL = "https://c2ba.api.huachen.cn/ip"; + private static final String REDIS_KEY_PREFIX = "IP_COUNTRY:"; + + private final RedisService redisService; + + /** + * 根据 IP 获取国家二字码(如 US、CN、HK). + * 结果缓存到 Redis,永久有效(IP 归属地基本不变). + * + * @param ip 用户 IP + * @return 国家二字码,查询失败返回空字符串 + */ + public String getCountryCode(String ip) { + if (StringUtils.isBlank(ip)) { + return ""; + } + String redisKey = REDIS_KEY_PREFIX + ip; + String cached = redisService.getString(redisKey); + if (StringUtils.isNotBlank(cached)) { + return cached; + } + + HttpGet httpGet = new HttpGet(REQUEST_URL + "?ip=" + ip); + httpGet.addHeader("Authorization", APPCODE); + RequestConfig requestConfig = RequestConfig.custom() + .setConnectTimeout(5000).setSocketTimeout(5000).setConnectionRequestTimeout(5000).build(); + + try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build(); + CloseableHttpResponse response = httpClient.execute(httpGet)) { + String result = EntityUtils.toString(response.getEntity()); + log.info("IpCountryUtils ip={} result={}", ip, result); + JSONObject jsonObject = JSON.parseObject(result); + if (Objects.equals(jsonObject.getInteger("ret"), 200)) { + JSONObject data = jsonObject.getJSONObject("data"); + String countryId = data.getString("country_id"); + if (StringUtils.isNotBlank(countryId)) { + redisService.setString(redisKey, countryId); + return countryId; + } + } + } catch (Exception e) { + log.error("IpCountryUtils ip={} error={}", ip, e.getMessage()); + } + return ""; + } + + /** + * 判断 IP 是否属于美国. + */ + public boolean isUsIp(String ip) { + return "US".equalsIgnoreCase(getCountryCode(ip)); + } +}