Ver código fonte

fix : 新链路小程序登录信息上报

bilingfeng 11 meses atrás
pai
commit
b72a31c248

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 < (游戏聊天消息对接武哥接口´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (新链路小程序登录信息上报´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 38 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/api/AppletServerApi.java

@@ -0,0 +1,38 @@
+package com.zanxiang.game.module.manage.controller.api;
+
+import com.zanxiang.game.module.manage.pojo.params.UserAppletSubmitParam;
+import com.zanxiang.game.module.manage.service.IUserAppletService;
+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 lombok.extern.slf4j.Slf4j;
+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 : 2024-04-29
+ * @description : 小程序接口
+ */
+@Api(tags = {"小程序接口"})
+@RestController
+@RequestMapping("/api/applet")
+@Slf4j
+public class AppletServerApi {
+
+    @Autowired
+    private IUserAppletService userAppletService;
+
+    @ApiOperation(value = "小程序登录信息提交")
+    @PostMapping(value = "/user/submit")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> userAppletSubmit(@Validated @RequestBody UserAppletSubmitParam param) {
+        return ResultVO.ok(userAppletService.userAppletSubmit(param));
+    }
+}

+ 51 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/UserAppletSubmitParam.java

@@ -0,0 +1,51 @@
+package com.zanxiang.game.module.manage.pojo.params;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-04-29
+ * @description : 小程序用户信息提交
+ */
+@Data
+public class UserAppletSubmitParam {
+
+    /**
+     * 加密标识
+     */
+    @NotNull(message = "加密标识不可为空")
+    @ApiModelProperty(notes = "加密标识")
+    private String sign;
+
+    /**
+     * 请求时间
+     */
+    @NotNull(message = "请求时间不可为空")
+    @ApiModelProperty(notes = "请求时间, 时间戳 : 13位")
+    private Long signTime;
+
+    /**
+     * 应用id
+     */
+    @NotBlank(message = "应用id不可为空")
+    @ApiModelProperty(notes = "应用id")
+    private String appId;
+
+    /**
+     * 用户openId
+     */
+    @NotBlank(message = "用户openId不可为空")
+    @ApiModelProperty(notes = "用户openId")
+    private String openId;
+
+    /**
+     * 渠道参数
+     */
+    @NotBlank(message = "渠道参数不可为空")
+    @ApiModelProperty(notes = "渠道参数")
+    private String channel;
+}

+ 28 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IGameExtService.java

@@ -0,0 +1,28 @@
+package com.zanxiang.game.module.manage.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.mybatis.entity.GameExt;
+
+/**
+ * @author : lingfeng
+ * @time : 2022-09-23
+ * @description : 游戏密钥
+ */
+public interface IGameExtService extends IService<GameExt> {
+
+    /**
+     * 通过游戏id
+     *
+     * @param gameId 游戏id
+     * @return {@link GameExt}
+     */
+    GameExt getByGameId(Long gameId);
+
+    /**
+     * 通过游戏应用程序id
+     *
+     * @param appId 应用程序id
+     * @return {@link GameExt}
+     */
+    GameExt getByGameAppId(String appId);
+}

+ 21 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IUserAppletService.java

@@ -0,0 +1,21 @@
+package com.zanxiang.game.module.manage.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.manage.pojo.params.UserAppletSubmitParam;
+import com.zanxiang.game.module.mybatis.entity.UserApplet;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-04-29
+ * @description : 投放小程序用户信息
+ */
+public interface IUserAppletService extends IService<UserApplet> {
+
+    /**
+     * 小程序访问信息提交
+     *
+     * @param param : 提交参数
+     * @return : 返回结果
+     */
+    boolean userAppletSubmit(UserAppletSubmitParam param);
+}

+ 2 - 19
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/api/CpServerApiService.java

@@ -7,6 +7,7 @@ import com.zanxiang.game.module.manage.pojo.params.OpenGameServerParam;
 import com.zanxiang.game.module.manage.service.IGameServerService;
 import com.zanxiang.game.module.manage.service.IGameServerService;
 import com.zanxiang.game.module.manage.service.IGameSupperService;
 import com.zanxiang.game.module.manage.service.IGameSupperService;
 import com.zanxiang.game.module.manage.service.IListenCallService;
 import com.zanxiang.game.module.manage.service.IListenCallService;
+import com.zanxiang.game.module.manage.utils.SignUtil;
 import com.zanxiang.game.module.mybatis.entity.GameServer;
 import com.zanxiang.game.module.mybatis.entity.GameServer;
 import com.zanxiang.game.module.mybatis.entity.GameSupper;
 import com.zanxiang.game.module.mybatis.entity.GameSupper;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.JsonUtil;
@@ -17,8 +18,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.client.RestTemplate;
 
 
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map;
@@ -127,26 +126,10 @@ public class CpServerApiService {
     private void signCheck(String cpServerKey, Long gameId, String serverId, Long signTime, String sign) {
     private void signCheck(String cpServerKey, Long gameId, String serverId, Long signTime, String sign) {
         String signStr = "cpServerKey=" + cpServerKey + "gameId=" + gameId
         String signStr = "cpServerKey=" + cpServerKey + "gameId=" + gameId
                 + "serverId=" + serverId + "signTime=" + signTime;
                 + "serverId=" + serverId + "signTime=" + signTime;
-        log.error("请求加密字符串 signStr : {}", signStr);
-        String mySign = this.md5(signStr);
+        String mySign = SignUtil.md5(signStr, Boolean.TRUE);
         if (Objects.equals(mySign, sign)) {
         if (Objects.equals(mySign, sign)) {
             log.error("加密验证失败, sign : {}, mySign : {}", sign, mySign);
             log.error("加密验证失败, sign : {}, mySign : {}", sign, mySign);
             throw new BaseException("加密标识错误");
             throw new BaseException("加密标识错误");
         }
         }
     }
     }
-
-    private String md5(String data) {
-        try {
-            java.security.MessageDigest md = MessageDigest.getInstance("MD5");
-            byte[] array = md.digest(data.getBytes(StandardCharsets.UTF_8));
-            StringBuilder sb = new StringBuilder();
-            for (byte item : array) {
-                sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3);
-            }
-            return sb.toString().toUpperCase();
-        } catch (Exception e) {
-            log.error("MD5加密异常, data : {}", data);
-            throw new BaseException("MD5加密异常");
-        }
-    }
 }
 }

