Browse Source

Merge branch 'package' of GameCenter/game-center into dev

zhimo 4 months ago
parent
commit
9a648ec1c3

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <腾讯媒体sdk测试修改200> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <腾讯媒体sdk测试修改2002> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +
                 "\\ `--.| | | | |/ / \n" +

+ 19 - 7
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameBackLogMediaSdkServiceImpl.java

@@ -14,6 +14,7 @@ import com.zanxiang.game.back.base.rpc.IGameBackPolicyRpc;
 import com.zanxiang.game.back.base.rpc.ITencentMiniGameBackRpc;
 import com.zanxiang.game.back.base.rpc.ITencentMiniGameBackRpc;
 import com.zanxiang.game.back.base.rpc.ITtAppBackRpc;
 import com.zanxiang.game.back.base.rpc.ITtAppBackRpc;
 import com.zanxiang.game.module.base.pojo.enums.AccountTypeEnum;
 import com.zanxiang.game.module.base.pojo.enums.AccountTypeEnum;
+import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
 import com.zanxiang.game.module.mybatis.entity.*;
 import com.zanxiang.game.module.mybatis.entity.*;
 import com.zanxiang.game.module.mybatis.mapper.GameBackLogMediaSdkMapper;
 import com.zanxiang.game.module.mybatis.mapper.GameBackLogMediaSdkMapper;
 import com.zanxiang.game.module.sdk.constant.RedisKeyConstant;
 import com.zanxiang.game.module.sdk.constant.RedisKeyConstant;
@@ -31,6 +32,7 @@ import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.LocalTime;
@@ -93,11 +95,11 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
         }
         }
         //判断结果返回对象
         //判断结果返回对象
         Map<String, Object> resultMap = this.getResultMap(param, userData);
         Map<String, Object> resultMap = this.getResultMap(param, userData);
-        //参数判断, 检测不通过
-        if (!this.callBackParamCheck(param, resultMap)) {
-            return resultMap;
-        }
         try {
         try {
+            //参数判断, 检测不通过
+            if (!this.callBackParamCheck(param, resultMap)) {
+                return resultMap;
+            }
             //查询玩家信息
             //查询玩家信息
             User user = userService.getById(userData.getUserId());
             User user = userService.getById(userData.getUserId());
             //测试账号判断
             //测试账号判断
@@ -116,8 +118,9 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
                     JsonUtil.toString(userData), e.getMessage(), e);
                     JsonUtil.toString(userData), e.getMessage(), e);
             resultMap.put("backMsg", "事件回传判断, 出现异常");
             resultMap.put("backMsg", "事件回传判断, 出现异常");
         } finally {
         } finally {
-            //等级提升以外的事件释放锁, 等级变化20秒以内不更新, 不回传, 因为包含了战力变化
-            if (!Objects.equals(param.getCallBackTypeEnum(), CallBackTypeEnum.CALL_BACK_UPDATE_LEVEL)) {
+            //等级提升和订单付费, 不释放锁, 其他事件锁释放
+            if (!Objects.equals(param.getCallBackTypeEnum(), CallBackTypeEnum.CALL_BACK_UPDATE_LEVEL)
+                    && !Objects.equals(param.getCallBackTypeEnum(), CallBackTypeEnum.CALL_BACK_PAY_ORDER)) {
                 distributedLockComponent.unlock(lockKey);
                 distributedLockComponent.unlock(lockKey);
             }
             }
         }
         }
@@ -237,9 +240,18 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
         //判断是否订单付费回传, 添加回传金额
         //判断是否订单付费回传, 添加回传金额
         if (Objects.equals(callBackTypeEnum, CallBackTypeEnum.CALL_BACK_PAY_ORDER) && Strings.isNotBlank(param.getOrderId())) {
         if (Objects.equals(callBackTypeEnum, CallBackTypeEnum.CALL_BACK_PAY_ORDER) && Strings.isNotBlank(param.getOrderId())) {
             PlatformOrderDTO platformOrderDTO = orderService.getByOrderId(param.getOrderId());
             PlatformOrderDTO platformOrderDTO = orderService.getByOrderId(param.getOrderId());
-            if (platformOrderDTO != null) {
+            if (platformOrderDTO == null || platformOrderDTO.getAmount() == null) {
+                return false;
+            }
+            //头条APP媒体回传, 返回的单位是元
+            if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())) {
                 resultMap.put("amount", Collections.singletonList(platformOrderDTO.getAmount().intValue()));
                 resultMap.put("amount", Collections.singletonList(platformOrderDTO.getAmount().intValue()));
             }
             }
