ios绿色游戏处理

This commit is contained in:
tianfeng 2026-03-19 22:13:48 +08:00
parent 7deeddc5a4
commit 7a1f231891
4 changed files with 114 additions and 1 deletions

View File

@ -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<GameListConfigCO> execute(GameListQryCmd cmd) {
List<GameListConfigCO> configs = listGameListConfig(cmd);
@ -131,10 +138,22 @@ public class GameListConfigQryExe {
}
if (cmd.checkIos()) {
return configs.stream()
List<GameListConfigCO> 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))

View File

@ -17,6 +17,8 @@ public interface VersionManageService extends BaseService<VersionManage> {
VersionManage getVersion(String sysOrigin, String platform, String channel, Boolean review);
boolean isIosReviewing(String sysOrigin);
PageResult<VersionManage> pageVersionManage(VersionManageQryCmd cmd);
Boolean saveVersionManage(VersionManage param);

View File

@ -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<VersionManage> pageVersionManage(VersionManageQryCmd cmd) {
return query()

View File

@ -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 获取国家二字码 USCNHK.
* 结果缓存到 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));
}
}