+ 29 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameExtServiceImpl.java

@@ -0,0 +1,29 @@
+package com.zanxiang.game.module.manage.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.manage.service.IGameExtService;
+import com.zanxiang.game.module.mybatis.entity.GameExt;
+import com.zanxiang.game.module.mybatis.mapper.GameExtMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author : lingfeng
+ * @time : 2022-09-23
+ * @description : 游戏密钥
+ */
+@Slf4j
+@Service
+public class GameExtServiceImpl extends ServiceImpl<GameExtMapper, GameExt> implements IGameExtService {
+
+    @Override
+    public GameExt getByGameId(Long gameId) {
+        return this.getOne(new LambdaQueryWrapper<GameExt>().eq(GameExt::getGameId, gameId));
+    }
+
+    @Override
+    public GameExt getByGameAppId(String appId) {
+        return this.getOne(new LambdaQueryWrapper<GameExt>().eq(GameExt::getAppId, appId));
+    }
+}

+ 73 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/UserAppletServiceImpl.java

@@ -0,0 +1,73 @@
+package com.zanxiang.game.module.manage.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.base.pojo.enums.DeleteEnum;
+import com.zanxiang.game.module.manage.pojo.params.UserAppletSubmitParam;
+import com.zanxiang.game.module.manage.service.IGameAppletService;
+import com.zanxiang.game.module.manage.service.IGameExtService;
+import com.zanxiang.game.module.manage.service.IUserAppletService;
+import com.zanxiang.game.module.manage.utils.SignUtil;
+import com.zanxiang.game.module.mybatis.entity.GameApplet;
+import com.zanxiang.game.module.mybatis.entity.GameExt;
+import com.zanxiang.game.module.mybatis.entity.UserApplet;
+import com.zanxiang.game.module.mybatis.mapper.UserAppletMapper;
+import com.zanxiang.module.util.JsonUtil;
+import com.zanxiang.module.util.exception.BaseException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.Objects;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-04-29
+ * @description : 投放小程序用户信息
+ */
+@Slf4j
+@Service
+public class UserAppletServiceImpl extends ServiceImpl<UserAppletMapper, UserApplet> implements IUserAppletService {
+
+    @Autowired
+    private IGameAppletService gameAppletService;
+
+    @Autowired
+    private IGameExtService gameExtService;
+
+    @Override
+    public boolean userAppletSubmit(UserAppletSubmitParam param) {
+        GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>()
+                .eq(GameApplet::getAppId, param.getAppId())
+                .last("limit 1"));
+        if (gameApplet == null) {
+            log.error("非法参数, 小程序信息不存在, param : {}", JsonUtil.toString(param));
+            throw new BaseException("非法参数, 小程序信息不存在");
+        }
+        GameExt gameExt = gameExtService.getByGameId(gameApplet.getGameId());
+        this.signCheck(gameExt.getLoginKey(), param);
+        return super.save(this.transform(param));
+    }
+
+    private UserApplet transform(UserAppletSubmitParam param) {
+        return UserApplet.builder()
+                .appId(param.getAppId())
+                .openId(param.getOpenId())
+                .channel(param.getChannel())
+                .isDelete(DeleteEnum.NO.getCode())
+                .createTime(LocalDateTime.now())
+                .updateTime(LocalDateTime.now())
+                .build();
+    }
+
+    private void signCheck(String loginKey, UserAppletSubmitParam param) {
+        String signStr = "cpServerKey=" + loginKey + "appId=" + param.getAppId()
+                + "openId=" + param.getOpenId() + "signTime=" + param.getSignTime();
+        String mySign = SignUtil.md5(signStr, Boolean.TRUE);
+        if (Objects.equals(mySign, param.getSign())) {
+            log.error("加密验证失败, sign : {}, mySign : {}", param.getSign(), mySign);
+            throw new BaseException("加密标识错误");
+        }
+    }
+}

