Quellcode durchsuchen

fix : bug调试修改

bilingfeng vor 1 Jahr
Ursprung
Commit
f85bcb2c12

+ 61 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/GameAppletConfigDTO.java

@@ -0,0 +1,61 @@
+package com.zanxiang.game.module.manage.pojo.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-06-21
+ * @description : 游戏应用信息
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class GameAppletConfigDTO {
+
+    /**
+     * 小游戏/公众号应用id
+     */
+    @ApiModelProperty(notes = "小游戏/公众号应用id (必填)")
+    private String appId;
+
+    /**
+     * 小游戏/公众号应用原始id
+     */
+    @ApiModelProperty(notes = "小游戏/公众号应用原始id (必填)")
+    private String ghId;
+
+    /**
+     * 小游戏/公众号应用名称
+     */
+    @ApiModelProperty(notes = "小游戏/公众号应用名称 (必填)")
+    private String appName;
+
+    /**
+     * 小游戏/公众号应用密钥
+     */
+    @ApiModelProperty(notes = "小游戏/公众号应用密钥 (必填)")
+    private String appSecret;
+
+    /**
+     * 公司主体信息
+     */
+    @ApiModelProperty(notes = "小游戏/公众号应用公司主体信息 (选填)")
+    private String company;
+
+    /**
+     * 小游戏/公众号应用登录账号
+     */
+    @ApiModelProperty(notes = "小游戏/公众号应用登录账号 (选填)")
+    private String account;
+
+    /**
+     * 小游戏/公众号应用管理员
+     */
+    @ApiModelProperty(notes = "小游戏/公众号应用管理员 (选填)")
+    private String manager;
+}

+ 4 - 19
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/GameAppletDTO.java

@@ -41,29 +41,14 @@ public class GameAppletDTO {
     private String appSecret;
 
     /**
-     * 米大师应用id
+     * 米大师配置
      */
-    private String miPayAppId;
+    private String miPayConfig;
 
     /**
-     * 米大师应用密钥
+     * 消息推送配置
      */
-    private String miPayAppKey;
-
-    /**
-     * 米大师应用沙箱密钥
-     */
-    private String miPayAppKeyDev;
-
-    /**
-     * 消息推送token
-     */
-    private String msgPushToken;
-
-    /**
-     * 消息推送加密密钥
-     */
-    private String msgPushAesKey;
+    private String msgConfig;
 
     /**
      * 公司主体信息

+ 7 - 25
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/GameAddParam.java

@@ -1,5 +1,6 @@
 package com.zanxiang.game.module.manage.pojo.params;
 
+import com.zanxiang.game.module.manage.pojo.dto.GameAppletConfigDTO;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
@@ -66,7 +67,7 @@ public class GameAddParam {
     /**
      * 父游戏id
      */
-    @ApiModelProperty(notes = "父游戏id")
+    @ApiModelProperty(notes = "父游戏id, 非主游戏时必填")
     private Long parentGameId;
 
     /**
@@ -81,34 +82,15 @@ public class GameAddParam {
     @ApiModelProperty(notes = "导量游戏id(选填)")
     private Long guideGameId;
 
-    /**
-     * 小游戏/公众号应用id
-     */
-    @ApiModelProperty(notes = "小游戏/公众号应用id (微信小游戏和H5游戏必填, APP游戏不填)")
-    private String appId;
-
-    /**
-     * 小游戏/公众号应用原始id
-     */
-    @ApiModelProperty(notes = "小游戏/公众号应用原始id (微信小游戏和H5游戏必填, APP游戏不填)")
-    private String ghId;
-
-    /**
-     * 小游戏/公众号应用名称
-     */
-    @ApiModelProperty(notes = "小游戏/公众号应用名称 (微信小游戏和H5游戏必填, APP游戏不填)")
-    private String appName;
-
-    /**
-     * 小游戏/公众号应用密钥
-     */
-    @ApiModelProperty(notes = "小游戏/公众号应用密钥 (微信小游戏和H5游戏必填, APP游戏不填)")
-    private String appSecret;
-
     /**
      * 游戏描述
      */
     @ApiModelProperty(notes = "游戏描述(选填)")
     private String description;
 
+    /**
+     * 小游戏/公众号应用信息
+     */
+    @ApiModelProperty(notes = "小游戏/公众号应用信息 (微信小游戏和H5游戏必填, 其他游戏不填)")
+    private GameAppletConfigDTO gameAppletConfigDTO;
 }

