yomi游戏对接完善
This commit is contained in:
parent
14f3811c35
commit
e17525798f
@ -1,9 +1,6 @@
|
||||
package com.red.circle.other.adapter.app.game.party3rd;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.red.circle.component.game.hotgame.response.HotGameCoin;
|
||||
import com.red.circle.component.game.hotgame.response.HotGameErrorEnum;
|
||||
import com.red.circle.component.game.hotgame.response.HotGameResponse;
|
||||
import com.red.circle.framework.core.exception.ResponseException;
|
||||
import com.red.circle.framework.web.controller.BaseController;
|
||||
import com.red.circle.other.app.dto.cmd.party3rd.*;
|
||||
@ -11,15 +8,13 @@ import com.red.circle.other.app.service.game.override.service.YomiGameService;
|
||||
import com.red.circle.other.infra.config.YomiConfig;
|
||||
import com.red.circle.other.infra.utils.AesUtils;
|
||||
import com.red.circle.wallet.inner.error.WalletErrorCode;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -44,10 +39,9 @@ public class YomiGameRestController extends BaseController {
|
||||
* @eo.method post
|
||||
* @eo.request-type text/plain
|
||||
*/
|
||||
@PostMapping("/api/gettoken")
|
||||
public YomiResponseWrapper<YomiTokenCO> getToken(HttpServletRequest request) {
|
||||
@PostMapping(value = "/api/gettoken")
|
||||
public YomiResponseWrapper<YomiTokenCO> getToken(@RequestBody String encryptedBody) {
|
||||
try {
|
||||
String encryptedBody = readRequestBody(request);
|
||||
String decryptedJson = AesUtils.decryptAESWithBase64(encryptedBody, yomiConfig.getAesKey());
|
||||
|
||||
// 解析JSON为Cmd对象
|
||||
@ -73,9 +67,8 @@ public class YomiGameRestController extends BaseController {
|
||||
* @eo.request-type text/plain
|
||||
*/
|
||||
@PostMapping("/api/userinfo")
|
||||
public YomiResponseWrapper<YomiUserInfoCO> getUserInfo(HttpServletRequest request) {
|
||||
public YomiResponseWrapper<YomiUserInfoCO> getUserInfo(@RequestBody String encryptedBody) {
|
||||
try {
|
||||
String encryptedBody = readRequestBody(request);
|
||||
String decryptedJson = AesUtils.decryptAESWithBase64(encryptedBody, yomiConfig.getAesKey());
|
||||
|
||||
// 解析JSON为Cmd对象
|
||||
@ -101,16 +94,11 @@ public class YomiGameRestController extends BaseController {
|
||||
* @eo.request-type text/plain
|
||||
*/
|
||||
@PostMapping("/api/change_balance")
|
||||
public YomiResponseWrapper<YomiBalanceCO> changeBalance(HttpServletRequest request) {
|
||||
public YomiResponseWrapper<YomiBalanceCO> changeBalance(@RequestBody String encryptedBody) {
|
||||
try {
|
||||
// 读取加密的请求body
|
||||
String encryptedBody = readRequestBody(request);
|
||||
log.info("yomi changeBalance 加密请求: {}", encryptedBody);
|
||||
|
||||
// AES解密
|
||||
String decryptedJson = AesUtils.decryptAESWithBase64(encryptedBody, yomiConfig.getAesKey());
|
||||
log.info("yomi changeBalance 解密后: {}", decryptedJson);
|
||||
|
||||
|
||||
// 解析JSON为Cmd对象
|
||||
YomiChangeBalanceCmd cmd = JSON.parseObject(decryptedJson, YomiChangeBalanceCmd.class);
|
||||
|
||||
@ -128,20 +116,9 @@ public class YomiGameRestController extends BaseController {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("yomi changeBalance 系统异常: {}", e.getMessage(), e);
|
||||
return YomiResponseWrapper.fail(9999, "系统错误,联系技术解决");
|
||||
return YomiResponseWrapper.fail(9999, e.getMessage());
|
||||
}
|
||||
return null;
|
||||
return YomiResponseWrapper.fail(9999, "系统错误,联系技术解决");
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取请求body
|
||||
*/
|
||||
private String readRequestBody(HttpServletRequest request) {
|
||||
try {
|
||||
byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream());
|
||||
return new String(bodyBytes, StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("读取请求body失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,8 @@ public enum GameOriginEnum {
|
||||
|
||||
HOTGAME,
|
||||
|
||||
LINGXIAN
|
||||
LINGXIAN,
|
||||
|
||||
YOMI
|
||||
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package com.red.circle.other.app.service.game;
|
||||
|
||||
import com.red.circle.auth.inner.endpoint.AuthClient;
|
||||
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
|
||||
import com.red.circle.component.game.hotgame.request.HotGameUserCoinUpdate;
|
||||
import com.red.circle.external.inner.endpoint.message.ImGroupClient;
|
||||
import com.red.circle.external.inner.model.cmd.message.BroadcastGroupMsgBodyCmd;
|
||||
import com.red.circle.external.inner.model.enums.message.GroupMessageTypeEnum;
|
||||
@ -132,8 +131,8 @@ public class YomiGameServiceImpl implements YomiGameService {
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("yomi获取用户信息失败: userId={}, error={}", userId, e.getMessage(), e);
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
return new YomiUserInfoCO();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,7 +156,7 @@ public class YomiGameServiceImpl implements YomiGameService {
|
||||
|
||||
// 获取游戏配置
|
||||
String sysOrigin = UserCredential.parseToken(token).getSysOrigin();
|
||||
GameListConfig gameConfig = gameListConfigService.getByGameId(gameId, GameOriginEnum.HOTGAME.name(), sysOrigin);
|
||||
GameListConfig gameConfig = gameListConfigService.getByGameId(gameId, GameOriginEnum.YOMI.name(), sysOrigin);
|
||||
if (gameConfig == null) {
|
||||
log.error("游戏配置不存在, gameId={}", gameId);
|
||||
return new YomiBalanceCO(currentBalance);
|
||||
@ -286,7 +285,7 @@ public class YomiGameServiceImpl implements YomiGameService {
|
||||
private void incGameRankingRecord(Integer rewardAmount, GameListConfig gameListConfig) {
|
||||
|
||||
GameRankingIncrementCmd build = GameRankingIncrementCmd.builder()
|
||||
.gameOrigin(GameOriginEnum.HOTGAME.name())
|
||||
.gameOrigin(GameOriginEnum.YOMI.name())
|
||||
.gameId(gameListConfig.getGameId())
|
||||
.gameName(gameListConfig.getName())
|
||||
.gameCover(gameListConfig.getCover())
|
||||
|
||||
@ -2,13 +2,13 @@ package com.red.circle.other.infra.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Yomi游戏配置
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "yomi")
|
||||
public class YomiConfig {
|
||||
|
||||
|
||||
@ -103,17 +103,21 @@ public class AesUtils {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// 生成AES密钥
|
||||
String key = "bDyeXhfYPAadK7DzxuMpZDHsPBZjbEzS";
|
||||
// 密文
|
||||
String encryptedData = "ni-P7cw9mPhm8SndkwvxAl_6o1I_jLc930uHJLXuYNe2On1vmKz1--5dvWFpJoMlKnXOrhax03DU5wrR82l_ukRo9ZMqk8AX3kENM816doDcGIS2xcotqrjaN202Lcj2_IFCy-TZdP4WjA==";
|
||||
String key = "Lt2tYDHewn6U44GaBiU0YirfmeJtA6Jr";
|
||||
|
||||
// 解密
|
||||
String decryptedData = decryptAESWithBase64(encryptedData, key);
|
||||
System.out.println("Decrypted Data: " + decryptedData);
|
||||
String base64Str = "{\n" +
|
||||
" \"game_id\": \"123\",\n" +
|
||||
" \"user_id\": \"1957345312961527809\",\n" +
|
||||
" \"token\": \"4C5BE79533FACBE3ADFEB22D60CFA771.djIlM0ExOTU3MzQ1MzEyOTYxNTI3ODA5JTNBTElLRUklM0ExNzcxNDIyNTgyNTY1JTNBMTc2ODgzMDU4MjU2NQ==\",\n" +
|
||||
" \"change_value\": 100,\n" +
|
||||
" \"change_cause\": \"bet\",\n" +
|
||||
" \"change_time\": 23423,\n" +
|
||||
" \"room_id\": \"1111\",\n" +
|
||||
" \"record_id\": \"recordId\",\n" +
|
||||
" \"round_id\": \"roundIdddd\"\n" +
|
||||
"}";
|
||||
|
||||
System.out.println();
|
||||
|
||||
String encryptedData2 = encryptAESWithBase64(decryptedData.getBytes(), key);
|
||||
String encryptedData2 = encryptAESWithBase64(base64Str.getBytes(), key);
|
||||
System.out.println("Encrypt Data: " + encryptedData2);
|
||||
|
||||
// 解密2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user