Parcourir la source

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

root il y a 2 jours
Parent
commit
4473e2564a

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -25,7 +25,7 @@ public class SDKApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <新增接口获取小程序的accessToken> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <新增接口获取小程序的accessToken-01> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 6 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/AppletController.java

@@ -42,6 +42,12 @@ public class AppletController {
     @UnSignCheck
     @PushDataCheck
     @GetMapping("/get/applet/accessToken")
+    public ResultVO<Map<String, String>> getAppletToken(@RequestParam String gameId) {
+        return ResultVO.ok(gameAppletService.getAppletToken(gameId));
+    }
+
+    @UnSignCheck
+    @GetMapping("/get/applet/accessToken/bySign")
     public ResultVO<Map<String, String>> getAppletToken(@RequestParam String gameId, @RequestParam Long signTime,
                                                         @RequestParam String sign) {
         return ResultVO.ok(gameAppletService.getAppletToken(gameId, signTime, sign));

+ 8 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IGameAppletService.java

@@ -15,6 +15,14 @@ import java.util.Map;
  */
 public interface IGameAppletService extends IService<GameApplet> {
 
+    /**
+     * 根据游戏外部唯一标志获取微信小游戏token
+     *
+     * @param gameAppId : CP游戏包唯一标识
+     * @return : 微信小游戏 appId, token
+     */
+    Map<String, String> getAppletToken(String gameAppId);
+
     /**
      * 根据游戏外部唯一标志获取微信小游戏token
      *

+ 18 - 6
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameAppletServiceImpl.java

@@ -70,6 +70,15 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
     @Autowired
     private IGameSupperService gameSupperService;
 
+    @Override
+    public Map<String, String> getAppletToken(String gameAppId) {
+        GameExt gameExt = gameExtService.getByGameAppId(gameAppId);
+        if (gameExt == null) {
+            throw new BaseException("参数错误, 游戏配置信息不存在");
+        }
+        return this.buildAppletTokenResult(gameExt);
+    }
+
     @Override
     public Map<String, String> getAppletToken(String gameId, Long signTime, String sign) {
         GameExt gameExt = gameExtService.getByGameAppId(gameId);
@@ -84,18 +93,21 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         if (gameSupper == null) {
             throw new BaseException("参数错误, 超父游戏信息不存在");
         }
-        //签名验证
         this.signCheck(gameSupper.getCpServerKey(), gameId, signTime, sign);
-        //获取小程序 accessToken
+
+        return this.buildAppletTokenResult(gameExt);
+    }
+
+    private Map<String, String> buildAppletTokenResult(GameExt gameExt) {
         GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gameExt.getGameId());
         if (gameAppletDTO == null) {
             throw new BaseException("参数错误, 微信小游戏配置信息不存在");
         }
         String accessToken = wxApiService.getAccessToken(gameAppletDTO.getAppId(), gameAppletDTO.getAppSecret());
-        Map<String, String> resultMap = new HashMap<>(2);
-        resultMap.put("appId", gameAppletDTO.getAppId());
-        resultMap.put("accessToken", accessToken);
-        return resultMap;
+        Map<String, String> result = new HashMap<>(2);
+        result.put("appId", gameAppletDTO.getAppId());
+        result.put("accessToken", accessToken);
+        return result;
     }
 
     private void signCheck(String cpServerKey, String gameId, Long signTime, String sign) {