+ 37 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/utils/SignUtil.java

@@ -0,0 +1,37 @@
+package com.zanxiang.game.module.manage.utils;
+
+import com.zanxiang.module.util.exception.BaseException;
+import lombok.extern.slf4j.Slf4j;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+
+/**
+ * @author : lingfeng
+ * @time : 2022-09-23
+ * @description : 签名算法工具类
+ */
+@Slf4j
+public class SignUtil {
+
+    /**
+     * MD5加密
+     *
+     * @param data 待处理数据
+     * @return MD5结果
+     */
+    public static String md5(String data, boolean upperCase) {
+        try {
+            java.security.MessageDigest md = MessageDigest.getInstance("MD5");
+            byte[] array = md.digest(data.getBytes(StandardCharsets.UTF_8));
+            StringBuilder sb = new StringBuilder();
+            for (byte item : array) {
+                sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3);
+            }
+            return upperCase ? sb.toString().toUpperCase() : sb.toString();
+        } catch (Exception e) {
+            log.error("MD5加密异常, data : {}", data);
+            throw new BaseException("MD5加密异常");
+        }
+    }
+}

+ 63 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/UserApplet.java

@@ -0,0 +1,63 @@
+package com.zanxiang.game.module.mybatis.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-04-29
+ * @description : 投放小程序用户信息
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString
+@Builder
+@TableName("t_user_applet")
+public class UserApplet implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 应用id
+     */
+    private String appId;
+
+    /**
+     * 用户openId
+     */
+    private String openId;
+
+    /**
+     * 渠道参数
+     */
+    private String channel;
+
+    /**
+     * 1 伪删除  0正常
+     */
+    @TableLogic
+    private Integer isDelete;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+}

+ 12 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/UserAppletMapper.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.UserApplet;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-04-29
+ * @description : ${description}
+ */
+public interface UserAppletMapper extends BaseMapper<UserApplet> {
+}