Bläddra i källkod

fix : 提交用户访问下载地址提交记录接口

bilingfeng 1 år sedan
förälder
incheckning
f75f04b49f

+ 71 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/UserVisitLog.java

@@ -0,0 +1,71 @@
+package com.zanxiang.game.module.mybatis.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-24
+ * @description : 用户访问下载地址记录
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString
+@Builder
+@TableName("t_user_visit_log")
+public class UserVisitLog implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键id
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 游戏id
+     */
+    private Long gameId;
+
+    /**
+     * 渠道id
+     */
+    private Long agentId;
+
+    /**
+     * 访问ip
+     */
+    private String ip;
+
+    /**
+     * 访问ua
+     */
+    private String ua;
+
+    /**
+     * 访问链接
+     */
+    private String url;
+
+    /**
+     * 链接参数
+     */
+    private String channel;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+}

+ 12 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/UserVisitLogMapper.java

@@ -0,0 +1,12 @@
+package com.zanxiang.game.module.mybatis.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zanxiang.game.module.mybatis.entity.UserVisitLog;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-24
+ * @description : ${description}
+ */
+public interface UserVisitLogMapper extends BaseMapper<UserVisitLog> {
+}

+ 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服务启动成功 <dubbo升级3.0, 用户渠道记录逻辑代码提交01> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <dubbo升级3.0, 提交用户访问下载地址提交记录接口> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 53 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/PushController.java

@@ -0,0 +1,53 @@
+package com.zanxiang.game.module.sdk.controller;
+
+import com.zanxiang.game.module.sdk.annotation.UnSignCheck;
+import com.zanxiang.game.module.sdk.pojo.param.GameRemitLogParam;
+import com.zanxiang.game.module.sdk.pojo.param.UserVisitLogParam;
+import com.zanxiang.game.module.sdk.service.IGameRemitLogService;
+import com.zanxiang.game.module.sdk.service.IUserVisitLogService;
+import com.zanxiang.module.util.pojo.ResultVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-17
+ * @description : 消息推送接收
+ */
+@Api(tags = "消息推送接收接口")
+@RestController
+@RequestMapping(value = "/api")
+public class PushController {
+
+    @Autowired
+    private IGameRemitLogService gameRemitLogService;
+
+    @Autowired
+    private IUserVisitLogService userVisitLogService;
+
+    @UnSignCheck
+    @ApiOperation(value = "游戏提现记录日志推送")
+    @PostMapping("/remit/log/push")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GameRemitLogParam param) {
+        return ResultVO.ok(gameRemitLogService.addOrUpdate(param));
+    }
+
+    @UnSignCheck
+    @ApiOperation(value = "用户下载地址访问记录")
+    @PostMapping("/visit/log/push")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> visitLogCreate(@Validated @RequestBody UserVisitLogParam param,
+                                            @RequestHeader(name = "User-Agent") String userAgent,
+                                            HttpServletRequest httpServletRequest) {
+        return ResultVO.ok(userVisitLogService.visitLogCreate(param.getUrl(), userAgent, httpServletRequest));
+    }
+
+}

+ 0 - 38
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/RemitController.java

@@ -1,38 +0,0 @@
-package com.zanxiang.game.module.sdk.controller;
-
-import com.zanxiang.game.module.sdk.annotation.UnSignCheck;
-import com.zanxiang.game.module.sdk.pojo.param.GameRemitLogParam;
-import com.zanxiang.game.module.sdk.service.IGameRemitLogService;
-import com.zanxiang.module.util.pojo.ResultVO;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * @author : lingfeng
- * @time : 2023-07-17
- * @description : 提现
- */
-@Api(tags = "注册登录接口")
-@RestController
-@RequestMapping(value = "/api/remit")
-public class RemitController {
-
-    @Autowired
-    private IGameRemitLogService gameRemitLogService;
-
-    @UnSignCheck
-    @ApiOperation(value = "游戏提现记录日志推送")
-    @PostMapping("/log/push")
-    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
-    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GameRemitLogParam param) {
-        return ResultVO.ok(gameRemitLogService.addOrUpdate(param));
-    }
-}

+ 22 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/param/UserVisitLogParam.java

