Bladeren bron

Merge branch 'package' of GameCenter/game-center into dev

zhimo 5 maanden geleden
bovenliggende
commit
0911179a40

+ 5 - 0
game-module/game-module-manage/pom.xml

@@ -137,6 +137,11 @@
             <artifactId>commons-io</artifactId>
             <version>2.11.0</version>
         </dependency>
+        <!--sms集成-->
+        <dependency>
+            <groupId>com.zanxiang.module</groupId>
+            <artifactId>zx-sms</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 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) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 < (发码器后台代码提交03・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (发码器后台代码提交04・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 4 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/constant/RedisKeyConstant.java

@@ -42,4 +42,8 @@ public class RedisKeyConstant {
      */
     public static final String GAME_USER_ROLE_UP_LOCK = RedisKeyConstant.REDIS_PREFIX + "gameUserRoleUpLock_";
 
+    /**
+     * 手机验证码缓存key
+     */
+    public static final String SMS_PHONE_KEY = RedisKeyConstant.REDIS_PREFIX + "sms_phone";
 }

+ 10 - 5
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/api/GameGiftPackApi.java

@@ -10,10 +10,9 @@ 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;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
 
 /**
  * @author : lingfeng
@@ -29,11 +28,17 @@ public class GameGiftPackApi {
     @Autowired
     private IGameGiftPackLinkLogService gameGiftPackLinkLogService;
 
-    @ApiOperation(value = "链接访问记录推送接口")
+    @ApiOperation(value = "链接访问记录推送提交")
     @PostMapping(value = "/link/log/push")
     @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Long.class)})
     public ResultVO<Long> linkList(@Validated @RequestBody GameGiftPackLinkLogPushParam param) {
         return ResultVO.ok(gameGiftPackLinkLogService.linkVisitLogPush(param.getUrl()));
     }
 
+    @ApiOperation(value = "获取游戏区服列表")
+    @GetMapping(value = "/source/game/server")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Long.class)})
+    public ResultVO<Map<String, String>> getSourceGameServer(@RequestParam Long linkLogId) {
+        return ResultVO.ok(gameGiftPackLinkLogService.getSourceGameServer(linkLogId));
+    }
 }

+ 36 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/api/SmsController.java

@@ -0,0 +1,36 @@
+package com.zanxiang.game.module.manage.controller.api;
+
+import com.zanxiang.game.module.manage.service.ISmsService;
+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.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-11-04
+ * @description : 手机短信接口
+ */
+@Slf4j
+@Api(tags = {"手机短信接口"})
+@RestController
+@RequestMapping("/api/sms")
+public class SmsController {
+
+    @Autowired
+    private ISmsService smsService;
+
+    @ApiOperation(value = "手机验证码发送")
+    @GetMapping(value = "/random/code/send")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> randomCodeSend(@RequestParam String phoneNumber) {
+        return ResultVO.ok(smsService.randomCodeSend(phoneNumber));
+    }
+}

+ 12 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/GameGiftPackCodeVO.java

@@ -37,12 +37,24 @@ public class GameGiftPackCodeVO {
     @ApiModelProperty(notes = "创建者")
     private String createByName;
 
+    /**
+     * 创建者
+     */
+    @ApiModelProperty(notes = "创建者")
+    private Long createBy;
+
     /**
      * 创建时间
      */
     @ApiModelProperty(notes = "创建时间")
     private LocalDateTime createTime;
 
+    /**
+     * 更新者
+     */
+    @ApiModelProperty(notes = "更新者")
+    private Long updateBy;
+
     /**
      * 更新者
      */

+ 24 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/GameGiftPackLinkVO.java

@@ -20,12 +20,24 @@ public class GameGiftPackLinkVO {
     @ApiModelProperty(notes = "主键")
     private Long id;
 
+    /**
+     * 游戏id
+     */
+    @ApiModelProperty(notes = "游戏id")
+    private Long gameId;
+
     /**
      * 游戏名称
      */
     @ApiModelProperty(notes = "游戏名称")
     private String gameName;
 
+    /**
+     * 礼包码类型
+     */
+    @ApiModelProperty(notes = "礼包码类型")
+    private String codeType;
+
     /**
      * 礼包码类型名称
      */
@@ -50,12 +62,24 @@ public class GameGiftPackLinkVO {
     @ApiModelProperty(notes = "更新者名字")
     private String createByName;
 
+    /**
+     * 创建者
+     */
+    @ApiModelProperty(notes = "创建者")
+    private Long createBy;
+
     /**
      * 创建时间
      */
     @ApiModelProperty(notes = "创建时间")
     private LocalDateTime createTime;
 
+    /**
+     * 更新者
+     */
+    @ApiModelProperty(notes = "更新者")
+    private Long updateBy;
+
     /**
      * 更新者名字
      */

+ 10 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IGameGiftPackLinkLogService.java

@@ -6,6 +6,8 @@ import com.zanxiang.game.module.manage.pojo.params.GameGiftPackLinkLogListParam;
 import com.zanxiang.game.module.manage.pojo.vo.GameGiftPackLinkLogVO;
 import com.zanxiang.game.module.mybatis.entity.GameGiftPackLinkLog;
 
+import java.util.Map;
+
 /**
  * @author : lingfeng
  * @time : 2022-09-23
@@ -28,4 +30,12 @@ public interface IGameGiftPackLinkLogService extends IService<GameGiftPackLinkLo
      * @return : 返回数据列表
      */
     IPage<GameGiftPackLinkLogVO> list(GameGiftPackLinkLogListParam param);
+
+    /**
+     * 获取游戏原始区服信息
+     *
+     * @param linkLogId : 访问日志id
+     * @return : 返回游戏区服信息
+     */
+    Map<String, String> getSourceGameServer(Long linkLogId);
 }

+ 26 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/ISmsService.java

@@ -0,0 +1,26 @@
+package com.zanxiang.game.module.manage.service;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-11-04
+ * @description :
+ */
+public interface ISmsService {
+
+    /**
+     * 发送短信验证码
+     *
+     * @param phoneNumber : 手机号
+     * @return : 返回结果
+     */
+    boolean randomCodeSend(String phoneNumber);
+
+    /**
+     * 验证码校验
+     *
+     * @param phoneNumber : 手机号
+     * @param randomCode  : 验证码
+     * @return : 返回验证结果
+     */
+    boolean randomCodeCheck(String phoneNumber, String randomCode);
+}

+ 9 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameGiftPackCodeLogServiceImpl.java

@@ -6,10 +6,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zanxiang.game.module.manage.pojo.params.GameGiftPackCodeLogListParam;
 import com.zanxiang.game.module.manage.pojo.vo.GameGiftPackCodeLogVO;
 import com.zanxiang.game.module.manage.service.IGameGiftPackCodeLogService;
+import com.zanxiang.game.module.manage.service.IGameUserRoleService;
 import com.zanxiang.game.module.mybatis.entity.GameGiftPackCodeLog;
 import com.zanxiang.game.module.mybatis.mapper.GameGiftPackCodeLogMapper;
 import com.zanxiang.module.util.bean.BeanUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import reactor.util.function.Tuple2;
 
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -22,6 +25,9 @@ import java.time.LocalTime;
 @Service
 public class GameGiftPackCodeLogServiceImpl extends ServiceImpl<GameGiftPackCodeLogMapper, GameGiftPackCodeLog> implements IGameGiftPackCodeLogService {
 
+    @Autowired
+    private IGameUserRoleService gameUserRoleService;
+
     @Override
     public IPage<GameGiftPackCodeLogVO> list(GameGiftPackCodeLogListParam param) {
         return page(param.toPage(), new QueryWrapper<GameGiftPackCodeLog>().lambda()
@@ -32,4 +38,7 @@ public class GameGiftPackCodeLogServiceImpl extends ServiceImpl<GameGiftPackCode
         ).convert(log -> BeanUtil.copy(log, GameGiftPackCodeLogVO.class));
     }
 
+    public Tuple2<Boolean, String> gameRoleCheck(String gameServerId, String roleName) {
+        return null;
+    }
 }

+ 26 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameGiftPackLinkLogServiceImpl.java

@@ -5,12 +5,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
 import com.zanxiang.game.module.manage.pojo.params.GameGiftPackLinkLogListParam;
 import com.zanxiang.game.module.manage.pojo.vo.GameGiftPackLinkLogVO;
 import com.zanxiang.game.module.manage.service.IGameGiftPackLinkLogService;
 import com.zanxiang.game.module.manage.service.IGameGiftPackLinkService;
+import com.zanxiang.game.module.manage.service.IGameServerService;
+import com.zanxiang.game.module.manage.service.IGameService;
 import com.zanxiang.game.module.mybatis.entity.GameGiftPackLink;
 import com.zanxiang.game.module.mybatis.entity.GameGiftPackLinkLog;
+import com.zanxiang.game.module.mybatis.entity.GameServer;
 import com.zanxiang.game.module.mybatis.mapper.GameGiftPackLinkLogMapper;
 import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.exception.BaseException;
@@ -26,6 +30,7 @@ import java.time.LocalTime;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author : lingfeng
@@ -36,6 +41,12 @@ import java.util.Map;
 @Service
 public class GameGiftPackLinkLogServiceImpl extends ServiceImpl<GameGiftPackLinkLogMapper, GameGiftPackLinkLog> implements IGameGiftPackLinkLogService {
 
+    @Autowired
+    private IGameService gameService;
+
+    @Autowired
+    private IGameServerService gameServerService;
+
     @Autowired
     private IGameGiftPackLinkService gameGiftPackLinkService;
 
@@ -49,6 +60,21 @@ public class GameGiftPackLinkLogServiceImpl extends ServiceImpl<GameGiftPackLink
         ).convert(log -> BeanUtil.copy(log, GameGiftPackLinkLogVO.class));
     }
 
+    @Override
+    public Map<String, String> getSourceGameServer(Long linkLogId) {
+        //查询访问日志
+        GameGiftPackLinkLog gameGiftPackLinkLog = super.getById(linkLogId);
+        assert gameGiftPackLinkLog != null : "参数错误, 链接访问日志信息不存在";
+        //查询游戏信息
+        GameDTO gameDTO = gameService.getById(gameGiftPackLinkLog.getGameId());
+        assert gameDTO != null : "参数错误, 游戏信息不存在";
+        //查询区服信息
+        return gameServerService.list(new LambdaQueryWrapper<GameServer>()
+                .eq(GameServer::getGameId, gameDTO.getSuperGameId())
+                .eq(GameServer::getIsSourceServer, Boolean.TRUE)
+        ).stream().collect(Collectors.toMap(GameServer::getServerId, GameServer::getServerName));
+    }
+
     @Override
     public Long linkVisitLogPush(String url) {
         Map<String, String> urlParameter = this.getUrlParameter(url);

+ 67 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/SmsServiceImpl.java

@@ -0,0 +1,67 @@
+package com.zanxiang.game.module.manage.service.impl;
+
+import cn.hutool.core.util.RandomUtil;
+import com.zanxiang.game.module.manage.constant.RedisKeyConstant;
+import com.zanxiang.game.module.manage.enums.ExpireTimeEnum;
+import com.zanxiang.game.module.manage.service.ISmsService;
+import com.zanxiang.game.module.manage.utils.RedisUtil;
+import com.zanxiang.module.sms.pojo.SendResult;
+import com.zanxiang.module.sms.service.impl.AliSmsService;
+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 java.util.Objects;
+import java.util.regex.Pattern;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-11-04
+ * @description : 短信验证码
+ */
+@Slf4j
+@Service
+public class SmsServiceImpl implements ISmsService {
+
+    @Autowired
+    private RedisUtil<String> redisUtil;
+
+    @Autowired
+    private AliSmsService aliSmsService;
+
+    @Override
+    public boolean randomCodeSend(String phoneNumber) {
+        //判断是否已经发送
+        String smsKey = RedisKeyConstant.SMS_PHONE_KEY + "_" + phoneNumber;
+        assert Strings.isBlank(redisUtil.getCache(smsKey)) : "验证码已发送请稍后再试";
+        //发送验证码
+        String randomCode = RandomUtil.randomNumbers(6);
+        //发送短信验证码
+        this.smsSendApi(randomCode, phoneNumber);
+        //发送成功设置缓存, 时效5分钟
+        return redisUtil.setCache(smsKey, randomCode, ExpireTimeEnum.FIVE_MIN.getTime());
+    }
+
+    @Override
+    public boolean randomCodeCheck(String phoneNumber, String randomCode) {
+        String smsKey = RedisKeyConstant.SMS_PHONE_KEY + "_" + phoneNumber;
+        //获取缓存中的验证码
+        String cache = redisUtil.getCache(smsKey);
+        //验证码已过期
+        assert Strings.isNotBlank(cache) : "验证码已过期";
+        //验证码错误
+        assert Objects.equals(cache, randomCode) : "验证码错误";
+        //验证成功, 删除缓存
+        return redisUtil.deleteCache(smsKey);
+    }
+
+    private void smsSendApi(String content, String phoneNumber) {
+        //验证手机号
+        assert Pattern.matches("^1[3-9]\\d{9}$", phoneNumber) : "手机号格式错误";
+        //发送短信
+        SendResult sendResult = aliSmsService.sendCode(content, phoneNumber);
+        //发送结果判断
+        assert sendResult.isSuccess() : "验证码发送失败";
+    }
+}