浏览代码

企业微信思域回传

wcc 9 月之前
父节点
当前提交
ef741d89cd
共有 13 个文件被更改,包括 256 次插入129 次删除
  1. 2 0
      game-back/game-back-base/src/main/java/com/zanxiang/game/back/base/pojo/dto/TencentAppApiUserAgentQueryRpcDTO.java
  2. 1 1
      game-back/game-back-base/src/main/java/com/zanxiang/game/back/base/pojo/dto/TencentRoleRegisterAppApiRpcDTO.java
  3. 7 5
      game-back/game-back-base/src/main/java/com/zanxiang/game/back/base/pojo/dto/TencentUserAppApiRpcDTO.java
  4. 9 5
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/pojo/entity/GameTencentAppApiUser.java
  5. 2 1
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/pojo/enums/ActionTypeEnum.java
  6. 21 8
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/rpc/impl/TencentAppApiBackRpcImpl.java
  7. 4 0
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/IGameTencentAppApiRoleRegisterService.java
  8. 3 1
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/IGameTencentAppCallbackService.java
  9. 3 3
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameOceanengineAppCallbackServiceImpl.java
  10. 49 44
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameTencentAppApiOrderServiceImpl.java
  11. 89 4
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameTencentAppApiRoleRegisterServiceImpl.java
  12. 45 46
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameTencentAppApiUserServiceImpl.java
  13. 21 11
      game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameTencentAppCallbackServiceImpl.java

+ 2 - 0
game-back/game-back-base/src/main/java/com/zanxiang/game/back/base/pojo/dto/TencentAppApiUserAgentQueryRpcDTO.java

