|
@@ -4,18 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.zanxiang.game.back.base.ServerInfo;
|
|
|
import com.zanxiang.game.back.base.pojo.dto.*;
|
|
|
-import com.zanxiang.game.back.base.pojo.vo.OrderBackQueryRpcVO;
|
|
|
import com.zanxiang.game.back.base.rpc.*;
|
|
|
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.sdk.constant.RedisKeyConstant;
|
|
|
-import com.zanxiang.game.module.sdk.enums.CallBackTypeEnum;
|
|
|
import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
|
|
|
-import com.zanxiang.game.module.sdk.pojo.param.CallBackControlParam;
|
|
|
-import com.zanxiang.game.module.sdk.pojo.param.UserData;
|
|
|
import com.zanxiang.game.module.sdk.service.*;
|
|
|
-import com.zanxiang.module.redis.service.IDistributedLockComponent;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
@@ -25,14 +19,13 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @author : lingfeng
|
|
|
* @time : 2022-11-10
|
|
|
- * @description : 回传
|
|
|
+ * @description : IAP游戏SDK回传方法
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
@@ -68,137 +61,9 @@ public class CallBackServiceImpl implements ICallBackService {
|
|
|
@Autowired
|
|
|
private IGameExtService gameExtService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IOrderService orderService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IGameBackLogService gameBackLogService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IDistributedLockComponent distributedLockComponent;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IUserEventService userEventService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, Object> callBackJudge(CallBackControlParam param, UserData userData) {
|
|
|
- log.error("事件回传判断请求, param : {}, userData : {}", JsonUtil.toString(param), JsonUtil.toString(userData));
|
|
|
- Map<String, Object> resultMap = new HashMap<>(7);
|
|
|
- resultMap.put("callBackTypeEnum", param.getCallBackTypeEnum().getValue());
|
|
|
- resultMap.put("userId", userData.getUserId());
|
|
|
- resultMap.put("gameId", userData.getGameId());
|
|
|
- //事件类型枚举
|
|
|
- CallBackTypeEnum callBackTypeEnum = param.getCallBackTypeEnum();
|
|
|
- Game game = gameService.getById(userData.getGameId());
|
|
|
- //判断游戏状态, 对接上包过程中, 全量回传
|
|
|
- if (this.isUserEvent(game, userData.getUserId())) {
|
|
|
- resultMap.put("callBack", Boolean.TRUE);
|
|
|
- if (Objects.equals(callBackTypeEnum, CallBackTypeEnum.CALL_BACK_PAY_ORDER)) {
|
|
|
- PlatformOrderDTO platformOrderDTO = orderService.getByOrderId(param.getOrderId());
|
|
|
- if (platformOrderDTO != null) {
|
|
|
- resultMap.put("amount", Collections.singletonList(platformOrderDTO.getAmount().intValue()));
|
|
|
- }
|
|
|
- }
|
|
|
- return resultMap;
|
|
|
- }
|
|
|
- //线程锁
|
|
|
- String lockKey = RedisKeyConstant.CALL_BACK_JUDGE_LOCK + callBackTypeEnum.getValue() + "_" + userData.getUserId();
|
|
|
- if (Objects.equals(callBackTypeEnum, CallBackTypeEnum.CALL_BACK_ACTIVATE)) {
|
|
|
- lockKey = lockKey + "_" + param.getRoleId();
|
|
|
- }
|
|
|
- if (Objects.equals(callBackTypeEnum, CallBackTypeEnum.CALL_BACK_PAY_ORDER)) {
|
|
|
- lockKey = lockKey + "_" + param.getOrderId();
|
|
|
- }
|
|
|
- //上锁
|
|
|
- if (!distributedLockComponent.doLock(lockKey, 0L, 1L, TimeUnit.MINUTES)) {
|
|
|
- log.error("重复请求触发线程锁, 直接返回false, lockKey : {}", lockKey);
|
|
|
- resultMap.put("callBack", Boolean.FALSE);
|
|
|
- return resultMap;
|
|
|
- }
|
|
|
- //查询玩家
|
|
|
- User user = userService.getById(userData.getUserId());
|
|
|
- //不存在渠道
|
|
|
- Agent agent = agentService.getById(user.getAgentId());
|
|
|
- if (agent == null) {
|
|
|
- resultMap.put("callBack", Boolean.FALSE);
|
|
|
- return resultMap;
|
|
|
- }
|
|
|
- //判断回传
|
|
|
- try {
|
|
|
- this.checkCallBack(user.getId(), agent, callBackTypeEnum, resultMap, param);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("事件回传判断, 出现异常, param : {}, userData : {}, e : {}", JsonUtil.toString(param),
|
|
|
- JsonUtil.toString(userData), e.getMessage(), e);
|
|
|
- resultMap.put("callBack", Boolean.FALSE);
|
|
|
- }
|
|
|
- //返回结果
|
|
|
- return resultMap;
|
|
|
- }
|
|
|
-
|
|
|
- private boolean isUserEvent(Game game, Long userId) {
|
|
|
- if (Objects.equals(game.getStatus(), 2)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- //查询玩家
|
|
|
- User user = userService.getById(userId);
|
|
|
- //判断是否测试过事件用户
|
|
|
- return userEventService.count(new LambdaQueryWrapper<UserEvent>()
|
|
|
- .eq(UserEvent::getGameId, game.getId())
|
|
|
- .and(qw -> qw.eq(UserEvent::getUsername, user.getUsername())
|
|
|
- .or().eq(UserEvent::getMobile, user.getMobile())
|
|
|
- )
|
|
|
- ) > 0;
|
|
|
- }
|
|
|
-
|
|
|
- private void checkCallBack(Long userId, Agent agent, CallBackTypeEnum callBackTypeEnum, Map<String, Object> resultMap,
|
|
|
- CallBackControlParam param) {
|
|
|
- switch (callBackTypeEnum) {
|
|
|
- case CALL_BACK_REGISTER:
|
|
|
- // 注册
|
|
|
- TtAppUserBackQueryRpcDTO userTransform = this.transform(userId, agent);
|
|
|
- resultMap.put("callBack", ttAppBackRpc.userBackQuery(userTransform).getData());
|
|
|
- break;
|
|
|
- case CALL_BACK_LOGIN_IN:
|
|
|
- // 登录
|
|
|
- resultMap.put("callBack", Boolean.FALSE);
|
|
|
- break;
|
|
|
- case CALL_BACK_ACTIVATE:
|
|
|
- // 激活(创角)
|
|
|
- if (Strings.isBlank(param.getRoleId())) {
|
|
|
- resultMap.put("callBack", Boolean.FALSE);
|
|
|
- resultMap.put("roleId", "unknown");
|
|
|
- break;
|
|
|
- }
|
|
|
- TtAppRoleRegisterBackQueryRpcDTO roleTransform = this.transform(userId, agent, param.getRoleId());
|
|
|
- resultMap.put("roleId", param.getRoleId());
|
|
|
- resultMap.put("callBack", ttAppBackRpc.roleRegisterBackQuery(roleTransform).getData());
|
|
|
- break;
|
|
|
- case CALL_BACK_PAY_ORDER:
|
|
|
- // 支付
|
|
|
- if (Strings.isBlank(param.getOrderId())) {
|
|
|
- resultMap.put("callBack", Boolean.FALSE);
|
|
|
- resultMap.put("orderId", "unknown");
|
|
|
- break;
|
|
|
- }
|
|
|
- TtAppOrderBackQueryRpcDTO orderTransform = this.transform(userId, param.getOrderId(), agent);
|
|
|
- OrderBackQueryRpcVO orderBackQueryRpcVO = ttAppBackRpc.orderBackQuery(orderTransform).getData();
|
|
|
- resultMap.put("orderId", param.getOrderId());
|
|
|
- resultMap.put("callBack", orderBackQueryRpcVO.getDoBack());
|
|
|
- resultMap.put("backMsg", orderBackQueryRpcVO.getBackMsg());
|
|
|
- if (Objects.equals(orderBackQueryRpcVO.getDoBack(), Boolean.TRUE)) {
|
|
|
- //传过来的金额是分, 换算成元, 存在小数直接舍弃
|
|
|
- List<Long> backMoney = orderBackQueryRpcVO.getBackMoney()
|
|
|
- .stream().map(money -> money / 100)
|
|
|
- .collect(Collectors.toList());
|
|
|
- resultMap.put("amount", backMoney);
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- // 处理未知类型
|
|
|
- resultMap.put("callBack", Boolean.FALSE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void userCallBack(User user, Map<String, String> urlParamMap) {
|
|
|
//判断游戏是否开启广告回传, 未开启, 不回传
|
|
@@ -266,17 +131,18 @@ public class CallBackServiceImpl implements ICallBackService {
|
|
|
//解析设置clickId
|
|
|
Map<String, String> channelMap = agentService.channelTransform(user.getChannel());
|
|
|
tencentUserDTO.setClickId(channelMap.get("gdt_vid"));
|
|
|
- //没有配置媒体SDK, 执行API回传
|
|
|
- String describe;
|
|
|
- if (Strings.isBlank(game.getAdSdkConfig())) {
|
|
|
+ //判断API回传开关是否关掉, 未设置关掉, 则执行API回传
|
|
|
+ if (game.getApiBackSwitch() == null || game.getApiBackSwitch()) {
|
|
|
tencentMiniGameBackRpc.backUser(tencentUserDTO);
|
|
|
- describe = "腾讯小游戏用户回传提交";
|
|
|
- } else {
|
|
|
- //执行媒体SDK回传
|
|
|
+ gameBackLogService.addLog(user.getId(), null, "腾讯小游戏用户回传提交",
|
|
|
+ JsonUtil.toString(tencentUserDTO));
|
|
|
+ }
|
|
|
+ //判断是否配置了媒体SDK, 配置了则执行媒体SDK回传
|
|
|
+ if (Strings.isNotBlank(game.getAdSdkConfig())) {
|
|
|
tencentMiniGameBackRpc.callBackUser(tencentUserDTO);
|
|
|
- describe = "腾讯小游戏用户媒体SDK回传提交";
|
|
|
+ gameBackLogService.addLog(user.getId(), null, "腾讯小游戏用户媒体SDK回传提交",
|
|
|
+ JsonUtil.toString(tencentUserDTO));
|
|
|
}
|
|
|
- gameBackLogService.addLog(user.getId(), null, describe, JsonUtil.toString(tencentUserDTO));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -339,16 +205,18 @@ public class CallBackServiceImpl implements ICallBackService {
|
|
|
//查询游戏信息
|
|
|
Game game = gameService.getById(agent.getGameId());
|
|
|
TencentRoleRegisterRpcDTO tencentRoleRegisterRpcDTO = this.transform(user, agent, gameApplet, gameUserRole);
|
|
|
- //没有配置媒体SDK, 执行API回传
|
|
|
- String describe;
|
|
|
- if (Strings.isBlank(game.getAdSdkConfig())) {
|
|
|
+ //判断API回传开关是否关掉, 未设置关掉, 则执行API回传
|
|
|
+ if (game.getApiBackSwitch() == null || game.getApiBackSwitch()) {
|
|
|
tencentMiniGameBackRpc.backRoleRegister(tencentRoleRegisterRpcDTO);
|
|
|
- describe = "腾讯小游戏创角回传提交";
|
|
|
- } else {
|
|
|
+ gameBackLogService.addLog(user.getId(), gameUserRole.getRoleId(), "腾讯小游戏创角回传提交",
|
|
|
+ JsonUtil.toString(tencentRoleRegisterRpcDTO));
|
|
|
+ }
|
|
|
+ //判断是否配置了媒体SDK, 配置了则执行媒体SDK回传
|
|
|
+ if (Strings.isNotBlank(game.getAdSdkConfig())) {
|
|
|
tencentMiniGameBackRpc.callBackRole(tencentRoleRegisterRpcDTO);
|
|
|
- describe = "腾讯小游戏创角媒体SDK回传提交";
|
|
|
+ gameBackLogService.addLog(user.getId(), gameUserRole.getRoleId(), "腾讯小游戏创角媒体SDK回传提交",
|
|
|
+ JsonUtil.toString(tencentRoleRegisterRpcDTO));
|
|
|
}
|
|
|
- gameBackLogService.addLog(user.getId(), gameUserRole.getRoleId(), describe, JsonUtil.toString(tencentRoleRegisterRpcDTO));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -415,16 +283,18 @@ public class CallBackServiceImpl implements ICallBackService {
|
|
|
//解析设置clickId
|
|
|
Map<String, String> channelMap = agentService.channelTransform(user.getChannel());
|
|
|
tencentOrderDTO.setClickId(channelMap.get("gdt_vid"));
|
|
|
- //没有配置媒体SDK, 执行API回传
|
|
|
- String describe;
|
|
|
- if (Strings.isBlank(game.getAdSdkConfig())) {
|
|
|
+ //判断API回传开关是否关掉, 未设置关掉, 则执行API回传
|
|
|
+ if (game.getApiBackSwitch() == null || game.getApiBackSwitch()) {
|
|
|
tencentMiniGameBackRpc.backOrder(tencentOrderDTO);
|
|
|
- describe = "腾讯小游戏订单回传提交";
|
|
|
- } else {
|
|
|
+ gameBackLogService.addLog(user.getId(), platformOrderDTO.getOrderId(), "腾讯小游戏订单回传提交",
|
|
|
+ JsonUtil.toString(tencentOrderDTO));
|
|
|
+ }
|
|
|
+ //判断是否配置了媒体SDK, 配置了则执行媒体SDK回传
|
|
|
+ if (Strings.isNotBlank(game.getAdSdkConfig())) {
|
|
|
tencentMiniGameBackRpc.callBackOrder(tencentOrderDTO);
|
|
|
- describe = "腾讯小游戏订单媒体SDK回传提交";
|
|
|
+ gameBackLogService.addLog(user.getId(), platformOrderDTO.getOrderId(), "腾讯小游戏订单媒体SDK回传提交",
|
|
|
+ JsonUtil.toString(tencentOrderDTO));
|
|
|
}
|
|
|
- gameBackLogService.addLog(user.getId(), platformOrderDTO.getOrderId(), describe, JsonUtil.toString(tencentOrderDTO));
|
|
|
}
|
|
|
|
|
|
private TencentRoleRegisterRpcDTO transform(User user, Agent agent, GameApplet gameApplet, GameUserRole gameUserRole) {
|