幸运礼物新爆率,新增多账号模式 根据standardId切换
This commit is contained in:
parent
5ef64ef311
commit
85f3e58190
@ -95,4 +95,10 @@ public class GameLuckyGiftBusinessEvent implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private List<GameLuckyGiftUser> users;
|
private List<GameLuckyGiftUser> users;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规格ID,用于匹配第三方API配置.
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long standardId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import com.red.circle.other.domain.ranking.RankingActivityType;
|
|||||||
import com.red.circle.other.domain.ranking.RankingCycleType;
|
import com.red.circle.other.domain.ranking.RankingCycleType;
|
||||||
import com.red.circle.other.domain.ranking.RankingDimension;
|
import com.red.circle.other.domain.ranking.RankingDimension;
|
||||||
import com.red.circle.other.infra.config.LuckyGiftApiConfig;
|
import com.red.circle.other.infra.config.LuckyGiftApiConfig;
|
||||||
|
import com.red.circle.other.infra.config.LuckyGiftApiConfig.ApiAccount;
|
||||||
import com.red.circle.other.infra.database.cache.entity.game.luckgift.GameLuckyGiftConfigCache;
|
import com.red.circle.other.infra.database.cache.entity.game.luckgift.GameLuckyGiftConfigCache;
|
||||||
import com.red.circle.other.infra.database.cache.entity.game.luckgift.GameLuckyGiftInventoryCache;
|
import com.red.circle.other.infra.database.cache.entity.game.luckgift.GameLuckyGiftInventoryCache;
|
||||||
import com.red.circle.other.infra.database.cache.entity.game.luckgift.LuckyGiftInventoryTemplateCache;
|
import com.red.circle.other.infra.database.cache.entity.game.luckgift.LuckyGiftInventoryTemplateCache;
|
||||||
@ -181,7 +182,8 @@ public class GameLuckyGiftCommon {
|
|||||||
.setOpenComboLoss(isOpenComboLoss(template))
|
.setOpenComboLoss(isOpenComboLoss(template))
|
||||||
.setSysComboLoss(template.getComboLoss())
|
.setSysComboLoss(template.getComboLoss())
|
||||||
.setOpenGiftGiveTotal(isOpenGiftGiveTotal(template))
|
.setOpenGiftGiveTotal(isOpenGiftGiveTotal(template))
|
||||||
.setSysGiftGiveTotal(template.getGiftGiveTotal());
|
.setSysGiftGiveTotal(template.getGiftGiveTotal())
|
||||||
|
.setStandardId(standardId);
|
||||||
|
|
||||||
// 是否正在连击送礼物
|
// 是否正在连击送礼物
|
||||||
if (Boolean.TRUE.equals(event.getCheckCombo())) {
|
if (Boolean.TRUE.equals(event.getCheckCombo())) {
|
||||||
@ -685,12 +687,16 @@ public class GameLuckyGiftCommon {
|
|||||||
*/
|
*/
|
||||||
private ThirdPartyLotteryResult callThirdPartyLotteryApi(GameLuckyGiftParam param, List<String> orderIds) {
|
private ThirdPartyLotteryResult callThirdPartyLotteryApi(GameLuckyGiftParam param, List<String> orderIds) {
|
||||||
try {
|
try {
|
||||||
|
// 根据 standardId 获取对应的API配置
|
||||||
|
ApiAccount apiConfig = luckyGiftApiConfig.getConfigByStandardId(param.getStandardId());
|
||||||
|
log.info("使用API配置, standardId: {}, config: {}", param.getStandardId(), apiConfig);
|
||||||
|
|
||||||
Map<String, Object> requestData = new HashMap<>();
|
Map<String, Object> requestData = new HashMap<>();
|
||||||
requestData.put("room_id", param.getRoomId().toString());
|
requestData.put("room_id", param.getRoomId().toString());
|
||||||
requestData.put("user_id", param.getUserId().toString());
|
requestData.put("user_id", param.getUserId().toString());
|
||||||
requestData.put("order_id", orderIds);
|
requestData.put("order_id", orderIds);
|
||||||
requestData.put("app_id", luckyGiftApiConfig.getAppId());
|
requestData.put("app_id", apiConfig.getAppId());
|
||||||
requestData.put("app_channel", luckyGiftApiConfig.getAppChannel());
|
requestData.put("app_channel", apiConfig.getAppChannel());
|
||||||
requestData.put("gift_id", param.getGiftId().intValue());
|
requestData.put("gift_id", param.getGiftId().intValue());
|
||||||
requestData.put("gift_price", param.getGift().getGiftCandy().intValue());
|
requestData.put("gift_price", param.getGift().getGiftCandy().intValue());
|
||||||
requestData.put("gift_num", param.getQuantity());
|
requestData.put("gift_num", param.getQuantity());
|
||||||
@ -698,7 +704,7 @@ public class GameLuckyGiftCommon {
|
|||||||
requestData.put("timestamp", System.currentTimeMillis() / 1000);
|
requestData.put("timestamp", System.currentTimeMillis() / 1000);
|
||||||
|
|
||||||
// 生成签名
|
// 生成签名
|
||||||
String signature = generateSignature(requestData);
|
String signature = generateSignature(requestData, apiConfig.getAppKey());
|
||||||
requestData.put("signature", signature);
|
requestData.put("signature", signature);
|
||||||
|
|
||||||
log.info("调用第三方幸运礼物API,请求参数:{}", JSON.toJSONString(requestData));
|
log.info("调用第三方幸运礼物API,请求参数:{}", JSON.toJSONString(requestData));
|
||||||
@ -709,7 +715,7 @@ public class GameLuckyGiftCommon {
|
|||||||
|
|
||||||
// 发送HTTP请求 - 使用Hutool的HttpUtil
|
// 发送HTTP请求 - 使用Hutool的HttpUtil
|
||||||
String requestBody = JSON.toJSONString(requestData);
|
String requestBody = JSON.toJSONString(requestData);
|
||||||
String response = HttpUtil.createPost(luckyGiftApiConfig.getUrl())
|
String response = HttpUtil.createPost(apiConfig.getUrl())
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.header("Accept", "application/json")
|
.header("Accept", "application/json")
|
||||||
.timeout(10000)
|
.timeout(10000)
|
||||||
@ -766,8 +772,12 @@ public class GameLuckyGiftCommon {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成API签名.
|
* 生成API签名.
|
||||||
|
*
|
||||||
|
* @param params 请求参数
|
||||||
|
* @param appKey 应用密钥
|
||||||
|
* @return 签名字符串
|
||||||
*/
|
*/
|
||||||
private String generateSignature(Map<String, Object> params) {
|
private String generateSignature(Map<String, Object> params, String appKey) {
|
||||||
try {
|
try {
|
||||||
// 按键名升序排列参数
|
// 按键名升序排列参数
|
||||||
TreeMap<String, Object> sortedParams = new TreeMap<>(params);
|
TreeMap<String, Object> sortedParams = new TreeMap<>(params);
|
||||||
@ -796,7 +806,7 @@ public class GameLuckyGiftCommon {
|
|||||||
signBuilder.append(key).append("=").append(valueStr);
|
signBuilder.append(key).append("=").append(valueStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
signBuilder.append("&app_key=").append(luckyGiftApiConfig.getAppKey());
|
signBuilder.append("&app_key=").append(appKey);
|
||||||
|
|
||||||
log.debug("签名原始字符串: {}", signBuilder.toString());
|
log.debug("签名原始字符串: {}", signBuilder.toString());
|
||||||
|
|
||||||
@ -1244,6 +1254,9 @@ public class GameLuckyGiftCommon {
|
|||||||
// 获得用户头像框
|
// 获得用户头像框
|
||||||
UserPropsResourcesDTO avatarFrameProps = getUserAvatarFrameProps(sendUserProfile);
|
UserPropsResourcesDTO avatarFrameProps = getUserAvatarFrameProps(sendUserProfile);
|
||||||
|
|
||||||
|
// 优先使用cmd传递的standardId,如果为空则降级使用gift的standardId
|
||||||
|
Long standardId = Objects.nonNull(cmd.getStandardId()) ? cmd.getStandardId() : gift.getStandardId();
|
||||||
|
|
||||||
return new GameLuckyGiftParam()
|
return new GameLuckyGiftParam()
|
||||||
.setId(cmd.getId())
|
.setId(cmd.getId())
|
||||||
.setGift(gift)
|
.setGift(gift)
|
||||||
@ -1253,7 +1266,7 @@ public class GameLuckyGiftCommon {
|
|||||||
.setUserId(cmd.getUserId())
|
.setUserId(cmd.getUserId())
|
||||||
.setQuantity(cmd.getQuantity())
|
.setQuantity(cmd.getQuantity())
|
||||||
.setSysOrigin(cmd.getSysOrigin())
|
.setSysOrigin(cmd.getSysOrigin())
|
||||||
.setStandardId(gift.getStandardId())
|
.setStandardId(standardId)
|
||||||
.setGiftsCount(cmd.getGiftsCount())
|
.setGiftsCount(cmd.getGiftsCount())
|
||||||
.setComboCount(cmd.getGiftCombos())
|
.setComboCount(cmd.getGiftCombos())
|
||||||
.setRoomAccount(cmd.getRoomAccount())
|
.setRoomAccount(cmd.getRoomAccount())
|
||||||
|
|||||||
@ -109,4 +109,10 @@ public class GameLuckyGiftParamCmd implements Serializable {
|
|||||||
@JsonSerialize(using = ToStringSerializer.class)
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
private Long acceptUserId;
|
private Long acceptUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规格ID,用于匹配第三方API配置.
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long standardId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -101,7 +101,8 @@ public class GameLuckyGiftBusinessListener implements MessageListener {
|
|||||||
.setSysComboLoss(event.getSysComboLoss())
|
.setSysComboLoss(event.getSysComboLoss())
|
||||||
.setOpenGiftGiveTotal(event.getOpenGiftGiveTotal())
|
.setOpenGiftGiveTotal(event.getOpenGiftGiveTotal())
|
||||||
.setSysGiftGiveTotal(event.getSysGiftGiveTotal())
|
.setSysGiftGiveTotal(event.getSysGiftGiveTotal())
|
||||||
.setRegionCode(userRegionGateway.getRegionCode(event.getUserId()));
|
.setRegionCode(userRegionGateway.getRegionCode(event.getUserId()))
|
||||||
|
.setStandardId(event.getStandardId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package com.red.circle.other.infra.config;
|
package com.red.circle.other.infra.config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import lombok.Data;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -7,11 +10,85 @@ import org.springframework.stereotype.Component;
|
|||||||
/**
|
/**
|
||||||
* 第三方幸运礼物API配置
|
* 第三方幸运礼物API配置
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
@Component
|
@Component
|
||||||
@ConfigurationProperties(prefix = "lucky.gift.api")
|
@ConfigurationProperties(prefix = "lucky.gift.api")
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
public class LuckyGiftApiConfig {
|
public class LuckyGiftApiConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多账号配置列表
|
||||||
|
*/
|
||||||
|
private List<ApiAccount> configs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认API地址(向后兼容旧配置)
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认应用密钥(向后兼容旧配置)
|
||||||
|
*/
|
||||||
|
private String appKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认应用ID(向后兼容旧配置)
|
||||||
|
*/
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认应用渠道(向后兼容旧配置)
|
||||||
|
*/
|
||||||
|
private String appChannel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
*/
|
||||||
|
private boolean enabled = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 standardId 获取对应的配置
|
||||||
|
* 优先从 configs 列表匹配,匹配不到则返回默认配置
|
||||||
|
*
|
||||||
|
* @param standardId 规格ID
|
||||||
|
* @return 匹配的配置
|
||||||
|
*/
|
||||||
|
public ApiAccount getConfigByStandardId(Long standardId) {
|
||||||
|
// 优先从 configs 列表中匹配
|
||||||
|
if (configs != null && !configs.isEmpty() && standardId != null) {
|
||||||
|
for (ApiAccount config : configs) {
|
||||||
|
if (Objects.equals(config.getStandardId(), standardId)) {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 匹配不到则返回默认配置(向后兼容)
|
||||||
|
return buildDefaultConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建默认配置(使用旧的单一配置字段)
|
||||||
|
*/
|
||||||
|
private ApiAccount buildDefaultConfig() {
|
||||||
|
ApiAccount defaultConfig = new ApiAccount();
|
||||||
|
defaultConfig.setUrl(this.url);
|
||||||
|
defaultConfig.setAppKey(this.appKey);
|
||||||
|
defaultConfig.setAppId(this.appId);
|
||||||
|
defaultConfig.setAppChannel(this.appChannel);
|
||||||
|
return defaultConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单个账号配置
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class ApiAccount {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规格ID,用于匹配
|
||||||
|
*/
|
||||||
|
private Long standardId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API地址
|
* API地址
|
||||||
*/
|
*/
|
||||||
@ -32,57 +109,24 @@ public class LuckyGiftApiConfig {
|
|||||||
*/
|
*/
|
||||||
private String appChannel;
|
private String appChannel;
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 是否启用
|
public String toString() {
|
||||||
*/
|
return "ApiAccount{" +
|
||||||
private boolean enabled = true;
|
"standardId=" + standardId +
|
||||||
|
", url='" + url + '\'' +
|
||||||
// Getter 和 Setter 方法
|
", appKey='***'" +
|
||||||
public String getUrl() {
|
", appId='" + appId + '\'' +
|
||||||
return url;
|
", appChannel='" + appChannel + '\'' +
|
||||||
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppKey() {
|
|
||||||
return appKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppKey(String appKey) {
|
|
||||||
this.appKey = appKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppId() {
|
|
||||||
return appId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppId(String appId) {
|
|
||||||
this.appId = appId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppChannel() {
|
|
||||||
return appChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppChannel(String appChannel) {
|
|
||||||
this.appChannel = appChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LuckyGiftApiConfig{" +
|
return "LuckyGiftApiConfig{" +
|
||||||
"url='" + url + '\'' +
|
"configs=" + configs +
|
||||||
", appKey='" + "***" + '\'' + // 敏感信息脱敏
|
", url='" + url + '\'' +
|
||||||
|
", appKey='***'" +
|
||||||
", appId='" + appId + '\'' +
|
", appId='" + appId + '\'' +
|
||||||
", appChannel='" + appChannel + '\'' +
|
", appChannel='" + appChannel + '\'' +
|
||||||
", enabled=" + enabled +
|
", enabled=" + enabled +
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user