@@ -10,6 +10,8 @@ public class TencentAppApiUserAgentQueryRpcDTO implements Serializable {
 
     private Long gameId;
 
+    private String userId;
+
     /**
      * 设备唯一编号IMEI
      */

+ 1 - 1
game-back/game-back-base/src/main/java/com/zanxiang/game/back/base/pojo/dto/TencentRoleRegisterAppApiRpcDTO.java

@@ -34,7 +34,7 @@ public class TencentRoleRegisterAppApiRpcDTO implements Serializable {
      */
     private Long adAccountId;
     /**
-     * 注册时间
+     * 创角时间
      */
     private LocalDateTime registerTime;
 

+ 7 - 5
game-back/game-back-base/src/main/java/com/zanxiang/game/back/base/pojo/dto/TencentUserAppApiRpcDTO.java

@@ -36,11 +36,6 @@ public class TencentUserAppApiRpcDTO implements Serializable {
      */
     private LocalDateTime registerTime;
 
-    /**
-     * 关注时间
-     */
-    private LocalDateTime subscribeTime;
-
     /**
      * 渠道号
      */
@@ -74,4 +69,11 @@ public class TencentUserAppApiRpcDTO implements Serializable {
      * IOS设备CAID
      */
     private String caid;
+
+    private String regIp;
+
+    /**
+     * 数据源ID
+     */
+    private Long userActionSetId;
 }

+ 9 - 5
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/pojo/entity/GameTencentAppApiUser.java

@@ -53,11 +53,6 @@ public class GameTencentAppApiUser implements Serializable {
      */
     private LocalDateTime registerTime;
 
-    /**
-     * 关注时间
-     */
-    private LocalDateTime subscribeTime;
-
     /**
      * 用户设备mac地址
      */
@@ -109,5 +104,14 @@ public class GameTencentAppApiUser implements Serializable {
      */
     private Long backPolicyId;
 
+    private String ip;
+
+    /**
+     * 数据源ID
+     */
+    private Long userActionSetId;
+
+    private Long callbackId;
+
 
 }

+ 2 - 1
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/pojo/enums/ActionTypeEnum.java

@@ -9,7 +9,8 @@ public enum ActionTypeEnum {
     REGISTER("REGISTER","注册"),
     PURCHASE("PURCHASE","付费"),
     CREATE_ROLE("CREATE_ROLE","创角"),
-    COMPLETE_ORDER("COMPLETE_ORDER","下单");
+    COMPLETE_ORDER("COMPLETE_ORDER","下单"),
+    ACTIVATE_APP("ACTIVATE_APP", "激活应用");
 
 
     private String ActionType;

+ 21 - 8
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/rpc/impl/TencentAppApiBackRpcImpl.java

@@ -59,13 +59,14 @@ public class TencentAppApiBackRpcImpl implements ITencentAppApiBackRpc {
                 && StringUtils.isBlank(dto.getCaid())) {
             return ResultVO.fail("找不到用户唯一标识");
         }
-        GameTencentAppApiUser gameTencentUser = GameTencentAppApiUser.builder()
+        GameTencentAppApiUser userLog = GameTencentAppApiUser.builder()
                 .userId(dto.getUserId())
                 .adAccountId(dto.getAdAccountId())
                 .gameId(dto.getGameId())
                 .channel(dto.getChannel())
-                .subscribeTime(dto.getSubscribeTime())
                 .registerTime(dto.getRegisterTime())
+                .ip(dto.getRegIp())
+                .userActionSetId(dto.getUserActionSetId())
                 .mac(dto.getMac())
                 .imei(dto.getImei())
                 .oaid(dto.getOaid())
@@ -75,7 +76,10 @@ public class TencentAppApiBackRpcImpl implements ITencentAppApiBackRpc {
                 .isBack(BackStatusEnum.NO.getBackStatus())
                 .createTime(LocalDateTime.now())
                 .build();
-        gameTencentAppApiUserService.save(gameTencentUser);
+
+        GameTencentAppCallback callback = gameTencentAppCallbackService.getUserCallback(userLog.getGameId(), userLog.getImei(), userLog.getOaid(), userLog.getAndroidId(), userLog.getIdfa(), userLog.getCaid(), userLog.getIp(), userLog.getRegisterTime());
+        userLog.setCallbackId(callback == null ? -1L : callback.getId());
+        gameTencentAppApiUserService.save(userLog);
         return ResultVO.ok(true);
         // 激活现在默认不回传了,等创角的时候一起回传
         // return ResultVO.ok(gameTencentAppApiUserService.userBack(gameTencentUser, false));
@@ -83,7 +87,7 @@ public class TencentAppApiBackRpcImpl implements ITencentAppApiBackRpc {
 
     @Override
     public ResultVO<Boolean> backRoleRegister(TencentRoleRegisterAppApiRpcDTO dto) {
-        log.error("腾讯 APP创角回传收到:{}", JsonUtil.toString(dto));
+        log.error("腾讯 APP-API 创角回传收到:{}", JsonUtil.toString(dto));
         if (StringUtils.isBlank(dto.getMac())) {
             dto.setMac("");
         }
@@ -134,9 +138,9 @@ public class TencentAppApiBackRpcImpl implements ITencentAppApiBackRpc {
     @Override
     public ResultVO<Boolean> backOrder(TencentOrderAppApiRpcDTO dto) {
         if (Objects.equals(OrderStatusEnum.SUCCESS_PAY.getValue(), dto.getOrderStatus())) {
-            log.error("腾讯 APP订单回传收到:{}。", JsonUtil.toString(dto));
+            log.error("腾讯 APP-API 订单回传收到:{}。", JsonUtil.toString(dto));
         } else {
-            log.error("腾讯H5订单回传收到:{}。订单未支付,直接过滤", JsonUtil.toString(dto));
+            log.error("腾讯 APP-API 订单回传收到:{}。订单未支付,直接过滤", JsonUtil.toString(dto));
             return ResultVO.ok(true);
         }
         if (StringUtils.isBlank(dto.getMac())) {
@@ -204,7 +208,16 @@ public class TencentAppApiBackRpcImpl implements ITencentAppApiBackRpc {
 
     @Override
     public ResultVO<String> queryUserAgentFromCallback(TencentAppApiUserAgentQueryRpcDTO dto) {
-        GameTencentAppCallback callback = gameTencentAppCallbackService.getUserCallback(dto.getGameId(), dto.getImei(), dto.getOaid(), dto.getAndroidId(), dto.getIdfa(), dto.getCaid());
-        return ResultVO.ok(callback == null ? null : callback.getAgentKey());
+        GameTencentAppApiUser user = gameTencentAppApiUserService.getOne(new LambdaQueryWrapper<GameTencentAppApiUser>()
+                .eq(GameTencentAppApiUser::getGameId, dto.getGameId())
+                .eq(GameTencentAppApiUser::getUserId, dto.getUserId())
+                .orderByDesc(GameTencentAppApiUser::getCreateTime)
+                .last("limit 1")
+        );
+        if(user == null || user.getCallbackId() == null || user.getCallbackId() < 1) {
+            return ResultVO.ok(null);
+        }
+        GameTencentAppCallback callback = gameTencentAppCallbackService.getById(user.getCallbackId());
+        return ResultVO.ok(callback.getAgentKey());
     }
 }

+ 4 - 0
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/IGameTencentAppApiRoleRegisterService.java

@@ -3,7 +3,11 @@ package com.zanxiang.game.back.serve.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zanxiang.game.back.serve.pojo.entity.GameTencentAppApiRoleRegister;
 
+import java.util.List;
+
 public interface IGameTencentAppApiRoleRegisterService extends IService<GameTencentAppApiRoleRegister> {
 
     boolean roleRegisterBack(GameTencentAppApiRoleRegister roleRegisterLog);
+
+    boolean tencentUserReport(List<Long> ids);
 }

+ 3 - 1
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/IGameTencentAppCallbackService.java

@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.zanxiang.game.back.serve.pojo.dto.GameTencentAppCallbackDTO;
 import com.zanxiang.game.back.serve.pojo.entity.GameTencentAppCallback;
 
+import java.time.LocalDateTime;
+
 public interface IGameTencentAppCallbackService extends IService<GameTencentAppCallback> {
 
     boolean callback(GameTencentAppCallbackDTO dto);
 
-    GameTencentAppCallback getUserCallback(Long gameId, String imei, String oaid, String android, String idfa, String caid);
+    GameTencentAppCallback getUserCallback(Long gameId, String imei, String oaid, String android, String idfa, String caid, String ip, LocalDateTime regTime);
 }

+ 3 - 3
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameOceanengineAppCallbackServiceImpl.java

@@ -73,11 +73,11 @@ implements IGameOceanengineAppCallbackService {
 
         qw.and(and -> {
             if(StringUtils.isNoneBlank(oaid)) {
-                and.eq(StringUtils.isNoneBlank(oaid), GameOceanengineAppCallback::getOaid, oaid)
-                        .or().eq(StringUtils.isNoneBlank(oaid), GameOceanengineAppCallback::getOaidMd5, StringUtils.isBlank(oaid) ? null : Md5Util.encrypt32(oaid).toLowerCase());
+                and.or().eq(GameOceanengineAppCallback::getOaid, oaid)
+                        .or().eq(GameOceanengineAppCallback::getOaidMd5, Md5Util.encrypt32(oaid).toLowerCase());
             }
             if (StringUtils.isNoneBlank(idfa)) {
-                and.eq(GameOceanengineAppCallback::getIdfaMd5, StringUtils.isBlank(idfa) ? null : Md5Util.encrypt32(idfa).toLowerCase())
+                and.or().eq(GameOceanengineAppCallback::getIdfaMd5, Md5Util.encrypt32(idfa).toLowerCase())
                         .or().eq(GameOceanengineAppCallback::getIdfa, idfa);
             }
             and.or().eq(StringUtils.isNoneBlank(mac), GameOceanengineAppCallback::getMac, StringUtils.isBlank(oaid) ? null : Md5Util.encrypt32(mac.replaceAll(":","").toUpperCase()).toLowerCase())

+ 49 - 44
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameTencentAppApiOrderServiceImpl.java

@@ -6,6 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.sd4324530.jtuple.Tuple2;
 import com.github.sd4324530.jtuple.Tuple3;
+import com.zanxiang.advertising.tencent.base.AdvertisingTencentServer;
+import com.zanxiang.advertising.tencent.base.pojo.dto.DataReportOfAccountIdRpcDTO;
+import com.zanxiang.advertising.tencent.base.pojo.dto.UserActionRpcDTO;
+import com.zanxiang.advertising.tencent.base.rpc.IUserActionSetRpc;
 import com.zanxiang.game.back.base.pojo.enums.OrderStatusEnum;
 import com.zanxiang.game.back.serve.dao.mapper.GameTencentAppApiOrderMapper;
 import com.zanxiang.game.back.serve.pojo.TencentAppReport;
@@ -21,9 +25,11 @@ import com.zanxiang.module.util.NumberUtil;
 import com.zanxiang.module.util.URIUtil;
 import com.zanxiang.module.util.encryption.Md5Util;
 import com.zanxiang.module.util.exception.BaseException;
+import com.zanxiang.module.util.pojo.ResultVO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
@@ -39,6 +45,8 @@ import java.util.concurrent.atomic.AtomicLong;
 public class GameTencentAppApiOrderServiceImpl extends ServiceImpl<GameTencentAppApiOrderMapper, GameTencentAppApiOrder>
 implements IGameTencentAppApiOrderService {
 
+    @DubboReference(providedBy = AdvertisingTencentServer.SERVER_DUBBO_NAME)
+    private IUserActionSetRpc userActionSetRpc;
     @Autowired
     private IGameTencentAppApiBackLogService gameTencentAppApiBackLogService;
     @Autowired
@@ -195,68 +203,65 @@ implements IGameTencentAppApiOrderService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Tuple2<BackStatusEnum, String> doCallback(GameTencentAppApiOrder orderLog, LocalDateTime backTime, Long backMoney) {
-
-        GameTencentAppCallback callback = gameTencentAppCallbackService.getUserCallback(orderLog.getGameId(), orderLog.getImei(), orderLog.getOaid(), orderLog.getAndroidId(), orderLog.getIdfa(), orderLog.getCaid());
-        if(callback == null) {
-            return Tuple2.with(BackStatusEnum.FAILED, "找不到监测链接");
+        GameTencentAppApiUser user = gameTencentAppApiUserService.getOne(new LambdaQueryWrapper<GameTencentAppApiUser>()
+                .eq(GameTencentAppApiUser::getGameId, orderLog.getGameId())
+                .eq(GameTencentAppApiUser::getUserId, orderLog.getUserId())
+                .eq(GameTencentAppApiUser::getAdAccountId, orderLog.getAdAccountId())
+                .orderByDesc(GameTencentAppApiUser::getCreateTime)
+                .last("limit 1")
+        );
+        if (user != null) {
+            if (user.getCallbackId() == null || user.getCallbackId() < 1) {
+                return Tuple2.with(BackStatusEnum.FAILED, "用户匹配不到广告");
+            }
+        } else  {
+            return Tuple2.with(BackStatusEnum.FAILED, "找不到用户");
         }
-        String callbackUrl = URIUtil.decodeURIComponent(callback.getCallback());
+        GameTencentAppCallback callback = gameTencentAppCallbackService.getById(user.getCallbackId());
 
-        Map<String, Object> actionParam = new HashMap<>(2);
-        actionParam.put("claim_type", 4);
-        actionParam.put("value", backMoney);
-        TencentAppReport reportData = TencentAppReport.builder()
-                .actions(Collections.singletonList(TencentAppReport.Action.builder()
-                        .action_time(DateUtil.localDateTimeToSecond(orderLog.getRegisterTime()))
-                        .userr_id(TencentAppReport.UserId.builder()
-                                .hash_imei(StringUtils.isBlank(orderLog.getImei()) ? null : Md5Util.encrypt32(orderLog.getImei().toLowerCase()).toLowerCase())
-                                .hash_oaid(StringUtils.isBlank(orderLog.getOaid()) ? null : Md5Util.encrypt32(orderLog.getOaid()).toLowerCase())
-                                .hash_android_id(StringUtils.isBlank(orderLog.getAndroidId()) ? null : Md5Util.encrypt32(orderLog.getAndroidId()).toLowerCase())
-                                .hash_idfa(StringUtils.isBlank(orderLog.getIdfa()) ? null : Md5Util.encrypt32(orderLog.getIdfa().toUpperCase()).toLowerCase())
-                                .caid(orderLog.getCaid())
+        Map<String, Object> actionParams = new HashMap<>();
+        actionParams.put("value", backMoney);
+        DataReportOfAccountIdRpcDTO dataReportOfAccountIdRpcDTO = DataReportOfAccountIdRpcDTO.builder()
+                .accountId(user.getAdAccountId())
+                .userActionSetId(user.getUserActionSetId())
+                .action(UserActionRpcDTO.builder()
+                        .actionTime(backTime)
+                        .actionType(ActionTypeEnum.PURCHASE.getActionType())
+                        .userId(UserActionRpcDTO.UserIdRpcDTO.builder()
+                                .hashImei(StringUtils.isBlank(user.getImei()) ? null : Md5Util.encrypt32(user.getImei().toLowerCase()).toLowerCase())
+                                .hashIdfa(StringUtils.isBlank(user.getOaid()) ? null : Md5Util.encrypt32(user.getIdfa().toLowerCase()).toLowerCase())
+                                .hashOaid(StringUtils.isBlank(user.getOaid()) ? null : Md5Util.encrypt32(user.getOaid().toLowerCase()).toLowerCase())
                                 .build())
-                        .action_type("PURCHASE")
-                        .trace(callback.getClickId())
-                        .action_param(actionParam)
-                        .build()))
+                        .trace(UserActionRpcDTO.TraceRpcDTO.builder()
+                                .clickId(callback.getClickId())
+                                .build())
+                        .actionParam(actionParams)
+                        .build())
                 .build();
 
-
-        BackStatusEnum backStatus;
-        String backLog;
-        try {
-            ResponseEntity<String> response = restTemplate.postForEntity(callbackUrl, reportData, String.class);
-            if (response.getStatusCode().is2xxSuccessful()) {
-                backStatus = BackStatusEnum.SUCCESS;
-                backLog = "回传成功";
-            } else {
-                backStatus = BackStatusEnum.FAILED;
-                backLog = "回传识别,失败信息:" + response.getBody();
-            }
-        } catch (Exception e) {
-            log.error(e.getMessage(), e);
-            backStatus = BackStatusEnum.FAILED;
-            backLog = "回传识别,失败原因:" + e.getMessage();
-        }
-
-        String actionType = ActionTypeEnum.PURCHASE.getActionType();
-
         GameTencentAppApiBackLog gameTencentBackLog = GameTencentAppApiBackLog.builder()
                 .gameId(orderLog.getGameId())
                 .userId(orderLog.getUserId())
                 .adAccountId(orderLog.getAdAccountId())
                 .actionTime(backTime)
                 .createTime(LocalDateTime.now())
-                .actionType(actionType)
+                .actionType(ActionTypeEnum.PURCHASE.getActionType())
                 .orderId(orderLog.getOrderId())
                 .imei(orderLog.getImei())
                 .oaid(orderLog.getOaid())
                 .androidId(orderLog.getAndroidId())
                 .idfa(orderLog.getIdfa())
                 .caid(orderLog.getCaid())
-                .backLog(backLog)
-                .actionParam(actionParam.toString())
+                .actionParam(actionParams.toString())
                 .build();
+        ResultVO<Boolean> result = userActionSetRpc.reportByAccountId(dataReportOfAccountIdRpcDTO);
+        BackStatusEnum backStatus = BackStatusEnum.FAILED;
+        if (result.isSuccess()) {
+            backStatus = BackStatusEnum.SUCCESS;
+            gameTencentBackLog.setBackLog("回传成功");
+        } else {
+            gameTencentBackLog.setBackLog(result.getMsg());
+        }
         gameTencentAppApiBackLogService.save(gameTencentBackLog);
         return Tuple2.with(backStatus, gameTencentBackLog.getBackLog());
     }

+ 89 - 4
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameTencentAppApiRoleRegisterServiceImpl.java

@@ -3,35 +3,70 @@ package com.zanxiang.game.back.serve.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.sd4324530.jtuple.Tuple2;
+import com.zanxiang.advertising.tencent.base.AdvertisingTencentServer;
+import com.zanxiang.advertising.tencent.base.pojo.dto.DataReportOfAccountIdRpcDTO;
+import com.zanxiang.advertising.tencent.base.pojo.dto.DataReportOfAppIdRpcDTO;
+import com.zanxiang.advertising.tencent.base.pojo.dto.UserActionRpcDTO;
+import com.zanxiang.advertising.tencent.base.rpc.IUserActionSetRpc;
 import com.zanxiang.game.back.serve.dao.mapper.GameTencentAppApiRoleRegisterMapper;
 import com.zanxiang.game.back.serve.pojo.entity.*;
+import com.zanxiang.game.back.serve.pojo.enums.ActionTypeEnum;
 import com.zanxiang.game.back.serve.pojo.enums.BackStatusEnum;
 import com.zanxiang.game.back.serve.service.*;
+import com.zanxiang.module.util.encryption.Md5Util;
+import com.zanxiang.module.util.pojo.ResultVO;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 @Slf4j
 @Service
 public class GameTencentAppApiRoleRegisterServiceImpl extends ServiceImpl<GameTencentAppApiRoleRegisterMapper, GameTencentAppApiRoleRegister>
 implements IGameTencentAppApiRoleRegisterService {
 
+    @Autowired
+    private IGameTencentAppApiBackLogService gameTencentAppApiBackLogService;
     @Autowired
     private IGameTencentAppApiUserService gameTencentAppApiUserService;
+    @Autowired
+    private IGameTencentAppCallbackService gameTencentAppCallbackService;
+    @DubboReference(providedBy = AdvertisingTencentServer.SERVER_DUBBO_NAME)
+    private IUserActionSetRpc userActionSetRpc;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean roleRegisterBack(GameTencentAppApiRoleRegister roleRegisterLog) {
-        BackStatusEnum backStatus = doCallback(roleRegisterLog);
+        Tuple2<BackStatusEnum, String> backStatus = doCallback(roleRegisterLog);
         return update(new LambdaUpdateWrapper<GameTencentAppApiRoleRegister>()
-                .set(GameTencentAppApiRoleRegister::getIsBack, backStatus.getBackStatus())
+                .set(GameTencentAppApiRoleRegister::getIsBack, backStatus.first.getBackStatus())
+                .set(GameTencentAppApiRoleRegister::getBackLog, backStatus.second)
                 .eq(GameTencentAppApiRoleRegister::getId, roleRegisterLog.getId())
         );
     }
 
+    @Override
+    public boolean tencentUserReport(List<Long> ids) {
+        listByIds(ids).forEach(roleRegisterLog -> {
+            Tuple2<BackStatusEnum, String> backStatus = doCallback(roleRegisterLog);
+            update(new LambdaUpdateWrapper<GameTencentAppApiRoleRegister>()
+                    .set(GameTencentAppApiRoleRegister::getIsBack, backStatus.first.getBackStatus())
+                    .set(GameTencentAppApiRoleRegister::getBackLog, backStatus.second)
+                    .eq(GameTencentAppApiRoleRegister::getId, roleRegisterLog.getId())
+            );
+        });
+        return true;
+    }
 
-    private BackStatusEnum doCallback(GameTencentAppApiRoleRegister roleRegisterLog) {
+    private Tuple2<BackStatusEnum, String> doCallback(GameTencentAppApiRoleRegister roleRegisterLog) {
         GameTencentAppApiUser user = gameTencentAppApiUserService.getOne(new LambdaQueryWrapper<GameTencentAppApiUser>()
                 .eq(GameTencentAppApiUser::getGameId, roleRegisterLog.getGameId())
                 .eq(GameTencentAppApiUser::getUserId, roleRegisterLog.getUserId())
@@ -40,10 +75,60 @@ implements IGameTencentAppApiRoleRegisterService {
                 .last("limit 1")
         );
         if (user != null) {
+            if (user.getCallbackId() == null || user.getCallbackId() < 1) {
+                return Tuple2.with(BackStatusEnum.FAILED, "用户匹配不到广告");
+            }
             if (BackStatusEnum.NO.getBackStatus().equals(user.getIsBack())) {
                 gameTencentAppApiUserService.userBack(user, true);
+            } else {
+                // 注册已回传,则默认认为创角也回传了
+                return Tuple2.with(BackStatusEnum.NO, "用户第二+次创角不回传");
             }
+        } else  {
+            return Tuple2.with(BackStatusEnum.FAILED, "找不到用户");
+        }
+
+        GameTencentAppCallback callback = gameTencentAppCallbackService.getById(user.getCallbackId());
+
+        DataReportOfAccountIdRpcDTO dataReportOfAccountIdRpcDTO = DataReportOfAccountIdRpcDTO.builder()
+                .accountId(user.getAdAccountId())
+                .userActionSetId(user.getUserActionSetId())
+                .action(UserActionRpcDTO.builder()
+                        .actionTime(roleRegisterLog.getRegisterTime())
+                        .actionType(ActionTypeEnum.CREATE_ROLE.getActionType())
+                        .userId(UserActionRpcDTO.UserIdRpcDTO.builder()
+                                .hashImei(StringUtils.isBlank(user.getImei()) ? null : Md5Util.encrypt32(user.getImei().toLowerCase()).toLowerCase())
+                                .hashIdfa(StringUtils.isBlank(user.getOaid()) ? null : Md5Util.encrypt32(user.getIdfa().toLowerCase()).toLowerCase())
+                                .hashOaid(StringUtils.isBlank(user.getOaid()) ? null : Md5Util.encrypt32(user.getOaid().toLowerCase()).toLowerCase())
+                                .build())
+                        .trace(UserActionRpcDTO.TraceRpcDTO.builder()
+                                .clickId(callback.getClickId())
+                                .build())
+                        .build())
+                .build();
+
+        GameTencentAppApiBackLog gameTencentBackLog = GameTencentAppApiBackLog.builder()
+                .gameId(roleRegisterLog.getGameId())
+                .userId(roleRegisterLog.getUserId())
+                .adAccountId(roleRegisterLog.getAdAccountId())
+                .actionTime(roleRegisterLog.getRegisterTime())
+                .createTime(LocalDateTime.now())
+                .actionType(ActionTypeEnum.CREATE_ROLE.getActionType())
+                .imei(roleRegisterLog.getImei())
+                .oaid(roleRegisterLog.getOaid())
+                .androidId(roleRegisterLog.getAndroidId())
+                .idfa(roleRegisterLog.getIdfa())
+                .caid(roleRegisterLog.getCaid())
+                .build();
+        ResultVO<Boolean> result = userActionSetRpc.reportByAccountId(dataReportOfAccountIdRpcDTO);
+        BackStatusEnum backStatus = BackStatusEnum.FAILED;
+        if (result.isSuccess()) {
+            backStatus = BackStatusEnum.SUCCESS;
+            gameTencentBackLog.setBackLog("回传成功");
+        } else {
+            gameTencentBackLog.setBackLog(result.getMsg());
         }
-        return BackStatusEnum.NO;
+        gameTencentAppApiBackLogService.save(gameTencentBackLog);
+        return Tuple2.with(backStatus, gameTencentBackLog.getBackLog());
     }
 }

+ 45 - 46
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameTencentAppApiUserServiceImpl.java

@@ -3,8 +3,12 @@ package com.zanxiang.game.back.serve.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.sd4324530.jtuple.Tuple2;
+import com.zanxiang.advertising.tencent.base.AdvertisingTencentServer;
+import com.zanxiang.advertising.tencent.base.pojo.dto.DataReportOfAccountIdRpcDTO;
+import com.zanxiang.advertising.tencent.base.pojo.dto.UserActionRpcDTO;
+import com.zanxiang.advertising.tencent.base.rpc.IUserActionSetRpc;
 import com.zanxiang.game.back.serve.dao.mapper.GameTencentAppApiUserMapper;
-import com.zanxiang.game.back.serve.pojo.TencentAppReport;
 import com.zanxiang.game.back.serve.pojo.entity.GameTencentAppApiBackLog;
 import com.zanxiang.game.back.serve.pojo.entity.GameTencentAppApiUser;
 import com.zanxiang.game.back.serve.pojo.entity.GameTencentAppCallback;
@@ -13,19 +17,17 @@ import com.zanxiang.game.back.serve.pojo.enums.BackStatusEnum;
 import com.zanxiang.game.back.serve.service.IGameTencentAppApiBackLogService;
 import com.zanxiang.game.back.serve.service.IGameTencentAppApiUserService;
 import com.zanxiang.game.back.serve.service.IGameTencentAppCallbackService;
-import com.zanxiang.module.util.DateUtil;
-import com.zanxiang.module.util.URIUtil;
 import com.zanxiang.module.util.encryption.Md5Util;
+import com.zanxiang.module.util.pojo.ResultVO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 
 import java.time.LocalDateTime;
-import java.util.Collections;
 import java.util.List;
 
 @Slf4j
@@ -38,13 +40,16 @@ implements IGameTencentAppApiUserService {
     private IGameTencentAppCallbackService gameTencentAppCallbackService;
     @Autowired
     private RestTemplate restTemplate;
+    @DubboReference(providedBy = AdvertisingTencentServer.SERVER_DUBBO_NAME)
+    private IUserActionSetRpc userActionSetRpc;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean userBack(GameTencentAppApiUser userLog, boolean mustBack) {
-        BackStatusEnum backStatus = doCallback(userLog, mustBack);
+        Tuple2<BackStatusEnum, String> backStatus = doCallback(userLog, mustBack);
         return update(new LambdaUpdateWrapper<GameTencentAppApiUser>()
-                .set(GameTencentAppApiUser::getIsBack, backStatus.getBackStatus())
+                .set(GameTencentAppApiUser::getIsBack, backStatus.first.getBackStatus())
+                .set(GameTencentAppApiUser::getBackLog, backStatus.second)
                 .eq(GameTencentAppApiUser::getId, userLog.getId())
         );
     }
@@ -52,9 +57,10 @@ implements IGameTencentAppApiUserService {
     @Override
     public boolean tencentUserReport(List<Long> ids) {
         listByIds(ids).forEach(userLog -> {
-            BackStatusEnum backStatus = doCallback(userLog, true);
+            Tuple2<BackStatusEnum, String> backStatus = doCallback(userLog, true);
             update(new LambdaUpdateWrapper<GameTencentAppApiUser>()
-                    .set(GameTencentAppApiUser::getIsBack, backStatus.getBackStatus())
+                    .set(GameTencentAppApiUser::getIsBack, backStatus.first.getBackStatus())
+                    .set(GameTencentAppApiUser::getBackLog, backStatus.second)
                     .eq(GameTencentAppApiUser::getId, userLog.getId())
             );
         });
@@ -62,7 +68,7 @@ implements IGameTencentAppApiUserService {
     }
 
 
-    private BackStatusEnum doCallback(GameTencentAppApiUser userLog, boolean mustBack) {
+    private Tuple2<BackStatusEnum, String> doCallback(GameTencentAppApiUser userLog, boolean mustBack) {
         boolean isBack = mustBack ? false : gameTencentAppApiBackLogService.count(new LambdaQueryWrapper<GameTencentAppApiBackLog>()
                 .eq(GameTencentAppApiBackLog::getGameId, userLog.getGameId())
                 .eq(GameTencentAppApiBackLog::getUserId, userLog.getUserId())
@@ -70,46 +76,31 @@ implements IGameTencentAppApiUserService {
                 .eq(GameTencentAppApiBackLog::getBackLog, "回传成功")
         ) > 0;
         if (isBack) {
-            return BackStatusEnum.NO;
+            return Tuple2.with(BackStatusEnum.SUCCESS, "回传成功");
         }
-        GameTencentAppCallback callback = gameTencentAppCallbackService.getUserCallback(userLog.getGameId(), userLog.getImei(), userLog.getOaid(), userLog.getAndroidId(), userLog.getIdfa(), userLog.getCaid());
-        if(callback == null) {
-            return BackStatusEnum.FAILED;
+        if (userLog.getCallbackId() == null || userLog.getCallbackId() < 1) {
+            return Tuple2.with(BackStatusEnum.FAILED, "用户匹配不到广告");
         }
-        String callbackUrl = URIUtil.decodeURIComponent(callback.getCallback());
 
-        TencentAppReport reportData = TencentAppReport.builder()
-                .actions(Collections.singletonList(TencentAppReport.Action.builder()
-                        .action_time(DateUtil.localDateTimeToSecond(userLog.getRegisterTime()))
-                        .userr_id(TencentAppReport.UserId.builder()
-                                .hash_imei(StringUtils.isBlank(userLog.getImei()) ? null : Md5Util.encrypt32(userLog.getImei().toLowerCase()).toLowerCase())
-                                .hash_oaid(StringUtils.isBlank(userLog.getOaid()) ? null : Md5Util.encrypt32(userLog.getOaid()).toLowerCase())
-                                .hash_android_id(StringUtils.isBlank(userLog.getAndroidId()) ? null : Md5Util.encrypt32(userLog.getAndroidId()).toLowerCase())
-                                .hash_idfa(StringUtils.isBlank(userLog.getIdfa()) ? null : Md5Util.encrypt32(userLog.getIdfa().toUpperCase()).toLowerCase())
-                                .caid(userLog.getCaid())
+        GameTencentAppCallback callback = gameTencentAppCallbackService.getById(userLog.getCallbackId());
+
+        DataReportOfAccountIdRpcDTO dataReportOfAccountIdRpcDTO = DataReportOfAccountIdRpcDTO.builder()
+                .accountId(userLog.getAdAccountId())
+                .userActionSetId(userLog.getUserActionSetId())
+                .action(UserActionRpcDTO.builder()
+                        .actionTime(userLog.getRegisterTime())
+                        .actionType(ActionTypeEnum.ACTIVATE_APP.getActionType())
+                        .userId(UserActionRpcDTO.UserIdRpcDTO.builder()
+                                .hashImei(StringUtils.isBlank(userLog.getImei()) ? null : Md5Util.encrypt32(userLog.getImei().toLowerCase()).toLowerCase())
+                                .hashIdfa(StringUtils.isBlank(userLog.getOaid()) ? null : Md5Util.encrypt32(userLog.getIdfa().toLowerCase()).toLowerCase())
+                                .hashOaid(StringUtils.isBlank(userLog.getOaid()) ? null : Md5Util.encrypt32(userLog.getOaid().toLowerCase()).toLowerCase())
+                                .build())
+                        .trace(UserActionRpcDTO.TraceRpcDTO.builder()
+                                .clickId(callback.getClickId())
                                 .build())
-                        .action_type("ACTIVATE_APP")
-                        .trace(callback.getClickId())
-                        .build()))
+                        .build())
                 .build();
 
-        BackStatusEnum backStatus;
-        String backLog;
-        try {
-            ResponseEntity<String> response = restTemplate.postForEntity(callbackUrl, reportData, String.class);
-            if (response.getStatusCode().is2xxSuccessful()) {
-                backStatus = BackStatusEnum.SUCCESS;
-                backLog = "回传成功";
-            } else {
-                backStatus = BackStatusEnum.FAILED;
-                backLog = "回传识别,失败信息:" + response.getBody();
-            }
-        } catch (Exception e) {
-            log.error(e.getMessage(), e);
-            backStatus = BackStatusEnum.FAILED;
-            backLog = "回传识别,失败原因:" + e.getMessage();
-        }
-
         GameTencentAppApiBackLog gameTencentBackLog = GameTencentAppApiBackLog.builder()
                 .gameId(userLog.getGameId())
                 .userId(userLog.getUserId())
@@ -122,9 +113,17 @@ implements IGameTencentAppApiUserService {
                 .androidId(userLog.getAndroidId())
                 .idfa(userLog.getIdfa())
                 .caid(userLog.getCaid())
-                .backLog(backLog)
                 .build();
+        ResultVO<Boolean> result = userActionSetRpc.reportByAccountId(dataReportOfAccountIdRpcDTO);
+
+        BackStatusEnum backStatus = BackStatusEnum.FAILED;
+        if (result.isSuccess()) {
+            backStatus = BackStatusEnum.SUCCESS;
+            gameTencentBackLog.setBackLog("回传成功");
+        } else {
+            gameTencentBackLog.setBackLog(result.getMsg());
+        }
         gameTencentAppApiBackLogService.save(gameTencentBackLog);
-        return backStatus;
+        return Tuple2.with(backStatus, gameTencentBackLog.getBackLog());
     }
 }

+ 21 - 11
game-back/game-back-serve/src/main/java/com/zanxiang/game/back/serve/service/impl/GameTencentAppCallbackServiceImpl.java

@@ -13,7 +13,6 @@ import com.zanxiang.module.util.DateUtil;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.encryption.Md5Util;
-import com.zanxiang.module.util.pojo.ResultVO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.dubbo.config.annotation.DubboReference;
@@ -25,6 +24,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 
 @Slf4j
 @Service
@@ -64,20 +64,30 @@ implements IGameTencentAppCallbackService {
     }
 
     @Override
-    public GameTencentAppCallback getUserCallback(Long gameId, String imei, String oaid, String android, String idfa, String caid) {
+    public GameTencentAppCallback getUserCallback(Long gameId, String imei, String oaid, String android, String idfa, String caid, String ip, LocalDateTime regTime) {
         LambdaQueryWrapper<GameTencentAppCallback> qw = new LambdaQueryWrapper<GameTencentAppCallback>()
+                .lt(GameTencentAppCallback::getClickTime, DateUtil.localDateTimeToSecond(regTime))
                 .eq(GameTencentAppCallback::getGameId, gameId)
                 .orderByDesc(GameTencentAppCallback::getClickTime)
                 .last("limit 1");
-        if (StringUtils.isNoneBlank(imei) || StringUtils.isNoneBlank(android) || StringUtils.isNoneBlank(oaid)) {
-            qw.and(and -> {
-                and.eq(StringUtils.isNoneBlank(imei), GameTencentAppCallback::getMuid, StringUtils.isBlank(imei) ? null : Md5Util.encrypt32(imei.toLowerCase()).toLowerCase())
-                        .or().eq(StringUtils.isNoneBlank(android), GameTencentAppCallback::getHashAndroidId, StringUtils.isBlank(android) ? null : Md5Util.encrypt32(android).toLowerCase())
-                        .or().eq(StringUtils.isNoneBlank(oaid), GameTencentAppCallback::getHashOaid, StringUtils.isBlank(oaid) ? null : Md5Util.encrypt32(oaid).toLowerCase());
-            });
-        } else if (StringUtils.isNoneBlank(idfa)) {
-            qw.eq(GameTencentAppCallback::getMuid, Md5Util.encrypt32(idfa).toLowerCase());
-        }
+        qw.and(and -> {
+            if(StringUtils.isNoneBlank(imei)) {
+                and.or().eq(GameTencentAppCallback::getMuid, Md5Util.encrypt32(imei.toLowerCase()).toLowerCase());
+            }
+            if(StringUtils.isNoneBlank(android)) {
+                and.or().eq(GameTencentAppCallback::getHashAndroidId, Md5Util.encrypt32(android).toLowerCase());
+            }
+            if(StringUtils.isNoneBlank(oaid)) {
+                and.or().eq(GameTencentAppCallback::getHashOaid, Md5Util.encrypt32(oaid).toLowerCase());
+            }
+            if(StringUtils.isNoneBlank(idfa)) {
+                and.or().eq(GameTencentAppCallback::getMuid, Md5Util.encrypt32(idfa.toUpperCase()).toLowerCase());
+            }
+            and.or().and(StringUtils.isNoneBlank(ip), tmp -> {
+                        tmp.ge(GameTencentAppCallback::getClickTime, DateUtil.localDateTimeToSecond(regTime.plusDays(2)))
+                                .eq(GameTencentAppCallback::getIp, ip);
+                    });
+        });
         return getOne(qw);
     }
 }