|
@@ -8,6 +8,7 @@ import com.github.sd4324530.jtuple.Tuple2;
|
|
|
import com.zanxiang.game.back.base.ServerInfo;
|
|
|
import com.zanxiang.game.back.base.pojo.dto.TencentAppApiUserAgentQueryRpcDTO;
|
|
|
import com.zanxiang.game.back.base.rpc.ITencentAppApiBackRpc;
|
|
|
+import com.zanxiang.game.back.base.rpc.ITencentMiniGameBackRpc;
|
|
|
import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
|
|
|
import com.zanxiang.game.module.mybatis.entity.*;
|
|
|
import com.zanxiang.game.module.mybatis.mapper.AgentMapper;
|
|
@@ -37,6 +38,9 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
|
@DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
|
|
|
private ITencentAppApiBackRpc tencentAppApiBackRpc;
|
|
|
|
|
|
+ @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
|
|
|
+ private ITencentMiniGameBackRpc tencentMiniGameBackRpc;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IUserService userService;
|
|
|
|
|
@@ -89,7 +93,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
|
//30天未登录, 更新渠道
|
|
|
Game game = gameService.getById(user.getGameId());
|
|
|
//渠道id, 链接参数, 分享人id
|
|
|
- Tuple3<Long, Map<String, String>, String> tuple3 = this.getUserAgentId(game, userData);
|
|
|
+ Tuple3<Long, Map<String, String>, String> tuple3 = this.getUserAgentId(game, userData, user.getOpenId());
|
|
|
//查询渠道
|
|
|
Agent agent = super.getById(tuple3.getT1());
|
|
|
if (agent == null) {
|
|
@@ -120,11 +124,22 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Tuple3<Long, Map<String, String>, String> getUserAgentId(Game game, UserData userData) {
|
|
|
+ public Tuple3<Long, Map<String, String>, String> getUserAgentId(Game game, UserData userData, String openId) {
|
|
|
try {
|
|
|
//微信小游戏解析
|
|
|
if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getId())) {
|
|
|
- return this.appletChannelTransform(userData.getChannel());
|
|
|
+ Tuple3<Long, Map<String, String>, String> tuple3 = this.appletChannelTransform(userData.getChannel());
|
|
|
+ //非自然量, 或者不存在openId, 直接返回结束
|
|
|
+ if (!Objects.equals(tuple3.getT1(), 0L) || Strings.isBlank(openId)) {
|
|
|
+ return tuple3;
|
|
|
+ }
|
|
|
+ //自然量, 做监测链接匹配补偿归因
|
|
|
+ Tuple2<Long, Map<String, String>> tuple2 = this.getChannelByOpenId(game.getId(), openId);
|
|
|
+ if (tuple2 == null) {
|
|
|
+ return tuple3;
|
|
|
+ }
|
|
|
+ userData.setChannel(JsonUtil.toString(tuple2.second));
|
|
|
+ return Tuples.of(tuple2.first, tuple2.second, tuple3.getT3());
|
|
|
}
|
|
|
//APP解析
|
|
|
if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_APP.getId())) {
|
|
@@ -142,6 +157,27 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
|
|
|
return Tuples.of(0L, Collections.emptyMap(), Strings.EMPTY);
|
|
|
}
|
|
|
|
|
|
+ private Tuple2<Long, Map<String, String>> getChannelByOpenId(Long gameId, String openId) {
|
|
|
+ try {
|
|
|
+ Map<String, Object> callBackMap = tencentMiniGameBackRpc.getCallBackByOpenId(gameId, openId).getData();
|
|
|
+ if (CollectionUtils.isEmpty(callBackMap) || !callBackMap.containsKey("agentKey")) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Agent agent = super.getOne(new LambdaQueryWrapper<Agent>().eq(Agent::getAgentKey, callBackMap.get("agentKey")));
|
|
|
+ if (agent == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<String, String> channelMap = new HashMap<>(3);
|
|
|
+ callBackMap.put("weixinadinfo", callBackMap.get("adgroupId") + "." + callBackMap.get("impressionId"));
|
|
|
+ callBackMap.put("gdt_vid", callBackMap.get("impressionId").toString());
|
|
|
+ callBackMap.put("callBack", JsonUtil.toString(callBackMap));
|
|
|
+ return Tuple2.with(agent.getId(), channelMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("微信小游戏补偿匹配监测链接异常, gameId : {}, openId : {}, e : {}", gameId, openId, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private Tuple3<Long, Map<String, String>, String> appletChannelTransform(String channel) {
|
|
|
//链接参数
|
|
|
if (Strings.isBlank(channel)) {
|