refactor(game): 重构游戏 API 地址来源

- 替换 ISysConfigService 为 IPlatformService
- 使用 GamePlatforms枚举替代硬编码的平台名称
- 优化地址获取逻辑,提高代码复用性
- 删除未使用的 Random 类导入
-调整代码格式,提高可读性
main-meitian
liaoyong 2025-04-03 11:32:14 +08:00
parent f1aa9d26e7
commit ad40fc712d
9 changed files with 60 additions and 55 deletions

View File

@ -3,8 +3,8 @@ package com.ff.game.api.ae.address;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ff.base.constant.Constants;
import com.ff.base.system.service.ISysConfigService;
import com.ff.base.enums.GamePlatforms;
import com.ff.game.service.IPlatformService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -20,12 +20,12 @@ import javax.annotation.Resource;
public class MyAEAddressSource implements AddressSource {
@Resource
private ISysConfigService configService;
private IPlatformService platformService;
@Override
public ForestAddress getAddress(ForestRequest request) {
String apiBaseUrl = configService.selectConfigByKey(Constants.AE_API_BASE_URL);
String apiBaseUrl = platformService.get(GamePlatforms.AE.getCode())
.getUrlInfo().getUrl();
return new ForestAddress("https", apiBaseUrl, 443, "");
}
}

View File

@ -3,8 +3,8 @@ package com.ff.game.api.dg.address;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ff.base.constant.Constants;
import com.ff.base.system.service.ISysConfigService;
import com.ff.base.enums.GamePlatforms;
import com.ff.game.service.IPlatformService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -20,12 +20,12 @@ import javax.annotation.Resource;
public class MyDGAddressSource implements AddressSource {
@Resource
private ISysConfigService configService;
private IPlatformService platformService;
@Override
public ForestAddress getAddress(ForestRequest request) {
String apiBaseUrl = configService.selectConfigByKey(Constants.DG_API_BASE_URL);
String apiBaseUrl = platformService.get(GamePlatforms.DG.getCode())
.getUrlInfo().getUrl();
return new ForestAddress("http", apiBaseUrl, 80, "");
}
}

View File

@ -3,8 +3,8 @@ package com.ff.game.api.fc.address;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ff.base.constant.Constants;
import com.ff.base.system.service.ISysConfigService;
import com.ff.base.enums.GamePlatforms;
import com.ff.game.service.IPlatformService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -13,12 +13,13 @@ import javax.annotation.Resource;
public class MyFCAddressSource implements AddressSource {
@Resource
private ISysConfigService configService;
private IPlatformService platformService;
@Override
public ForestAddress getAddress(ForestRequest request) {
String apiBaseUrl = configService.selectConfigByKey(Constants.FC_API_BASE_URL);
String apiBaseUrl = platformService.get(GamePlatforms.FC.getCode())
.getUrlInfo().getUrl();
return new ForestAddress("https", apiBaseUrl, 443, "");
}
}

View File