+ 7 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/GameListVO.java

@@ -1,5 +1,6 @@
 package com.zanxiang.game.module.manage.pojo.vo;
 
+import com.zanxiang.game.module.manage.pojo.dto.GameAppletConfigDTO;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
@@ -120,4 +121,10 @@ public class GameListVO {
      */
     @ApiModelProperty(notes = "上线状态1 接入中, 2 可上线, 3 已下线")
     private Integer status;
+
+    /**
+     * 小游戏/公众号应用信息
+     */
+    @ApiModelProperty(notes = "小游戏/公众号应用信息 (微信小游戏和H5游戏才有值)")
+    private GameAppletConfigDTO gameAppletConfigDTO;
 }

+ 0 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameAppletServiceImpl.java

@@ -82,7 +82,6 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         gameApplet.setGhId(param.getGhId());
         gameApplet.setAccount(param.getAccount());
         gameApplet.setPassword(param.getPassword());
-        gameApplet.setManagerVx(param.getAdminVx());
         gameApplet.setCompany(param.getCompany());
         gameApplet.setAppSecret(param.getAppSecret());
         gameApplet.setUpdateTime(LocalDateTime.now());

+ 6 - 8
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GamePayWayServiceImpl.java

@@ -17,6 +17,7 @@ import com.zanxiang.game.module.manage.service.*;
 import com.zanxiang.game.module.mybatis.entity.GameApplet;
 import com.zanxiang.game.module.mybatis.entity.GamePayWay;
 import com.zanxiang.game.module.mybatis.mapper.GamePayWayMapper;
+import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.exception.BaseException;
 import lombok.extern.slf4j.Slf4j;
@@ -137,9 +138,7 @@ public class GamePayWayServiceImpl extends ServiceImpl<GamePayWayMapper, GamePay
                 throw new BaseException("参数错误, 米大师支付参数配置不全");
             }
             gameAppletService.update(new LambdaUpdateWrapper<GameApplet>()
-                    .set(GameApplet::getMiPayAppId, miPayConfig.getAppId())
-                    .set(GameApplet::getMiPayAppKey, miPayConfig.getAppKey())
-                    .set(GameApplet::getMiPayAppKeyDev, miPayConfig.getAppKeyDev())
+                    .set(GameApplet::getMiPayConfig, JsonUtil.toString(miPayConfig))
                     .set(GameApplet::getUpdateTime, LocalDateTime.now())
                     .eq(GameApplet::getGameId, gamePayWay.getGameId()));
         }
@@ -226,11 +225,10 @@ public class GamePayWayServiceImpl extends ServiceImpl<GamePayWayMapper, GamePay
         }
         if (Objects.equals(PayWayEnum.MI_PAY.getPayWayId(), payWayId.intValue())) {
             GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gamePayWay.getGameId());
-            GamePayWayListVO.MiPayConfigBean miPayConfigBean = new GamePayWayListVO.MiPayConfigBean();
-            miPayConfigBean.setAppId(gameAppletDTO.getMiPayAppId());
-            miPayConfigBean.setAppKey(gameAppletDTO.getMiPayAppKey());
-            miPayConfigBean.setAppKeyDev(gameAppletDTO.getMiPayAppKeyDev());
-            gamePayWayListVO.setMiPayConfig(miPayConfigBean);
+            String miPayConfig = gameAppletDTO.getMiPayConfig();
+            if (Strings.isNotBlank(miPayConfig)) {
+                gamePayWayListVO.setMiPayConfig(JsonUtil.toObj(miPayConfig, GamePayWayListVO.MiPayConfigBean.class));
+            }
         }
         //返回
         return gamePayWayListVO;

