Parcourir la source

fix : CP消息推送兼容配置修改

bilingfeng il y a 1 an
Parent
commit
5c06f80b64

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 < (处理Websocket导致的token入侵问题02´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (CP消息推送兼容配置修改´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 29 - 10
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/CpSendMsgLogServiceImpl.java

@@ -6,16 +6,17 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zanxiang.game.module.manage.enums.CpSendRoleResultEnum;
 import com.zanxiang.game.module.manage.pojo.dto.CpSendMsgResultDTO;
-import com.zanxiang.game.module.manage.service.ICpSendMsgLogService;
-import com.zanxiang.game.module.manage.service.ICpSendMsgResultService;
-import com.zanxiang.game.module.manage.service.IGameUserRoleService;
+import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
+import com.zanxiang.game.module.manage.service.*;
 import com.zanxiang.game.module.mybatis.entity.CpSendMsgLog;
 import com.zanxiang.game.module.mybatis.entity.CpSendMsgResult;
+import com.zanxiang.game.module.mybatis.entity.GameSupper;
 import com.zanxiang.game.module.mybatis.entity.GameUserRole;
 import com.zanxiang.game.module.mybatis.mapper.CpSendMsgLogMapper;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.exception.BaseException;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
@@ -41,14 +42,18 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
 
     private static final String SIGN_MD5 = "MD5";
 
-    private static final String CP_API_KEY = "355b7f07125c1ef71cfd10166e0b90aa";
-
     @Autowired
     private TransactionTemplate transactionTemplate;
 
     @Autowired
     private RestTemplate restTemplate;
 
+    @Autowired
+    private IGameService gameService;
+
+    @Autowired
+    private IGameSupperService gameSupperService;
+
     @Autowired
     private IGameUserRoleService gameUserRoleService;
 
@@ -67,6 +72,20 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
         CpSendMsgLog cpSendMsgLog = this.transform(taskId, gameId, msgId, gameUserRoleList.size());
         super.save(cpSendMsgLog);
         if (CollectionUtils.isEmpty(gameUserRoleList)) {
+            log.error("CP发送消息参数错误, 角色列表信息不存在! taskId : {}, gameId : {}, roleIdList : {}",
+                    taskId, gameId, JsonUtil.toString(roleIdList));
+            return;
+        }
+        GameDTO gameDTO = gameService.getById(gameId);
+        if (gameDTO == null) {
+            log.error("CP发送消息参数错误, 游戏信息不存在! taskId : {}, gameId : {}, roleIdList : {}",
+                    taskId, gameId, JsonUtil.toString(roleIdList));
+            return;
+        }
+        GameSupper gameSupper = gameSupperService.getById(gameDTO.getSuperGameId());
+        if (gameSupper == null || Strings.isBlank(gameSupper.getCpSendMsgUrl()) || Strings.isBlank(gameSupper.getCpSendMsgKey())) {
+            log.error("CP发送消息参数错误, 超父游戏信息不全! taskId : {}, gameId : {}, roleIdList : {}, gameSupper : {}",
+                    taskId, gameId, JsonUtil.toString(roleIdList), JsonUtil.toString(gameSupper));
             return;
         }
         //角色信息按区服分组
@@ -75,7 +94,7 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
         serverIdRoleMap.forEach((serverId, roleList) -> {
             List<String> serverRoleIdList = roleList.stream().map(GameUserRole::getRoleId).collect(Collectors.toList());
             try {
-                CpSendMsgResultDTO result = this.cpSendMsgApi(msgId, serverId, serverRoleIdList, text);
+                CpSendMsgResultDTO result = this.cpSendMsgApi(gameSupper, msgId, serverId, text, serverRoleIdList);
                 this.resultHandle(cpSendMsgLog, result, serverId, serverRoleIdList);
             } catch (Exception e) {
                 log.error("CP消息发送API调用异常, serverId : {}, roleList : {}", serverId, roleList);
@@ -130,13 +149,14 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
                 .build();
     }
 
-    private CpSendMsgResultDTO cpSendMsgApi(String msgId, String serverId, List<String> roleIdList, String text) throws Exception {
+    private CpSendMsgResultDTO cpSendMsgApi(GameSupper gameSupper, String msgId, String serverId, String text,
+                                            List<String> roleIdList) throws Exception {
         long time = System.currentTimeMillis() / 1000;
         Map<String, Object> param = new HashMap<>(8);
         param.put("msgId", msgId);
         param.put("strRan", msgId);
         param.put("time", time);
-        param.put("sign", this.MD5("key=" + CP_API_KEY + "&msgId=" + msgId + "&strRan=" + msgId + "&time=" + time));
+        param.put("sign", this.MD5("key=" + gameSupper.getCpSendMsgKey() + "&msgId=" + msgId + "&strRan=" + msgId + "&time=" + time));
         param.put("pushType", 1);
         param.put("serverid", serverId);
         param.put("roleIds", roleIdList);
@@ -153,8 +173,7 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
         HttpEntity<String> request = new HttpEntity<>(JsonUtil.toString(param), headers);
         String result;
         try {
-            result = restTemplate.postForObject("https://ht.lttx.t5yx.cn/extapi?action=BgzszhSendTip",
-                    request, String.class);
+            result = restTemplate.postForObject(gameSupper.getCpSendMsgUrl(), request, String.class);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new BaseException("消息发送失败");

+ 10 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameSupper.java

@@ -40,6 +40,16 @@ public class GameSupper implements Serializable {
      */
     private String name;
 
+    /**
+     * CP发消息地址
+     */
+    private String cpSendMsgUrl;
+
+    /**
+     * CP发消息key
+     */
+    private String cpSendMsgKey;
+
     /**
      * 1 删除  0 正常
      */