Jelajahi Sumber

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

zhimo 1 tahun lalu
induk
melakukan
c910016d98

+ 1 - 1
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/pojo/enums/HttpStatusEnum.java

@@ -35,7 +35,7 @@ public enum HttpStatusEnum {
     /**
      * 请先登录
      */
-    USER_NO_LOGIN(40400, "请登录"),
+    USER_NO_LOGIN(40400, "登录信息已失效, 重新登录"),
 
     /**
      * 用户名为空

+ 5 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameExt.java

@@ -69,6 +69,11 @@ public class GameExt implements Serializable {
      */
     private Boolean adCallBackSwitch;
 
+    /**
+     * 小游戏壳包控制开关
+     */
+    private Boolean appletShellSwitch;
+
     /**
      * 客服手机
      */

+ 14 - 5
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/InitController.java

@@ -2,7 +2,7 @@ package com.zanxiang.game.module.sdk.controller;
 
 import com.zanxiang.game.module.sdk.annotation.UnSignCheck;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
-import com.zanxiang.game.module.sdk.pojo.vo.GameAppletVO;
+import com.zanxiang.game.module.sdk.pojo.vo.GameInitVO;
 import com.zanxiang.game.module.sdk.service.IGameAppletService;
 import com.zanxiang.module.util.pojo.ResultVO;
 import io.swagger.annotations.Api;
@@ -12,6 +12,7 @@ import io.swagger.annotations.ApiResponses;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
@@ -28,10 +29,18 @@ public class InitController {
     private IGameAppletService gameAppletService;
 
     @UnSignCheck
-    @ApiOperation(value = "微信小游戏sdk初始化")
+    @ApiOperation(value = "(H5和微信小游戏)SDK参数初始化")
     @PostMapping("/applet")
-    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameAppletVO.class)})
-    public ResultVO<GameAppletVO> gameAppletInit(UserData userData) {
-        return ResultVO.ok(gameAppletService.gameAppletInit(userData));
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameInitVO.class)})
+    public ResultVO<GameInitVO> h5AndAppletInit(UserData userData) {
+        return ResultVO.ok(gameAppletService.h5AndAppletInit(userData));
+    }
+
+    @UnSignCheck
+    @ApiOperation(value = "微信小游戏壳包控制开关")
+    @PostMapping("/shell/switch")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> appletShellSwitch(@RequestParam String appId) {
+        return ResultVO.ok(gameAppletService.appletShellSwitch(appId));
     }
 }

+ 0 - 32
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/vo/GameAppletVO.java

@@ -1,32 +0,0 @@
-package com.zanxiang.game.module.sdk.pojo.vo;
-
-import io.swagger.annotations.ApiModelProperty;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-/**
- * @author : lingfeng
- * @time : 2023-01-03
- * @description : 微信小游戏初始化
- */
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class GameAppletVO {
-
-    /**
-     * 应用appId
-     */
-    @ApiModelProperty(notes = "应用appId")
-    private String appId;
-
-    /**
-     * 是否投放
-     */
-    @ApiModelProperty(notes = "是否投放")
-    private Boolean isPut;
-
-}

+ 12 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/vo/GameInitVO.java

@@ -1,7 +1,10 @@
 package com.zanxiang.game.module.sdk.pojo.vo;
 
 import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 /**
  * @author : lingfeng
@@ -9,6 +12,9 @@ import lombok.Data;
  * @description : 游戏初始化
  */
 @Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
 public class GameInitVO {
 
     /**
@@ -23,6 +29,12 @@ public class GameInitVO {
     @ApiModelProperty(notes = "游戏应用(小游戏/公众号)appId")
     private String appId;
 
+    /**
+     * 前端appKey
+     */
+    @ApiModelProperty(notes = "前端appKey")
+    private String appKey;
+
     /**
      * H5游戏是否使用应用授权登录
      */

+ 12 - 3
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IGameAppletService.java

@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.zanxiang.game.module.mybatis.entity.GameApplet;
 import com.zanxiang.game.module.sdk.pojo.dto.GameAppletDTO;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
-import com.zanxiang.game.module.sdk.pojo.vo.GameAppletVO;
+import com.zanxiang.game.module.sdk.pojo.vo.GameInitVO;
 
 /**
  * @author : lingfeng
@@ -33,6 +33,7 @@ public interface IGameAppletService extends IService<GameApplet> {
      * @param signature 签名
      * @param timestamp 时间戳
      * @param nonce     现时标志
+     * @param postData  post数据
      * @return {@link String}
      * @throws Exception 异常
      */
@@ -58,7 +59,15 @@ public interface IGameAppletService extends IService<GameApplet> {
      * 微信小游戏初始化获取信息
      *
      * @param userData : 用户信息
-     * @return {@link GameAppletVO}
+     * @return {@link GameInitVO}
      */
-    GameAppletVO gameAppletInit(UserData userData);
+    GameInitVO h5AndAppletInit(UserData userData);
+
+    /**
+     * 小游戏壳包控制开关
+     *
+     * @param appId 应用程序id
+     * @return boolean
+     */
+    boolean appletShellSwitch(String appId);
 }

+ 29 - 5
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameAppletServiceImpl.java

@@ -5,12 +5,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zanxiang.game.module.base.pojo.enums.HttpStatusEnum;
 import com.zanxiang.game.module.mybatis.entity.Game;
 import com.zanxiang.game.module.mybatis.entity.GameApplet;
+import com.zanxiang.game.module.mybatis.entity.GameExt;
 import com.zanxiang.game.module.mybatis.entity.Order;
 import com.zanxiang.game.module.mybatis.mapper.GameAppletMapper;
 import com.zanxiang.game.module.sdk.enums.OrderStateEnum;
 import com.zanxiang.game.module.sdk.pojo.dto.*;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
-import com.zanxiang.game.module.sdk.pojo.vo.GameAppletVO;
+import com.zanxiang.game.module.sdk.pojo.vo.GameInitVO;
 import com.zanxiang.game.module.sdk.service.*;
 import com.zanxiang.game.module.sdk.service.api.WxApiService;
 import com.zanxiang.game.module.sdk.util.SignUtil;
@@ -61,6 +62,9 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
     @Autowired
     private IGameService gameService;
 
+    @Autowired
+    private IGameExtService gameExtService;
+
     @Value("${payConfig.wxPay.customH5Url}")
     private String customH5Url;
 
@@ -184,13 +188,33 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
     }
 
     @Override