@ -3,13 +3,11 @@ package com.ff.game.api.jili.address;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ff.base.constant.Constants;
import com.ff.base.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import com.ff.base.enums.GamePlatforms;
import com.ff.game.service.IPlatformService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Random;
/**
@ -22,12 +20,12 @@ import java.util.Random;
public class MyJILIAddressSource implements AddressSource {
@Resource
private ISysConfigService configService;
private IPlatformService platformService;
@Override
public ForestAddress getAddress(ForestRequest request) {
String apiBaseUrl = configService.selectConfigByKey(Constants.JILI_API_BASE_URL);
String apiBaseUrl = platformService.get(GamePlatforms.FC.getCode())
.getUrlInfo().getUrl();
return new ForestAddress("https", apiBaseUrl, 443, "api1");
}
}

View File

@ -3,8 +3,8 @@ package com.ff.game.api.km.address;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ff.base.constant.Constants;
import com.ff.base.system.service.ISysConfigService;
import com.ff.base.enums.GamePlatforms;
import com.ff.game.service.IPlatformService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -20,12 +20,12 @@ import javax.annotation.Resource;
public class MyKMAddressSource implements AddressSource {
@Resource
private ISysConfigService configService;
private IPlatformService platformService;
@Override
public ForestAddress getAddress(ForestRequest request) {
String apiBaseUrl = configService.selectConfigByKey(Constants.KM_API_BASE_URL_LOGIN);
String apiBaseUrl = platformService.get(GamePlatforms.KM.getCode())
.getUrlInfo().getUrl();
return new ForestAddress("https", apiBaseUrl, 443, "api");
}
}

View File

@ -3,8 +3,8 @@ package com.ff.game.api.ng.address;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ff.base.constant.Constants;
import com.ff.base.system.service.ISysConfigService;
import com.ff.base.enums.GamePlatforms;
import com.ff.game.service.IPlatformService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -13,12 +13,14 @@ import javax.annotation.Resource;
public class MyNGAddressSource implements AddressSource {
@Resource
private ISysConfigService configService;
private IPlatformService platformService;
@Override
public ForestAddress getAddress(ForestRequest request) {
String apiBaseUrl = configService.selectConfigByKey(Constants.NG_API_BASE_URL);
//String apiBaseUrl = configService.selectConfigByKey(Constants.NG_API_BASE_URL);
String apiBaseUrl = platformService.get(GamePlatforms.PG.getCode())
.getUrlInfo().getUrl();
return new ForestAddress("https", apiBaseUrl, 443, "api");
}
}

View File

@ -3,8 +3,8 @@ package com.ff.game.api.pgx.address;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ff.base.constant.Constants;
import com.ff.base.system.service.ISysConfigService;
import com.ff.base.enums.GamePlatforms;
import com.ff.game.service.IPlatformService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -20,12 +20,13 @@ import javax.annotation.Resource;
public class MyPGXAddressSource implements AddressSource {
@Resource
private ISysConfigService configService;
private IPlatformService platformService;
@Override
public ForestAddress getAddress(ForestRequest request) {
String apiBaseUrl = configService.selectConfigByKey(Constants.PGX_API_BASE_URL);
// String apiBaseUrl = configService.selectConfigByKey(Constants.PGX_API_BASE_URL);
String apiBaseUrl = platformService.get(GamePlatforms.PGX.getCode())
.getUrlInfo().getUrl();
return new ForestAddress("http", apiBaseUrl, 80, "");
}
}

View File

@ -3,8 +3,8 @@ package com.ff.game.api.sa.address;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ff.base.constant.Constants;
import com.ff.base.system.service.ISysConfigService;
import com.ff.base.enums.GamePlatforms;
import com.ff.game.service.IPlatformService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -20,12 +20,14 @@ import javax.annotation.Resource;
public class MySAAddressSource implements AddressSource {
@Resource
private ISysConfigService configService;
private IPlatformService platformService;
@Override
public ForestAddress getAddress(ForestRequest request) {
String apiBaseUrl = configService.selectConfigByKey(Constants.SA_API_BASE_URL);
// String apiBaseUrl = configService.selectConfigByKey(Constants.SA_API_BASE_URL);
String apiBaseUrl = platformService.get(GamePlatforms.SA.getCode())
.getUrlInfo().getUrl();
return new ForestAddress("https", apiBaseUrl, 443, "api");
}
}

View File

@ -3,8 +3,8 @@ package com.ff.game.api.xk.address;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ff.base.constant.Constants;
import com.ff.base.system.service.ISysConfigService;
import com.ff.base.enums.GamePlatforms;
import com.ff.game.service.IPlatformService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -20,12 +20,13 @@ import javax.annotation.Resource;
public class MyXKAddressSource implements AddressSource {
@Resource
private ISysConfigService configService;
private IPlatformService platformService;
@Override
public ForestAddress getAddress(ForestRequest request) {
String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
// String apiBaseUrl = configService.selectConfigByKey(Constants.XK_API_BASE_URL);
String apiBaseUrl = platformService.get(GamePlatforms.XK.getCode())
.getUrlInfo().getUrl();
return new ForestAddress("https", apiBaseUrl, 443, "api");
}
}