فهرست منبع

Merge remote-tracking branch 'origin/package-back' into package

bilingfeng 11 ماه پیش
والد
کامیت
1d6d02acaf

+ 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) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <删除调试日志> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <头条虚拟游戏链路兼容修改> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 12 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IUserAppletService.java

@@ -0,0 +1,12 @@
+package com.zanxiang.game.module.sdk.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.mybatis.entity.UserApplet;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-04-29
+ * @description : 投放小程序用户信息
+ */
+public interface IUserAppletService extends IService<UserApplet> {
+}

+ 86 - 12
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/AgentServiceImpl.java

@@ -54,6 +54,9 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
     @Autowired
     private IKafkaService kafkaService;
 
+    @Autowired
+    private IUserAppletService userAppletService;
+
     @Override
     public void userAgentUpdate(User user, String channel) {
         log.error("用户登录接收到的渠道参数 userId : {}, channel : {}", user.getId(), channel);
@@ -108,23 +111,30 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
     public Tuple3<Long, Map<String, String>, String> getUserAgentId(UserData userData) {
         log.error("用户注册接收到的渠道参数 userData : {}", JsonUtil.toString(userData));
         //获取游戏信息
-        GameExt gameExt = gameExtService.getByGameId(userData.getGameId());
         Game game = gameService.getById(userData.getGameId());
-        //不投放得APP游戏按ip和ua进行渠道匹配
-        if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())
-                && !Objects.equals(gameExt.getAdCallBackSwitch(), Boolean.TRUE)) {
-            UserVisitLog userVisitLog = this.getUserVisitLog(userData);
-            if (userVisitLog == null) {
-                return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
-            }
-            return Tuples.of(userVisitLog.getAgentId(), Collections.emptyMap(), Strings.EMPTY);
+        //微信小游戏解析
+        if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getId())) {
+            return this.appletChannelTransform(userData.getChannel());
+        }
+        //APP解析
+        if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())) {
+            return this.appChannelTransform(game, userData);
+        }
+        //H5解析
+        if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_H5.getId())) {
+            return this.h5ChannelTransform(userData.getChannel());
         }