@@ -0,0 +1,22 @@
+package com.zanxiang.game.module.sdk.pojo.param;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-24
+ * @description : 访问信息
+ */
+@Data
+public class UserVisitLogParam {
+
+    /**
+     * 访问url
+     */
+    @NotBlank(message = "访问url不可为空")
+    @ApiModelProperty(notes = "访问url")
+    private String url;
+}

+ 24 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IUserVisitLogService.java

@@ -0,0 +1,24 @@
+package com.zanxiang.game.module.sdk.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.mybatis.entity.UserVisitLog;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-24
+ * @description : 用户下载地址访问记录
+ */
+public interface IUserVisitLogService extends IService<UserVisitLog> {
+
+    /**
+     * 访问日志创建
+     *
+     * @param url                url
+     * @param userAgent          用户代理
+     * @param httpServletRequest http servlet请求
+     * @return boolean
+     */
+    boolean visitLogCreate(String url, String userAgent, HttpServletRequest httpServletRequest);
+}

+ 95 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/UserVisitLogServiceImpl.java

@@ -0,0 +1,95 @@
+package com.zanxiang.game.module.sdk.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.mybatis.entity.Agent;
+import com.zanxiang.game.module.mybatis.entity.UserVisitLog;
+import com.zanxiang.game.module.mybatis.mapper.UserVisitLogMapper;
+import com.zanxiang.game.module.sdk.service.IAgentService;
+import com.zanxiang.game.module.sdk.service.IUserVisitLogService;
+import com.zanxiang.module.web.util.IpUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.logging.log4j.util.Strings;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.http.HttpServletRequest;
+import java.net.URLDecoder;
+import java.time.LocalDateTime;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-24
+ * @description : 用户下载地址访问记录
+ */
+@Slf4j
+@Service
+public class UserVisitLogServiceImpl extends ServiceImpl<UserVisitLogMapper, UserVisitLog> implements IUserVisitLogService {
+
+    @Autowired
+    private IAgentService agentService;
+
+    @Override
+    public boolean visitLogCreate(String url, String userAgent, HttpServletRequest httpServletRequest) {
+        //解析url
+        Map<String, String> urlParamMap = this.getUrlParameter(url);
+        //获取渠道标识
+        String state = urlParamMap.get("agentId");
+        if (Strings.isBlank(state)) {
+            state = urlParamMap.get("agentKey");
+        }
+        //查询渠道信息
+        Agent agent = agentService.getOne(new LambdaQueryWrapper<Agent>().eq(Agent::getAgentKey, state));
+        //保存访问记录
+        return super.save(UserVisitLog.builder()
+                .gameId(agent == null ? null : agent.getGameId())
+                .gameId(agent == null ? null : agent.getId())
+                .ip(IpUtil.getRealIp(httpServletRequest))
+                .ua(userAgent)
+                .ua(urlParamMap.get("url"))
+                .channel(urlParamMap.get("channel"))
+                .createTime(LocalDateTime.now())
+                .updateTime(LocalDateTime.now())
+                .build());
+    }
+
+    /**
+     * 解析头条的url的host和参数
+     *
+     * @param url : 请求的url
+     * @return : 返回url中携带的参数的和host地址
+     */
+    private Map<String, String> getUrlParameter(String url) {
+        //参数判断
+        if (Strings.isBlank(url)) {
+            return Collections.emptyMap();
+        }
+        //没有拼接参数
+        if (url.indexOf('?') == -1) {
+            return Collections.singletonMap("url", url);
+        }
+        //参数map
+        Map<String, String> map = new HashMap<>(5);
+        try {
+            final String charset = "utf-8";
+            url = URLDecoder.decode(url, charset);
+            //添加url的host
+            map.put("url", url.substring(0, url.indexOf('?')));
+            map.put("channel", url.substring(url.indexOf('?')));
+            //解析参数
+            final String contents = url.substring(url.indexOf('?') + 1);
+            String[] keyValues = contents.split("&");
+            for (String keyValue : keyValues) {
+                String key = keyValue.substring(0, keyValue.indexOf("="));
+                String value = keyValue.substring(keyValue.indexOf("=") + 1);
+                map.put(key, value);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return map;
+    }
+}