|  | @@ -4,23 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.dao.mapper.GameTencentMiniGameCallbackMapper;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.pojo.dto.GameTencentCallbackDTO;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.pojo.entity.GameBackPolicy;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.pojo.entity.GameTencentMiniGameBackLog;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.pojo.entity.GameTencentMiniGameCallback;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.pojo.entity.GameTencentMiniGameUser;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.pojo.enums.ActionTypeEnum;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.pojo.enums.BackStatusEnum;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.pojo.enums.BackTypeEnum;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.service.IGameBackPolicyService;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.service.IGameTencentMiniGameBackLogService;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.service.IGameTencentMiniGameCallbackService;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.service.IGameTencentMiniGameUserService;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.base.ServerInfo;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.base.pojo.vo.AgentRpcVO;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.base.rpc.IAgentRpc;
 | 
	
		
			
				|  |  | -import com.zanxiang.module.redis.service.IDistributedLockComponent;
 | 
	
		
			
				|  |  |  import com.zanxiang.module.util.DateUtil;
 | 
	
		
			
				|  |  |  import com.zanxiang.module.util.JsonUtil;
 | 
	
		
			
				|  |  | +import com.zanxiang.module.util.URIUtil;
 | 
	
		
			
				|  |  |  import com.zanxiang.module.util.bean.BeanUtil;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  import org.apache.dubbo.config.annotation.DubboReference;
 | 
	
	
		
			
				|  | @@ -32,8 +23,7 @@ import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.time.LocalDate;
 | 
	
		
			
				|  |  | -import java.util.Objects;
 | 
	
		
			
				|  |  | -import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  | +import java.util.Optional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Slf4j
 | 
	
		
			
				|  |  |  @Service
 | 
	
	
		
			
				|  | @@ -49,18 +39,6 @@ public class GameTencentMiniGameCallbackServiceImpl extends ServiceImpl<GameTenc
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private KafkaProducer<String, String> kafkaProducer;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private IDistributedLockComponent distributedLockComponent;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private IGameBackPolicyService gameBackPolicyService;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private IGameTencentMiniGameUserService gameTencentMiniGameUserService;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  | -    private IGameTencentMiniGameBackLogService gameTencentMiniGameBackLogService;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public boolean callback(GameTencentCallbackDTO dto) {
 | 
	
		
			
				|  |  |          AgentRpcVO agent = agentRpc.getByTencentAccountId(dto.getAccountId()).getData();
 | 
	
	
		
			
				|  | @@ -87,50 +65,30 @@ public class GameTencentMiniGameCallbackServiceImpl extends ServiceImpl<GameTenc
 | 
	
		
			
				|  |  |          return true;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private void linkCallBack(GameTencentMiniGameCallback callback, AgentRpcVO agent) {
 | 
	
		
			
				|  |  | -        //渠道参数判断
 | 
	
		
			
				|  |  | -        if (agent == null || agent.getBackPolicyId() == null) {
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //查询策略, 判断是否开启监测链接回传
 | 
	
		
			
				|  |  | -        GameBackPolicy gameBackPolicy = gameBackPolicyService.getById(agent.getBackPolicyId());
 | 
	
		
			
				|  |  | -        if (!Objects.equals(gameBackPolicy.getLinkCallBack(), Boolean.TRUE)) {
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //参数校验, 判断是否符合回传条件
 | 
	
		
			
				|  |  | -        if (callback.getGameId() == null || Strings.isBlank(callback.getWechatAppId())
 | 
	
		
			
				|  |  | -                || callback.getAccountId() == null || Strings.isBlank(callback.getWechatOpenid())) {
 | 
	
		
			
				|  |  | -            log.error("监测链接回传参数不全, id : {}", callback.getId());
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //判断是否是新用户, 已注册的老用户不回传
 | 
	
		
			
				|  |  | -        if (gameTencentMiniGameUserService.count(new LambdaQueryWrapper<GameTencentMiniGameUser>()
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameUser::getGameId, callback.getGameId())
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameUser::getWechatAppId, callback.getWechatAppId())
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameUser::getWechatOpenid, callback.getWechatOpenid())
 | 
	
		
			
				|  |  | -        ) > 0) {
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //线程锁, 防止重复请求
 | 
	
		
			
				|  |  | -        String lockKey = com.zanxiang.game.back.base.ServerInfo.SERVER_NAME + ":tencentMiniLinkCallBack:"
 | 
	
		
			
				|  |  | -                + callback.getGameId() + ":" + callback.getAccountId() + ":"
 | 
	
		
			
				|  |  | -                + callback.getWechatAppId() + ":" + callback.getWechatOpenid();
 | 
	
		
			
				|  |  | -        if (!distributedLockComponent.doLock(lockKey, 0L, 3L, TimeUnit.MINUTES)) {
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //注册已回传判断
 | 
	
		
			
				|  |  | -        if (gameTencentMiniGameBackLogService.count(new LambdaQueryWrapper<GameTencentMiniGameBackLog>()
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameBackLog::getGameId, callback.getGameId())
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameBackLog::getWechatAppId, callback.getWechatAppId())
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameBackLog::getWechatOpenid, callback.getWechatOpenid())
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameBackLog::getAdAccountId, callback.getAccountId())
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameBackLog::getActionType, ActionTypeEnum.REGISTER.getActionType())
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameBackLog::getBackStatus, BackStatusEnum.SUCCESS.getBackStatus())
 | 
	
		
			
				|  |  | -                .eq(GameTencentMiniGameBackLog::getBackType, BackTypeEnum.BACK_API.getBackType())
 | 
	
		
			
				|  |  | -        ) > 0) {
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public String getCallBackUrl(String wechatOpenid, String clickId) {
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            GameTencentMiniGameCallback tencentMiniGameCallback = super.getOne(
 | 
	
		
			
				|  |  | +                    new LambdaQueryWrapper<GameTencentMiniGameCallback>()
 | 
	
		
			
				|  |  | +                            .eq(GameTencentMiniGameCallback::getWechatOpenid, wechatOpenid)
 | 
	
		
			
				|  |  | +                            .and(qw -> qw.eq(GameTencentMiniGameCallback::getImpressionId, clickId)
 | 
	
		
			
				|  |  | +                                    .or().eq(GameTencentMiniGameCallback::getRequestId, clickId)
 | 
	
		
			
				|  |  | +                                    .or().eq(GameTencentMiniGameCallback::getClickId, clickId)
 | 
	
		
			
				|  |  | +                            )
 | 
	
		
			
				|  |  | +                            .orderByDesc(GameTencentMiniGameCallback::getClickTime)
 | 
	
		
			
				|  |  | +                            .last("limit 1"));
 | 
	
		
			
				|  |  | +            String callBack = Optional.ofNullable(tencentMiniGameCallback)
 | 
	
		
			
				|  |  | +                    .map(GameTencentMiniGameCallback::getCallback)
 | 
	
		
			
				|  |  | +                    .orElse(null);
 | 
	
		
			
				|  |  | +            if (Strings.isBlank(callBack)) {
 | 
	
		
			
				|  |  | +                log.error("匹配监测链接为空, wechatOpenid : {}, clickId : {}", wechatOpenid, clickId);
 | 
	
		
			
				|  |  | +                return null;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //返回匹配回传地址
 | 
	
		
			
				|  |  | +            return URIUtil.decodeURIComponent(callBack);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.error("匹配监测链接异常, wechatOpenid : {}, clickId : {}", wechatOpenid, clickId);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //注册回传
 | 
	
		
			
				|  |  | -        gameTencentMiniGameBackLogService.linkCallBack(callback);
 | 
	
		
			
				|  |  | +        return null;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |