Преглед изворни кода

fix : 小程序登录信息上报修改05

bilingfeng пре 11 месеци
родитељ
комит
eeebce0e84

+ 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服务启动成功 < (新链路小程序登录信息上报04´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (新链路小程序登录信息上报5´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 2 - 2
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/api/CpServerApiService.java

@@ -126,8 +126,8 @@ public class CpServerApiService {
     private void signCheck(String cpServerKey, Long gameId, String serverId, Long signTime, String sign) {
         String signStr = "cpServerKey=" + cpServerKey + "gameId=" + gameId
                 + "serverId=" + serverId + "signTime=" + signTime;
-        String mySign = SignUtil.md5(signStr, Boolean.TRUE);
-        if (Objects.equals(mySign, sign)) {
+        String mySign = SignUtil.md5(signStr);
+        if (!Objects.equals(mySign.toUpperCase(), sign.toUpperCase())) {
             log.error("加密验证失败, sign : {}, mySign : {}", sign, mySign);
             throw new BaseException("加密标识错误");
         }

+ 3 - 17
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/CpSendMsgLogServiceImpl.java

@@ -8,6 +8,7 @@ import com.zanxiang.game.module.manage.enums.CpSendRoleResultEnum;
 import com.zanxiang.game.module.manage.pojo.dto.CpSendMsgResultDTO;
 import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
 import com.zanxiang.game.module.manage.service.*;
+import com.zanxiang.game.module.manage.utils.SignUtil;
 import com.zanxiang.game.module.mybatis.entity.CpSendMsgLog;
 import com.zanxiang.game.module.mybatis.entity.CpSendMsgResult;
 import com.zanxiang.game.module.mybatis.entity.GameSupper;
@@ -25,8 +26,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.support.TransactionTemplate;
 import org.springframework.web.client.RestTemplate;
 
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -40,8 +39,6 @@ import java.util.stream.Collectors;
 @Service
 public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpSendMsgLog> implements ICpSendMsgLogService {
 
-    private static final String SIGN_MD5 = "MD5";
-
     @Autowired
     private TransactionTemplate transactionTemplate;
 
@@ -149,14 +146,13 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
                 .build();
     }
 
-    private CpSendMsgResultDTO cpSendMsgApi(GameSupper gameSupper, String msgId, String serverId, String text,
-                                            List<String> roleIdList) throws Exception {
+    private CpSendMsgResultDTO cpSendMsgApi(GameSupper gameSupper, String msgId, String serverId, String text, List<String> roleIdList) {
         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=" + gameSupper.getCpSendMsgKey() + "&msgId=" + msgId + "&strRan=" + msgId + "&time=" + time));
+        param.put("sign", SignUtil.md5("key=" + gameSupper.getCpSendMsgKey() + "&msgId=" + msgId + "&strRan=" + msgId + "&time=" + time));
         param.put("pushType", 1);
         param.put("serverid", serverId);
         param.put("roleIds", roleIdList);
@@ -180,14 +176,4 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
         }
         return JsonUtil.toObj(result, CpSendMsgResultDTO.class);
     }
-
-    private String MD5(String data) throws Exception {
-        java.security.MessageDigest md = MessageDigest.getInstance(SIGN_MD5);
-        byte[] array = md.digest(data.getBytes(StandardCharsets.UTF_8));
-        StringBuilder sb = new StringBuilder();
-        for (byte item : array) {
-            sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3);
-        }
-        return sb.toString();
-    }
 }

+ 2 - 3
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/UserAppletServiceImpl.java

@@ -75,9 +75,8 @@ public class UserAppletServiceImpl extends ServiceImpl<UserAppletMapper, UserApp
     private void signCheck(String loginKey, UserAppletSubmitParam param) {
         String signStr = "loginKey=" + loginKey + "appId=" + param.getAppId()
                 + "code=" + param.getCode() + "signTime=" + param.getSignTime();
-        log.error("加密字符串 : signStr : {}", signStr);
-        String mySign = SignUtil.md5(signStr, Boolean.TRUE);
-        if (Objects.equals(mySign, param.getSign())) {
+        String mySign = SignUtil.md5(signStr);
+        if (!Objects.equals(mySign.toUpperCase(), param.getSign().toUpperCase())) {
             log.error("加密验证失败, sign : {}, mySign : {}", param.getSign(), mySign);
             throw new BaseException("加密标识错误");
         }

+ 2 - 2
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/utils/SignUtil.java

@@ -20,7 +20,7 @@ public class SignUtil {
      * @param data 待处理数据
      * @return MD5结果
      */
-    public static String md5(String data, boolean upperCase) {
+    public static String md5(String data) {
         try {
             java.security.MessageDigest md = MessageDigest.getInstance("MD5");
             byte[] array = md.digest(data.getBytes(StandardCharsets.UTF_8));
@@ -28,7 +28,7 @@ public class SignUtil {
             for (byte item : array) {
                 sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3);
             }
-            return upperCase ? sb.toString().toUpperCase() : sb.toString();
+            return sb.toString();
         } catch (Exception e) {
             log.error("MD5加密异常, data : {}", data);
             throw new BaseException("MD5加密异常");