From e17525798fda7032ca42fef80ded3253ca7ab87b Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Tue, 20 Jan 2026 16:42:26 +0800 Subject: [PATCH] =?UTF-8?q?yomi=E6=B8=B8=E6=88=8F=E5=AF=B9=E6=8E=A5?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/party3rd/YomiGameRestController.java | 39 ++++--------------- .../app/enums/violation/GameOriginEnum.java | 4 +- .../app/service/game/YomiGameServiceImpl.java | 7 ++-- .../circle/other/infra/config/YomiConfig.java | 4 +- .../circle/other/infra/utils/AesUtils.java | 22 ++++++----- 5 files changed, 29 insertions(+), 47 deletions(-) diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/party3rd/YomiGameRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/party3rd/YomiGameRestController.java index 6ea0ac8a..b4c7fe3e 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/party3rd/YomiGameRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/party3rd/YomiGameRestController.java @@ -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 getToken(HttpServletRequest request) { + @PostMapping(value = "/api/gettoken") + public YomiResponseWrapper 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 getUserInfo(HttpServletRequest request) { + public YomiResponseWrapper 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 changeBalance(HttpServletRequest request) { + public YomiResponseWrapper 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()); - } - } } \ No newline at end of file diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/enums/violation/GameOriginEnum.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/enums/violation/GameOriginEnum.java index 6acd5817..c747fae5 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/enums/violation/GameOriginEnum.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/enums/violation/GameOriginEnum.java @@ -6,6 +6,8 @@ public enum GameOriginEnum { HOTGAME, - LINGXIAN + LINGXIAN, + + YOMI } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/YomiGameServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/YomiGameServiceImpl.java index cd318f37..6382c801 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/YomiGameServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/YomiGameServiceImpl.java @@ -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()) diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/config/YomiConfig.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/config/YomiConfig.java index 87dcb1e1..7fb7728f 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/config/YomiConfig.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/config/YomiConfig.java @@ -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 { diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/AesUtils.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/AesUtils.java index 663adb7b..b39a4c8f 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/AesUtils.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/AesUtils.java @@ -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