|
@@ -0,0 +1,125 @@
|
|
|
+package com.zanxiang.game.back.serve.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zanxiang.game.back.serve.dao.mapper.GameOceanengineAppCallbackXgltMapper;
|
|
|
+import com.zanxiang.game.back.serve.pojo.entity.GameOceanengineAppCallbackXglt;
|
|
|
+import com.zanxiang.game.back.serve.pojo.entity.GameOceanengineAppUserLog;
|
|
|
+import com.zanxiang.game.back.serve.service.GameOceanengineAppCallbackXgltService;
|
|
|
+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.util.DateUtil;
|
|
|
+import com.zanxiang.module.util.JsonUtil;
|
|
|
+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.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class GameOceanengineAppCallbackXgltServiceImpl extends ServiceImpl<GameOceanengineAppCallbackXgltMapper, GameOceanengineAppCallbackXglt>
|
|
|
+ implements GameOceanengineAppCallbackXgltService {
|
|
|
+
|
|
|
+ @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
|
|
|
+ private IAgentRpc agentRpc;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean callback(Map<String, Object> paramMap) {
|
|
|
+ try {
|
|
|
+ GameOceanengineAppCallbackXglt callback = JsonUtil.toObj(JsonUtil.toString(paramMap), GameOceanengineAppCallbackXglt.class);
|
|
|
+ callback.setDay(callback.getTs() == null || callback.getTs() < 1000 ? LocalDate.now() : DateUtil.milliToLocalDate(callback.getTs()));
|
|
|
+ callback.setCreateTime(LocalDateTime.now());
|
|
|
+ save(callback);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("接收到头条星广联投测链接数据保存异常, paramMap : {}, errorMsg : {}", JsonUtil.toString(paramMap), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getCallBackParamByUser(GameOceanengineAppUserLog userLog) {
|
|
|
+ //没有渠道标识, 无法匹配
|
|
|
+ if (StringUtils.isBlank(userLog.getAgentKey())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ ResultVO<List<AgentRpcVO>> resultVO = agentRpc.getByAgentKeys(Collections.singletonList(userLog.getAgentKey()));
|
|
|
+ Long demandId = Optional.ofNullable(resultVO).map(ResultVO::getData)
|
|
|
+ .filter(list -> !list.isEmpty()).map(list -> list.get(0))
|
|
|
+ .map(AgentRpcVO::getXgltDemandId).orElse(null);
|
|
|
+ if (demandId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ GameOceanengineAppCallbackXglt callBack = this.getCallBack(demandId, userLog.getAndroidId(), userLog.getOaid(),
|
|
|
+ userLog.getImei(), userLog.getActiveTime());
|
|
|
+ return callBack == null ? null : callBack.getCallbackParam();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("头条APP玩家匹配星广联投监测链接数据异常, userLogId : {}, e : {}", JsonUtil.toString(userLog), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private GameOceanengineAppCallbackXglt getCallBack(Long demandId, String androidId, String oaid, String imei, LocalDateTime regTime) {
|
|
|
+ //星广联投任务id不存在, 不可匹配
|
|
|
+ if (demandId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<GameOceanengineAppCallbackXglt> queryWrapper = new LambdaQueryWrapper<GameOceanengineAppCallbackXglt>()
|
|
|
+ .lt(GameOceanengineAppCallbackXglt::getTs, DateUtil.localDateTimeToMilli(regTime))
|
|
|
+ .eq(GameOceanengineAppCallbackXglt::getDemandId, demandId)
|
|
|
+ .orderByDesc(GameOceanengineAppCallbackXglt::getTs)
|
|
|
+ .last("limit 1");
|
|
|
+ //条件匹配
|
|
|
+ queryWrapper.and(qw -> {
|
|
|
+ boolean hasCondition = false;
|
|
|
+ //安卓id匹配
|
|
|
+ if (StringUtils.isNoneBlank(androidId)) {
|
|
|
+ qw.or().eq(GameOceanengineAppCallbackXglt::getAndroidIdMd5, Md5Util.encrypt32(androidId));
|
|
|
+ hasCondition = true;
|
|
|
+ }
|
|
|
+ //oaid匹配
|
|
|
+ if (StringUtils.isNoneBlank(oaid)) {
|
|
|
+ qw.or().eq(GameOceanengineAppCallbackXglt::getOaidMd5, Md5Util.encrypt32(oaid));
|
|
|
+ hasCondition = true;
|
|
|
+ }
|
|
|
+ //imei匹配
|
|
|
+ if (StringUtils.isNoneBlank(imei)) {
|
|
|
+ qw.or().eq(GameOceanengineAppCallbackXglt::getImeiMd5, Md5Util.encrypt32(imei));
|
|
|
+ hasCondition = true;
|
|
|
+ }
|
|
|
+ // 避免无条件的OR查询
|
|
|
+ if (!hasCondition) {
|
|
|
+ qw.or().apply("1=0");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //返回星广联投监测链接数据
|
|
|
+ return super.getOne(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String doCallBack(String callback, String eventType, Long amount) {
|
|
|
+ Map<String, String> paramMap = new HashMap<>(3);
|
|
|
+ paramMap.put("callback", callback);
|
|
|
+ paramMap.put("event_type", eventType);
|
|
|
+ //付费回传
|
|
|
+ if (Objects.equals(eventType, "2") && amount != null) {
|
|
|
+ Map<String, String> payAmount = Collections.singletonMap("pay_amount", amount.toString());
|
|
|
+ paramMap.put("props", URIUtil.encodeURIComponent(JsonUtil.toString(payAmount)));
|
|
|
+ }
|
|
|
+ String uri = URIUtil.fillUrlParams("https://ad.oceanengine.com/track/activate/", paramMap, false);
|
|
|
+ return restTemplate.getForObject(uri, String.class);
|
|
|
+ }
|
|
|
+}
|