|
@@ -1,11 +1,30 @@
|
|
|
package com.zanxiang.game.module.sdk.service.impl;
|
|
|
|
|
|
-import com.zanxiang.game.module.sdk.service.ICallBackService;
|
|
|
-import com.zanxiang.game.module.sdk.service.IOrderService;
|
|
|
-import com.zanxiang.game.module.sdk.service.IUserService;
|
|
|
+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.oceanengine.pojo.dto.AccountReportRpcDTO;
|
|
|
+import com.zanxiang.game.back.base.oceanengine.pojo.dto.OrderReportRpcDTO;
|
|
|
+import com.zanxiang.game.back.base.oceanengine.pojo.dto.UserActiveReportRpcDTO;
|
|
|
+import com.zanxiang.game.back.base.oceanengine.rpc.IWechatMiniGameDataReportRpc;
|
|
|
+import com.zanxiang.game.back.base.tencent.pojo.dto.TencentOrderDTO;
|
|
|
+import com.zanxiang.game.back.base.tencent.pojo.dto.TencentUserDTO;
|
|
|
+import com.zanxiang.game.back.base.tencent.rpc.IGameBackTencentRpc;
|
|
|
+import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.Agent;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.Game;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameApplet;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.User;
|
|
|
+import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
|
|
|
+import com.zanxiang.game.module.sdk.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import reactor.util.function.Tuple2;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @author : lingfeng
|
|
@@ -16,93 +35,160 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class CallBackServiceImpl implements ICallBackService {
|
|
|
|
|
|
+ @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
|
|
|
+ private IGameBackTencentRpc gameBackTencentRpc;
|
|
|
+
|
|
|
+ @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
|
|
|
+ private IWechatMiniGameDataReportRpc wechatMiniGameDataReportRpc;
|
|
|
+
|
|
|
@Autowired
|
|
|
- private IUserService userService;
|
|
|
+ private IAgentService agentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameService gameService;
|
|
|
|
|
|
@Autowired
|
|
|
- private IOrderService orderService;
|
|
|
+ private IGameAppletService gameAppletService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void userCallBack(User user, Tuple2<Long, Map<String, String>> tuple2) {
|
|
|
+ Long agentId = tuple2.getT1();
|
|
|
+ Map<String, String> urlParamMap = tuple2.getT2();
|
|
|
+ //自然量, 或者跳转链接参数不存在, 不做回传处理
|
|
|
+ if (agentId == 0L || CollectionUtils.isEmpty(urlParamMap)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //查询用户渠道信息
|
|
|
+ Agent agent = agentService.getById(user.getAgentId());
|
|
|
+ if (agent == null) {
|
|
|
+ log.error("用户回传不存在渠道信息, userId : {}", user.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //查询小游戏信息或者H5游戏相关公众号信息
|
|
|
+ GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>()
|
|
|
+ .eq(GameApplet::getGameId, user.getGameId()));
|
|
|
+ try {
|
|
|
+ //腾讯回传
|
|
|
+ if (Objects.equals(agent.getAccountType(), Agent.ACCOUNT_TYPE_TENCENT)) {
|
|
|
+ TencentUserDTO tencentUserDTO = this.transform(user, agent, gameApplet);
|
|
|
+ gameBackTencentRpc.backUser(tencentUserDTO);
|
|
|
+ }
|
|
|
+ //头条回传
|
|
|
+ if (CollectionUtils.isNotEmpty(urlParamMap) && Objects.equals(agent.getAccountType(), Agent.ACCOUNT_TYPE_BYTE)) {
|
|
|
+ Game game = gameService.getById(user.getGameId());
|
|
|
+ //判断是微信小游戏
|
|
|
+ if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getCategory())) {
|
|
|
+ UserActiveReportRpcDTO activeReportRpcDTO = this.transform(user, agent, gameApplet, urlParamMap);
|
|
|
+ wechatMiniGameDataReportRpc.userActiveReport(activeReportRpcDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("用户回传异常, userId : {}, e : {}", user.getId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void orderCallBack(PlatformOrderDTO platformOrderDTO) {
|
|
|
+ //查询用户渠道信息
|
|
|
+ Agent agent = agentService.getById(platformOrderDTO.getAgentId());
|
|
|
+ if (agent == null) {
|
|
|
+ log.error("订单回传不存在渠道信息, orderId : {}", platformOrderDTO.getOrderId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ User user = userService.getById(platformOrderDTO.getUserId());
|
|
|
+ //查询小游戏信息或者H5游戏相关公众号信息
|
|
|
+ GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>()
|
|
|
+ .eq(GameApplet::getGameId, user.getGameId()));
|
|
|
+ try {
|
|
|
+ //腾讯回传
|
|
|
+ if (Objects.equals(agent.getAccountType(), Agent.ACCOUNT_TYPE_TENCENT)) {
|
|
|
+ TencentOrderDTO tencentOrderDTO = this.transform(platformOrderDTO, user, agent, gameApplet);
|
|
|
+ gameBackTencentRpc.backOrder(tencentOrderDTO);
|
|
|
+ }
|
|
|
+ //头条回传
|
|
|
+ if (Objects.equals(agent.getAccountType(), Agent.ACCOUNT_TYPE_BYTE)) {
|
|
|
+ //判断游戏类型
|
|
|
+ Game game = gameService.getById(platformOrderDTO.getGameId());
|
|
|
+ if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getCategory())) {
|
|
|
+ OrderReportRpcDTO orderReportRpcDTO = this.transform(platformOrderDTO, user.getOpenId(), agent, gameApplet);
|
|
|
+ wechatMiniGameDataReportRpc.orderReport(orderReportRpcDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("订单回传异常, orderId : {}, e : {}", platformOrderDTO.getOrderId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private TencentUserDTO transform(User user, Agent agent, GameApplet gameApplet) {
|
|
|
+ return TencentUserDTO.builder()
|
|
|
+ .gameId(user.getGameId())
|
|
|
+ .adAccountId(agent.getAccountId())
|
|
|
+ .registerTime(user.getCreateTime())
|
|
|
+ .channel(agent.getAgentKey())
|
|
|
+ .wechatOpenid(user.getOpenId())
|
|
|
+ .wechatAppId(gameApplet == null ? null : gameApplet.getAppId())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
|
|
|
+ private UserActiveReportRpcDTO transform(User user, Agent agent, GameApplet gameApplet, Map<String, String> urlParamMap) {
|
|
|
+ AccountReportRpcDTO accountReportRpcDTO = AccountReportRpcDTO.builder()
|
|
|
+ .accountId(agent.getAccountId())
|
|
|
+ .reportToken(agent.getReportToken())
|
|
|
+ .reportUrl(agent.getReportUrl())
|
|
|
+ .build();
|
|
|
+ return UserActiveReportRpcDTO.builder()
|
|
|
+ .gameId(user.getGameId())
|
|
|
+ .wechatAppId(gameApplet == null ? null : gameApplet.getAppId())
|
|
|
+ .wechatOpenId(user.getOpenId())
|
|
|
+ .accountReport(accountReportRpcDTO)
|
|
|
+ .agentKey(agent.getAgentKey())
|
|
|
+ .activeTime(user.getCreateTime())
|
|
|
+ .clueToken(urlParamMap.get("clue_token"))
|
|
|
+ .projectId(urlParamMap.get("project_id") == null ? null : Long.valueOf(urlParamMap.get("project_id")))
|
|
|
+ .promotionId(urlParamMap.get("promotion_id") == null ? null : Long.valueOf(urlParamMap.get("promotion_id")))
|
|
|
+ .advertiserId(urlParamMap.get("advertiser_id") == null ? null : Long.valueOf(urlParamMap.get("advertiser_id")))
|
|
|
+ .reqId(urlParamMap.get("req_id"))
|
|
|
+ .build();
|
|
|
+ }
|
|
|
|
|
|
-// @DubboReference(providedBy = PlatformServer.SERVER_DUBBO_NAME)
|
|
|
-// private IAppUserRpc appUserRpc;
|
|
|
-//
|
|
|
-// @DubboReference(providedBy = PlatformServer.SERVER_DUBBO_NAME)
|
|
|
-// private IAppOrderRpc appOrderRpc;
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void userCallBack(User user) {
|
|
|
-// if (user == null) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// log.error("用户注册回传, userId : {}", user.getId());
|
|
|
-// UserRegisterRpcDTO dto = UserRegisterRpcDTO.builder()
|
|
|
-// .appKey(String.valueOf(user.getGameId()))
|
|
|
-// .userId(String.valueOf(user.getId()))
|
|
|
-// .username(user.getUsername())
|
|
|
-// .mac(user.getMac())
|
|
|
-// .imei(user.getImei())
|
|
|
-// .androidId(user.getAndroidId())
|
|
|
-// .ip(user.getIp())
|
|
|
-// .osType(OsEnum.getByName(user.getDeviceSystem()))
|
|
|
-// .registerTime(user.getCreateTime())
|
|
|
-// .build();
|
|
|
-// //调接口
|
|
|
-// ResultVO<AppReportLogRpcVO> result;
|
|
|
-// try {
|
|
|
-// result = appUserRpc.register(dto);
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.error("用户注册回传上报异常, user : {}, e : {}", JsonUtil.toString(user), e.getMessage());
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// log.error("用户注册回传结果, userId : {}, result : {}", user.getId(), JsonUtil.toString(result));
|
|
|
-// String adId = "AD_ID";
|
|
|
-// //成功
|
|
|
-// if (result.isSuccess() && result.getData() != null && result.getData().getAid() != null) {
|
|
|
-// adId = result.getData().getAid().toString();
|
|
|
-// }
|
|
|
-// //更新数据库
|
|
|
-// userService.update(new LambdaUpdateWrapper<User>().set(User::getAdId, adId).eq(User::getId, user.getId()));
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void orderCallBack(PlatformOrderDTO orderInfo) {
|
|
|
-// if (orderInfo == null) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// log.error("用户注册回传, orderId : {}", orderInfo.getOrderId());
|
|
|
-// AppOrderRpcDTO dto = AppOrderRpcDTO.builder()
|
|
|
-// .appKey(String.valueOf(orderInfo.getGameId()))
|
|
|
-// .orderId(orderInfo.getOrderId())
|
|
|
-// .userId(String.valueOf(orderInfo.getUserId()))
|
|
|
-// .amount(orderInfo.getAmount().multiply(new BigDecimal("100")).longValue())
|
|
|
-// .realAmount(orderInfo.getRealAmount().multiply(new BigDecimal("100")).longValue())
|
|
|
-// .tranNo(orderInfo.getMerchantOrderNo())
|
|
|
-// .orderStatus(orderInfo.getStatus())
|
|
|
-// .payType(PayTypeEnum.getByPayType(orderInfo.getPayWayId()))
|
|
|
-// .payTime(orderInfo.getPayTime())
|
|
|
-// .createTime(orderInfo.getCreateTime())
|
|
|
-// .build();
|
|
|
-// //调接口
|
|
|
-// ResultVO<AppReportLogRpcVO> result;
|
|
|
-// try {
|
|
|
-// result = appOrderRpc.order(dto);
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.error("订单回传上报异常, orderInfo : {}, e : {}", JsonUtil.toString(orderInfo), e.getMessage());
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// log.error("订单回传结果, orderId : {}, result : {}", orderInfo.getOrderId(), JsonUtil.toString(result));
|
|
|
-// String adId = "AD_ID";
|
|
|
-// Integer callBackStatus = CallBackEnum.FAIL_CALL_BACK.getCallBackStatus();
|
|
|
-// //成功
|
|
|
-// if (result.isSuccess() && result.getData() != null && result.getData().getAid() != null) {
|
|
|
-// adId = result.getData().getAid().toString();
|
|
|
-// callBackStatus = CallBackEnum.SUCCESS_CALL_BACK.getCallBackStatus();
|
|
|
-// }
|
|
|
-// //更新数据库
|
|
|
-// orderService.update(new LambdaUpdateWrapper<Order>()
|
|
|
-// .set(Order::getAdId, adId)
|
|
|
-// .set(Order::getCallBackStatus, callBackStatus)
|
|
|
-// .eq(Order::getOrderId, orderInfo.getOrderId()));
|
|
|
-// }
|
|
|
+ private TencentOrderDTO transform(PlatformOrderDTO platformOrderDTO, User user, Agent agent, GameApplet gameApplet) {
|
|
|
+ return TencentOrderDTO.builder()
|
|
|
+ .backPolicyId(agent.getBackPolicyId())
|
|
|
+ .gameId(platformOrderDTO.getGameId())
|
|
|
+ .adAccountId(agent.getAccountId())
|
|
|
+ .registerTime(user.getCreateTime())
|
|
|
+ .rechargeMoney(platformOrderDTO.getAmount().longValue() * 100)
|
|
|
+ .rechargeTime(platformOrderDTO.getCreateTime())
|
|
|
+ .orderId(platformOrderDTO.getOrderId())
|
|
|
+ .channel(agent.getAgentKey())
|
|
|
+ .wechatOpenid(user.getOpenId())
|
|
|
+ .wechatAppId(gameApplet == null ? null : gameApplet.getAppId())
|
|
|
+ .orderStatus(platformOrderDTO.getStatus())
|
|
|
+ .payTime(platformOrderDTO.getPayTime())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
|
|
|
+ private OrderReportRpcDTO transform(PlatformOrderDTO platformOrderDTO, String openId, Agent agent, GameApplet gameApplet) {
|
|
|
+ AccountReportRpcDTO accountReportRpcDTO = AccountReportRpcDTO.builder()
|
|
|
+ .accountId(agent.getAccountId())
|
|
|
+ .reportToken(agent.getReportToken())
|
|
|
+ .reportUrl(agent.getReportUrl())
|
|
|
+ .build();
|
|
|
+ return OrderReportRpcDTO.builder()
|
|
|
+ .gameId(platformOrderDTO.getGameId())
|
|
|
+ .accountReport(accountReportRpcDTO)
|
|
|
+ .wechatAppId(gameApplet == null ? null : gameApplet.getAppId())
|
|
|
+ .wechatOpenId(openId)
|
|
|
+ .orderId(platformOrderDTO.getOrderId())
|
|
|
+ .agentKey(agent.getAgentKey())
|
|
|
+ .backPolicyId(agent.getBackPolicyId())
|
|
|
+ .rechargeMoney(platformOrderDTO.getAmount().longValue() * 100)
|
|
|
+ .orderStatus(platformOrderDTO.getStatus())
|
|
|
+ .createTime(platformOrderDTO.getCreateTime())
|
|
|
+ .payTime(platformOrderDTO.getPayTime())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
}
|