+ 4 - 24
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameApplet.java

@@ -53,29 +53,14 @@ public class GameApplet {
     private String appSecret;
 
     /**
-     * 米大师应用id
+     * 米大师配置
      */
-    private String miPayAppId;
+    private String miPayConfig;
 
     /**
-     * 米大师应用密钥
+     * 消息推送配置
      */
-    private String miPayAppKey;
-
-    /**
-     * 米大师应用沙箱密钥
-     */
-    private String miPayAppKeyDev;
-
-    /**
-     * 消息推送token
-     */
-    private String msgPushToken;
-
-    /**
-     * 消息推送加密密钥
-     */
-    private String msgPushAesKey;
+    private String msgConfig;
 
     /**
      * 公司主体信息
@@ -97,11 +82,6 @@ public class GameApplet {
      */
     private String manager;
 
-    /**
-     * 管理员微信
-     */
-    private String managerVx;
-
     /**
      * 备注
      */

+ 2 - 3
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/AppletController.java

@@ -2,7 +2,6 @@ package com.zanxiang.game.module.sdk.controller;
 
 import com.zanxiang.game.module.sdk.annotation.UnSignCheck;
 import com.zanxiang.game.module.sdk.pojo.param.MiniAppPayParam;
-import com.zanxiang.game.module.sdk.pojo.vo.GameAppletVO;
 import com.zanxiang.game.module.sdk.service.IGameAppletService;
 import com.zanxiang.game.module.sdk.service.IPayApplicationService;
 import com.zanxiang.module.util.JsonUtil;
@@ -41,7 +40,7 @@ public class AppletController {
     @UnSignCheck
     @ApiOperation(value = "小程序客服消息认证")
     @GetMapping("/applet/custom/msg/{appId}")
-    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameAppletVO.class)})
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = String.class)})
     public String appletMsgCheck(@PathVariable("appId") String appId, @RequestParam String signature,
                                  @RequestParam String timestamp, @RequestParam String nonce,
                                  @RequestParam String echostr) throws Exception {
@@ -51,7 +50,7 @@ public class AppletController {
     @UnSignCheck
     @ApiOperation(value = "小程序客服消息事件监听")
     @PostMapping("/applet/custom/msg/{appId}")
-    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameAppletVO.class)})
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = String.class)})
     public String appletMsg(@PathVariable("appId") String appId, @RequestParam String signature,
                             @RequestParam String timestamp, @RequestParam String nonce,
                             @RequestBody String postData) throws Exception {

+ 62 - 12
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/dto/GameAppletDTO.java

@@ -2,7 +2,12 @@ package com.zanxiang.game.module.sdk.pojo.dto;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.zanxiang.module.util.JsonUtil;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.logging.log4j.util.Strings;
 
 /**
  * @author : lingfeng
@@ -10,6 +15,9 @@ import lombok.Data;
  * @description : 游戏小程序信息
  */
 @Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
 public class GameAppletDTO {
 
     /**
@@ -44,27 +52,69 @@ public class GameAppletDTO {
     private String appSecret;
 
     /**
-     * 米大师应用id
+     * 米大师配置
      */
-    private String miPayAppId;
+    private String miPayConfig;
 
     /**
-     * 米大师应用密钥
+     * 消息推送配置
      */
-    private String miPayAppKey;
+    private String msgConfig;
 
     /**
-     * 米大师应用沙箱密钥
+     * 获取米大师支付配置Bean
+     *
+     * @return {@link MiPayConfigBean}
      */
-    private String miPayAppKeyDev;
+    public MiPayConfigBean getMiPayConfigBean() {
+        if (Strings.isBlank(this.miPayConfig)) {
+            return null;
+        }
+        return JsonUtil.toObj(this.miPayConfig, GameAppletDTO.MiPayConfigBean.class);
+    }
 
     /**
-     * 消息推送token
+     * 获取小游戏消息推送配置Bean
+     *
+     * @return {@link MsgConfigBean}
      */
-    private String msgPushToken;
+    public MsgConfigBean getMsgConfigBean() {
+        if (Strings.isBlank(this.msgConfig)) {
+            return null;
+        }
+        return JsonUtil.toObj(this.msgConfig, GameAppletDTO.MsgConfigBean.class);
+    }
 
-    /**
-     * 消息推送加密密钥
-     */
-    private String msgPushAesKey;
+    @Data
+    public static class MiPayConfigBean {
+
+        /**
+         * 米大师支付应用id
+         */
+        private String appId;
+
+        /**
+         * 米大师现网AppKey
+         */
+        private String appKey;
+
+        /**
+         * 米大师沙箱AppKey
+         */
+        private String appKeyDev;
+    }
+
+    @Data
+    public static class MsgConfigBean {
+
+        /**
+         * 消息推送token
+         */
+        private String msgPushToken;
+
+        /**
+         * 消息推送加密密钥
+         */
+        private String msgPushAesKey;
+    }
 }

+ 9 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IGameAppletService.java

@@ -39,13 +39,21 @@ public interface IGameAppletService extends IService<GameApplet> {
     String appletMsg(String appId, String signature, String timestamp, String nonce, String postData) throws Exception;
 
     /**
-     * 通过游戏id和app id
+     * 通过游戏id
      *
      * @param gameId 游戏id
      * @return {@link GameAppletDTO}
      */
     GameAppletDTO getByGameId(Long gameId);
 
+    /**
+     * 通过应用程序id
+     *
+     * @param appId 应用程序id
+     * @return {@link GameAppletDTO}
+     */
+    GameAppletDTO getByAppId(String appId);
+
     /**
      * 微信小游戏初始化获取信息
      *

+ 23 - 13
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameAppletServiceImpl.java

@@ -63,12 +63,12 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
     @Override
     public String appletMsgCheck(String appId, String signature, String timestamp, String nonce, String echoStr) throws Exception {
         log.error("验证参数, appId : {}, signature : {}, timestamp : {}, nonce : {}, echoStr : {}", appId, signature, timestamp, nonce, echoStr);
-        GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()
-                .eq(GameApplet::getAppId, appId));
-        if (gameApplet == null) {
-            throw new BaseException("参数错误, 游戏小程序信息不存在");
+        GameAppletDTO gameAppletDTO = this.getByAppId(appId);
+        GameAppletDTO.MsgConfigBean msgConfigBean = gameAppletDTO.getMsgConfigBean();
+        if (msgConfigBean == null) {
+            throw new BaseException("参数错误, 小游戏应用缺少消息推送配置");
         }
-        String mySignature = SignUtil.SHA1(gameApplet.getMsgPushToken(), timestamp, nonce);
+        String mySignature = SignUtil.SHA1(msgConfigBean.getMsgPushToken(), timestamp, nonce);
         log.error("计算出来的签名, signature : {},  mySignature : {}", signature, mySignature);
         if (!Objects.equals(mySignature, signature)) {
             throw new BaseException("验证签名不匹配");
@@ -84,12 +84,12 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         if (Strings.isBlank(postData)) {
             return result;
         }
-        GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()
-                .eq(GameApplet::getAppId, appId));
-        if (gameApplet == null) {
+        GameAppletDTO gameAppletDTO = this.getByAppId(appId);
+        GameAppletDTO.MsgConfigBean msgConfigBean = gameAppletDTO.getMsgConfigBean();
+        if (msgConfigBean == null) {
             return result;
         }
-        String mySignature = SignUtil.SHA1(gameApplet.getMsgPushToken(), timestamp, nonce);
+        String mySignature = SignUtil.SHA1(msgConfigBean.getMsgPushToken(), timestamp, nonce);
         if (!Objects.equals(mySignature, signature)) {
             log.error("计算出来的签名不匹配, signature : {},  mySignature : {}", signature, mySignature);
             return result;
@@ -100,7 +100,7 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
             return result;
         }
         //用户信息
-        UserDTO userDTO = userService.getUserByOpenId(gameApplet.getGameId(), appletMsgDTO.getFromUserName());
+        UserDTO userDTO = userService.getUserByOpenId(gameAppletDTO.getGameId(), appletMsgDTO.getFromUserName());
         //查询用户最新订单
         Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
                 .eq(Order::getUserId, userDTO.getId())
@@ -111,10 +111,10 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
             return result;
         }
         //发送客服消息
-        return this.sendCustomMessage(gameApplet, userDTO.getOpenId(), order);
+        return this.sendCustomMessage(gameAppletDTO, userDTO.getOpenId(), order);
     }
 
-    private String sendCustomMessage(GameApplet gameApplet, String openId, Order order) {
+    private String sendCustomMessage(GameAppletDTO gameAppletDTO, String openId, Order order) {
         //查询订单支付方式
         GamePayWayDTO gamePayWayDTO = gamePayWayService.getById(order.getGamePayWayId());
         //查询支付应用信息
@@ -148,7 +148,7 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         paramMap.put("link", linkMap);
         log.error("客服消息发送参数, paramMap : {}", JsonUtil.toString(paramMap));
         //获取接口token
-        String accessToken = wxApiService.getAccessToken(gameApplet.getAppId(), gameApplet.getAppSecret());
+        String accessToken = wxApiService.getAccessToken(gameAppletDTO.getAppId(), gameAppletDTO.getAppSecret());
         URI uri = UriComponentsBuilder.fromHttpUrl("https://api.weixin.qq.com/cgi-bin/message/custom/send")
                 .queryParam("access_token", accessToken)
                 .build().toUri();
@@ -168,6 +168,16 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         return BeanUtil.copy(gameApplet, GameAppletDTO.class);
     }
 
+    @Override
+    public GameAppletDTO getByAppId(String appId) {
+        GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()
+                .eq(GameApplet::getAppId, appId));
+        if (gameApplet == null) {
+            throw new BaseException("参数错误, 游戏小程序信息不存在");
+        }
+        return BeanUtil.copy(gameApplet, GameAppletDTO.class);
+    }
+
     @Override
     public GameAppletVO gameAppletInit(UserData userData) {
         GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()

+ 8 - 3
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/pay/MiPayService.java

@@ -198,13 +198,18 @@ public class MiPayService extends PayBaseService {
     private void configInit(Long gameId) {
         //查询游戏小程序信息
         GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gameId);
+        GameAppletDTO.MiPayConfigBean miPayConfigBean = gameAppletDTO.getMiPayConfigBean();
+        if (miPayConfigBean == null) {
+            log.error("参数错误, 米大师支付参数不存在, gameId : {}", gameId);
+            throw new BaseException("参数错误, 米大师支付参数不存在");
+        }
         //支付配置赋值
         this.config = MiPayConfigDTO.builder()
                 .appId(gameAppletDTO.getAppId())
                 .secret(gameAppletDTO.getAppSecret())
-                .offerId(gameAppletDTO.getMiPayAppId())
-                .appKey(gameAppletDTO.getMiPayAppKey())
-                .appKeyDev(gameAppletDTO.getMiPayAppKeyDev())
+                .offerId(miPayConfigBean.getAppId())
+                .appKey(miPayConfigBean.getAppKey())
+                .appKeyDev(miPayConfigBean.getAppKeyDev())
                 .build();
     }