+        //默认返回自然量
+        return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
+    }
+
+    private Tuple3<Long, Map<String, String>, String> appletChannelTransform(String channel) {
         //链接参数
-        if (Strings.isBlank(userData.getChannel())) {
+        if (Strings.isBlank(channel)) {
             return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
         }
         //数据解析
-        Map<String, String> urlParamMap = this.channelTransform(userData.getChannel());
+        Map<String, String> urlParamMap = this.channelTransform(channel);
         String shareUserId = urlParamMap.get("shareUserId");
         //查询渠道
         Agent agent = null;
@@ -142,6 +152,48 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
         return Tuples.of(agent.getId(), urlParamMap, Strings.isBlank(shareUserId) ? Strings.EMPTY : shareUserId);
     }
 
+    private Tuple3<Long, Map<String, String>, String> appChannelTransform(Game game, UserData userData) {
+        //游戏拓展信息
+        GameExt gameExt = gameExtService.getByGameId(userData.getGameId());
+        //不投放, 不回传, 只归因渠道, -- 不投放, 且回传只存在于导量情况, 导量无注册行为
+        if (Objects.equals(game.getIsPut(), Boolean.FALSE) && Objects.equals(gameExt.getAdCallBackSwitch(), Boolean.FALSE)) {
+            //查询访问记录
+            UserVisitLog userVisitLog = this.getUserVisitLog(userData);
+            //返回渠道信息
+            return Tuples.of(userVisitLog == null ? 0L : userVisitLog.getAgentId(), Collections.emptyMap(), Strings.EMPTY);
+        }
+        //投放, 且回传 -- 投放, 且不回传这种情况不存在
+        if (Objects.equals(game.getIsPut(), Boolean.TRUE) && Objects.equals(gameExt.getAdCallBackSwitch(), Boolean.TRUE)) {
+            //查询访问记录
+            UserVisitLog userVisitLog = this.getUserVisitLog(userData);
+            if (userVisitLog == null) {
+                //未匹配到访问信息, 返回自然凉
+                return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
+            }
+            //解析访问记录中得请求参数
+            Map<String, String> urlParamMap = this.channelTransform(userVisitLog.getChannel());
+            //查询渠道
+            Agent agent = this.getAgentByKey(urlParamMap);
+            //返回渠道信息
+            return Tuples.of(agent == null ? 0L : agent.getId(), urlParamMap, Strings.EMPTY);
+        }
+        //默认返回自然量
+        return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
+    }
+
+    private Tuple3<Long, Map<String, String>, String> h5ChannelTransform(String channel) {
+        //链接参数
+        if (Strings.isBlank(channel)) {
+            return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
+        }
+        //数据解析
+        Map<String, String> urlParamMap = this.channelTransform(channel);
+        //查询渠道
+        Agent agent = this.getAgentByKey(urlParamMap);
+        //返回
+        return Tuples.of(agent == null ? 0L : agent.getId(), urlParamMap, Strings.EMPTY);
+    }
+
     private UserVisitLog getUserVisitLog(UserData userData) {
         //当前时间
         LocalDateTime regTime = LocalDateTime.now();
@@ -154,7 +206,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
         // 1. 策略一 : 根据 ip + ua 精准匹配用户
         userVisitLogList = userVisitLogService.list(new LambdaQueryWrapper<UserVisitLog>()
                 .eq(UserVisitLog::getIp, userData.getIp())
-                .eq(UserVisitLog::getUa, userData)
+                .eq(UserVisitLog::getUa, userData.getUa())
                 .le(UserVisitLog::getCreateTime, regTime));
         // 判断通过策略一是否拿到数据, 筛选出访问时间与注册时间最接近的
         if (CollectionUtils.isNotEmpty(userVisitLogList)) {
@@ -236,6 +288,28 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 
     @Override
     public Map<String, String> channelTransform(String channel) {
+        if (Strings.isBlank(channel) || Strings.isBlank(channel.trim())) {
+            return Collections.emptyMap();
+        }
+        //渠道参数
+        Map<String, String> paramMap = this.channelToMap(channel);
+        //企业微信拼接字段名
+        String callState = "callState";
+        //判断是否包含转译参数
+        if (!paramMap.containsKey(callState)) {
+            return paramMap;
+        }
+        //小程序访问信息
+        UserApplet userApplet = userAppletService.getById(Integer.valueOf(paramMap.get(callState)));
+        if (userApplet != null && Strings.isNotBlank(userApplet.getChannel())) {
+            paramMap.putAll(this.channelToMap(userApplet.getChannel()));
+            paramMap.put("appId", userApplet.getAppId());
+            paramMap.put("openId", userApplet.getOpenId());
+        }
+        return paramMap;
+    }
+
+    private Map<String, String> channelToMap(String channel) {
         if (Strings.isBlank(channel) || Strings.isBlank(channel.trim())) {
             return Collections.emptyMap();
         }

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/LoginServiceImpl.java

@@ -290,7 +290,7 @@ public class LoginServiceImpl implements IRegisterLoginService {
         User user = transform(userData, tuple3.getT1(), userName);
         user.setPassword(password);
         user.setMobile(mobile);
-        user.setOpenId(openId);
+        user.setOpenId(Strings.isNotBlank(openId) ? openId : tuple3.getT2().get("openId"));
         user.setSessionKey(sessionKey);
         user.setChannel(userData.getChannel());
         user.setShareUserId(shareUserId);

+ 18 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/UserAppletServiceImpl.java

@@ -0,0 +1,18 @@
+package com.zanxiang.game.module.sdk.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.mybatis.entity.UserApplet;
+import com.zanxiang.game.module.mybatis.mapper.UserAppletMapper;
+import com.zanxiang.game.module.sdk.service.IUserAppletService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-04-29
+ * @description : 投放小程序用户信息
+ */
+@Slf4j
+@Service
+public class UserAppletServiceImpl extends ServiceImpl<UserAppletMapper, UserApplet> implements IUserAppletService {
+}