-    public GameAppletVO gameAppletInit(UserData userData) {
+    public GameInitVO h5AndAppletInit(UserData userData) {
+        //游戏
+        Game game = gameService.getById(userData.getGameId());
+        if (game == null) {
+            throw new BaseException("参数错误, 游戏信息不存在");
+        }
+        //游戏应用信息
         GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()
                 .eq(GameApplet::getGameId, userData.getGameId()));
-        Game game = gameService.getById(userData.getGameId());
-        return GameAppletVO.builder()
+        GameExt gameExt = gameExtService.getByGameId(userData.getGameId());
+        //构造初始化信息
+        return GameInitVO.builder()
                 .appId(gameApplet == null ? null : gameApplet.getAppId())
-                .isPut(game.getParentId() == null)
+                .appKey(gameExt == null ? null : gameExt.getAppKey())
+                .gameName(game.getName())
+                .isPut(game.getIsPut())
+                .h5GameUrl(game.getH5GameUrl())
+                .h5LoginLogo(game.getH5LoginLogo())
                 .build();
     }
+
+    @Override
+    public boolean appletShellSwitch(String appId) {
+        GameExt gameExt = gameExtService.getByGameAppId(appId);
+        if (gameExt == null || gameExt.getAppletShellSwitch() == null) {
+            return false;
+        }
+        return gameExt.getAppletShellSwitch();
+    }
 }

+ 9 - 10
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/LoginServiceImpl.java

@@ -107,18 +107,17 @@ public class LoginServiceImpl implements IRegisterLoginService {
                 .eq(User::getGameId, userData.getGameId()).eq(User::getOpenId, openId));
         //已注册
         if (user != null) {
+            //账号停用, 返回登录失败
+            if (Objects.equals(BanStatusEnum.BAN_STATUS.getStatus(), user.getStatus())) {
+                return ResultVO.fail(HttpStatusEnum.ACCOUNT_HALT.getMsg());
+            }
             //更新用户sessionKey
             if (Strings.isNotBlank(sessionKey)) {
                 userService.update(new LambdaUpdateWrapper<User>()
-                        .set(User::getSessionKey, sessionKey)
-                        .eq(User::getId, user.getId()));
+                        .set(User::getSessionKey, sessionKey).eq(User::getId, user.getId()));
             }
             //渠道更新和回传判断
             agentService.userAgentUpdate(user, userData.getChannel());
-            //判断账号是否停用
-            if (Objects.equals(BanStatusEnum.BAN_STATUS.getStatus(), user.getStatus())) {
-                return ResultVO.fail(HttpStatusEnum.ACCOUNT_HALT.getMsg());
-            }
             //返回登录信息
             return ResultVO.ok(this.createUserLoginVO(user, userData));
         }
@@ -153,8 +152,6 @@ public class LoginServiceImpl implements IRegisterLoginService {
                 user = userService.getOne(new LambdaQueryWrapper<User>()
                         .eq(User::getGameId, userData.getGameId()).eq(User::getUsername, username));
             }
-            //渠道更新和回传判断
-            agentService.userAgentUpdate(user, userData.getChannel());
             //用户信息不存在
             if (user == null) {
                 return ResultVO.fail(HttpStatusEnum.USERNAME_OR_PASSWORD_ERR.getMsg());
@@ -167,6 +164,8 @@ public class LoginServiceImpl implements IRegisterLoginService {
             if (!Objects.equals(RegisterUtil.cmfPassword(password), user.getPassword())) {
                 return ResultVO.fail(HttpStatusEnum.USERNAME_OR_PASSWORD_ERR.getMsg());
             }
+            //渠道更新和回传判断
+            agentService.userAgentUpdate(user, userData.getChannel());
             //返回登录信息
             return ResultVO.ok(this.createUserLoginVO(user, userData));
         }
@@ -201,12 +200,12 @@ public class LoginServiceImpl implements IRegisterLoginService {
                 .eq(User::getGameId, userData.getGameId()).eq(User::getMobile, mobile));
         //用户信息存在
         if (user != null) {
-            //渠道更新和回传判断
-            agentService.userAgentUpdate(user, userData.getChannel());
             //判断账号是否停用
             if (Objects.equals(BanStatusEnum.BAN_STATUS.getStatus(), user.getStatus())) {
                 return ResultVO.fail(HttpStatusEnum.ACCOUNT_HALT.getMsg());
             }
+            //渠道更新和回传判断
+            agentService.userAgentUpdate(user, userData.getChannel());
             //返回登录信息
             return ResultVO.ok(this.createUserLoginVO(user, userData));
         }