+            //腾讯小游戏媒体SDK回传, 返回的单位是分, 乘以100
+            if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getId())) {
+                int amount = platformOrderDTO.getAmount().multiply(new BigDecimal(100)).intValue();
+                resultMap.put("amount", Collections.singletonList(amount));
+            }
         }
         }
         //返回结果
         //返回结果
         return true;
         return true;

+ 33 - 9
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameServiceImpl.java

@@ -5,10 +5,12 @@ import com.zanxiang.game.module.base.pojo.enums.AccountTypeEnum;
 import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
 import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
 import com.zanxiang.game.module.mybatis.entity.Agent;
 import com.zanxiang.game.module.mybatis.entity.Agent;
 import com.zanxiang.game.module.mybatis.entity.Game;
 import com.zanxiang.game.module.mybatis.entity.Game;
+import com.zanxiang.game.module.mybatis.entity.User;
 import com.zanxiang.game.module.mybatis.mapper.GameMapper;
 import com.zanxiang.game.module.mybatis.mapper.GameMapper;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
 import com.zanxiang.game.module.sdk.service.IAgentService;
 import com.zanxiang.game.module.sdk.service.IAgentService;
 import com.zanxiang.game.module.sdk.service.IGameService;
 import com.zanxiang.game.module.sdk.service.IGameService;
+import com.zanxiang.game.module.sdk.service.IUserService;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.JsonUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.logging.log4j.util.Strings;
 import org.apache.logging.log4j.util.Strings;
@@ -31,6 +33,9 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements IG
     @Autowired
     @Autowired
     private IAgentService agentService;
     private IAgentService agentService;
 
 
+    @Autowired
+    private IUserService userService;
+
     @Override
     @Override
     public Map<String, Object> getAdSdkConfig(UserData userData) {
     public Map<String, Object> getAdSdkConfig(UserData userData) {
         Game game = super.getById(userData.getGameId());
         Game game = super.getById(userData.getGameId());
@@ -41,20 +46,39 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements IG
         if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())) {
         if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())) {
             return JsonUtil.toMap(game.getAdSdkConfig(), Map.class, Object.class);
             return JsonUtil.toMap(game.getAdSdkConfig(), Map.class, Object.class);
         }
         }
-        //微信小游戏, 根据channel, 判断当前是投的腾讯还是头条
-        if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getId())) {
-            //当前调试阶段
-            if (Objects.equals(game.getStatus(), 2)) {
+        //不是微信小程序, 不返回配置
+        if (!Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getId())) {
+            //默认返回不初始化
+            return Collections.singletonMap("adSdk", 0);
+        }
+        //目前只有投腾讯才返回
+        Agent agent = this.getUserAgent(userData.getUserId());
+        if (agent != null) {
+            //腾讯广告
+            if (Objects.equals(agent.getAccountType(), AccountTypeEnum.TENCENT_MINI_GAME.getValue())) {
                 return JsonUtil.toMap(game.getAdSdkConfig(), Map.class, Object.class);
                 return JsonUtil.toMap(game.getAdSdkConfig(), Map.class, Object.class);
             }
             }
-            //非调试阶段, 目前只有投腾讯才返回
-            Map<String, String> urlParamMap = agentService.channelTransform(userData.getChannel());
-            Agent agent = agentService.getAgentByKey(urlParamMap);
-            if (agent != null && Objects.equals(agent.getAccountType(), AccountTypeEnum.TENCENT_MINI_GAME.getValue())) {
-                return JsonUtil.toMap(game.getAdSdkConfig(), Map.class, Object.class);
+            //头条广告
+            if (Objects.equals(agent.getAccountType(), AccountTypeEnum.BYTE.getValue())) {
+                return Collections.singletonMap("adSdk", 0);
             }
             }
         }
         }
+        //当前调试阶段
+        if (userData.getUserId() != null && Objects.equals(game.getStatus(), 2)) {
+            return JsonUtil.toMap(game.getAdSdkConfig(), Map.class, Object.class);
+        }
         //默认返回不初始化
         //默认返回不初始化
         return Collections.singletonMap("adSdk", 0);
         return Collections.singletonMap("adSdk", 0);
     }
     }
+
+    private Agent getUserAgent(Long userId) {
+        if (userId == null) {
+            return null;
+        }
+        User user = userService.getById(userId);
+        if (user == null) {
+            return null;
+        }
+        return agentService.getById(user.getAgentId());
+    }
 }
 }