浏览代码

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

zhimo 1 年之前
父节点
当前提交
7f0f2bd8df

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

@@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
 import lombok.Getter;
 import org.apache.logging.log4j.util.Strings;
 
+import java.util.Arrays;
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -44,7 +46,12 @@ public enum PayDeviceEnum {
     /**
      * 客服支付
      */
-    CUSTOM_PAY(6L, "CUSTOM_PAY", "客服支付");
+    CUSTOM_PAY(6L, "CUSTOM_PAY", "客服支付"),
+
+    /**
+     * 公众号支付
+     */
+    MP_PAY(7L, "MP_PAY", "公众号支付");
 
     /**
      * 支付方式id
@@ -78,4 +85,15 @@ public enum PayDeviceEnum {
         }
         return Strings.EMPTY;
     }
+
+    /**
+     * 获取特殊的支付类型(预下单在获取支付参数)
+     *
+     * @return {@link List}<{@link Long}>
+     */
+    public static List<Long> getByPayWayIdList() {
+        return Arrays.asList(PayDeviceEnum.APPLET_PAY.getPayDeviceId(),
+                PayDeviceEnum.CUSTOM_PAY.getPayDeviceId(),
+                PayDeviceEnum.MP_PAY.getPayDeviceId());
+    }
 }

+ 12 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/GameController.java

@@ -5,6 +5,7 @@ import com.zanxiang.erp.security.annotation.PreAuthorize;
 import com.zanxiang.game.module.manage.pojo.params.GameAddParam;
 import com.zanxiang.game.module.manage.pojo.params.GameListParam;
 import com.zanxiang.game.module.manage.pojo.vo.GameListVO;
+import com.zanxiang.game.module.manage.service.IGameAppletService;
 import com.zanxiang.game.module.manage.service.IGameService;
 import com.zanxiang.module.util.pojo.ResultVO;
 import io.swagger.annotations.Api;
@@ -30,6 +31,9 @@ public class GameController {
     @Autowired
     private IGameService gameService;
 
+    @Autowired
+    private IGameAppletService gameAppletService;
+
     @ApiOperation(value = "新增游戏")
     @PostMapping(value = "/add/or/update")
     @PreAuthorize(permissionKey = "manage:game:add")
@@ -61,4 +65,12 @@ public class GameController {
     public ResultVO<Boolean> statusUpdate(@RequestParam Long id, @RequestParam Integer status) {
         return ResultVO.ok(gameService.statusUpdate(id, status));
     }
+
+    @ApiOperation(value = "创建游戏回传数据源")
+    @PutMapping(value = "/create/game/action/set")
+    @PreAuthorize(permissionKey = "manage:game:createGameActionSet")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> createActionSet(@RequestParam Long gameId) {
+        return ResultVO.ok(gameAppletService.createActionSet(gameId));
+    }
 }

+ 17 - 97
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/GameDTO.java

@@ -27,120 +27,45 @@ public class GameDTO {
      */
     private String name;
 
-    /**
-     * appkey
-     */
-    private String appKey;
-
-    /**
-     * 游戏标签
-     */
-    private Long tags;
-
     /**
      * 游戏类型
      */
     private Long category;
 
     /**
-     * 游戏分类id, 多个
+     * H5游戏跳转地址
      */
-    private String classify;
+    private String h5GameUrl;
 
     /**
-     * 游戏分类父id, 多个
+     * H5游戏登录logo图片
      */
-    private String classifyParent;
+    private String h5LoginLogo;
 
     /**
-     * 网页游戏图标,200*200
+     * 游戏是否投放
      */
-    private String icon;
+    private Boolean isPut;
 
     /**
-     * CP回调路径
-     */
-    private String cpPaybackUrl;
-
-    /**
-     * 从属游戏
-     */
-    private Long parentId;
-
-    /**
-     * 包名
+     * 游戏标签
      */
-    private String packageName;
+    private String tags;
 
     /**
-     * 上线状态1 接入中, 2 可上线, 3 已下线
+     * 上线状态 1 : 未接入, 2 : 接入中, 3 : 上线, 4 : 下线
      */
     private Integer status;
 
     /**
-     * 1在线游戏 2 单机
-     */
-    private Boolean isOnline;
-
-    /**
-     * 1 不是SDK游戏  2 是SDK游戏
-     */
-    private Boolean isSdk;
-
-    /**
-     * 游戏宣传语
-     */
-    private String publicity;
-
-    /**
-     * 语言
-     */
-    private String language;
-
-    /**
-     * 游戏描述
-     */
-    private String description;
-
-    /**
-     * 游戏宣传图 JSON格式
-     */
-    private String image;
-
-    /**
-     * 苹果应用ID
-     */
-    private String appleId;
-
-    /**
-     * 是否需要实名认证,1:关闭实名认证,2:强制实名认证  3:开启实名认证
-     */
-    private Integer needAuth;
-
-    /**
-     * 扩展 JSON格式
-     */
-    private String extInfo;
-
-    /**
-     * 上线时间
-     */
-    private LocalDateTime onlineTime;
-
-    /**
-     * 1 删除  0 正常
-     */
-    private Integer isDelete;
-
-    /**
-     * 删除时间
+     * 分成比例
      */
-    private LocalDateTime deleteTime;
+    private Double shareScale;
 
     /**
-     * 分成比例
+     * 父游戏id
      */
-    private Double shareScale;
+    private Long parentId;
 
     /**
      * 关联H5游戏id
@@ -153,19 +78,14 @@ public class GameDTO {
     private Long guideGameId;
 
     /**
-     * 游戏地址
+     * 游戏备注
      */
-    private String gameUrl;
+    private String remark;
 
     /**
-     * 游戏版本
-     */
-    private String version;
-
-    /**
-     * 下载次数
+     * 1 删除  0 正常
      */
-    private Long downloadCount;
+    private Integer isDelete;
 
     /**
      * 创建时间

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

@@ -22,6 +22,14 @@ public interface IGameAppletService extends IService<GameApplet> {
      */
     boolean addOrUpdate(Game game, GameAppletConfigDTO gameAppletConfigDTO);
 
+    /**
+     * 创建数据源
+     *
+     * @param gameId 游戏id
+     * @return {@link Boolean}
+     */
+    Boolean createActionSet(Long gameId);
+
     /**
      * 通过游戏id
      *

+ 41 - 15
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameAppletServiceImpl.java

@@ -12,7 +12,9 @@ import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
 import com.zanxiang.game.module.base.pojo.enums.StatusEnum;
 import com.zanxiang.game.module.manage.pojo.dto.GameAppletConfigDTO;
 import com.zanxiang.game.module.manage.pojo.dto.GameAppletDTO;
+import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
 import com.zanxiang.game.module.manage.service.IGameAppletService;
+import com.zanxiang.game.module.manage.service.IGameService;
 import com.zanxiang.game.module.mybatis.entity.Game;
 import com.zanxiang.game.module.mybatis.entity.GameApplet;
 import com.zanxiang.game.module.mybatis.mapper.GameAppletMapper;
@@ -21,6 +23,7 @@ import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.URIUtil;
 import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.exception.BaseException;
+import com.zanxiang.module.util.pojo.ResultVO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.apache.logging.log4j.util.Strings;
@@ -32,10 +35,7 @@ import java.io.PrintWriter;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.time.LocalDateTime;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.UUID;
+import java.util.*;
 
 /**
  * @author : lingfeng
@@ -52,6 +52,9 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
     @Autowired
     private IOssService ossService;
 
+    @Autowired
+    private IGameService gameService;
+
     @Override
     public boolean addOrUpdate(Game game, GameAppletConfigDTO gameAppletConfigDTO) {
         GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()
@@ -59,17 +62,7 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
                 .eq(GameApplet::getGameId, game.getId())
         );
         if (gameApplet == null) {
-            CreateUserActionSetRpcDTO actionSetRpcDTO = CreateUserActionSetRpcDTO.builder()
-                    .appId(gameAppletConfigDTO.getAppId())
-                    .build();
-            //小游戏需要创建数据源
-            if (Objects.equals(GameCategoryEnum.CATEGORY_WX_APPLET.getId(), game.getCategory())) {
-//                userActionSetRpc.create(actionSetRpcDTO);
-            }
-            //H5游戏要判断是否主游戏, 主游戏才投, 需要创建公众号数据源
-            if (game.getParentId() == null && Objects.equals(GameCategoryEnum.CATEGORY_H5.getId(), game.getCategory())) {
-//                userActionSetRpc.create(actionSetRpcDTO);
-            }
+            this.createActionSet(game.getCategory(), game.getIsPut(), gameAppletConfigDTO.getAppId());
             gameApplet = GameApplet.builder()
                     .gameId(game.getId())
                     .appId(gameAppletConfigDTO.getAppId())
@@ -105,6 +98,39 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         return super.saveOrUpdate(gameApplet);
     }
 
+    @Override
+    public Boolean createActionSet(Long gameId) {
+        GameDTO gameDTO = gameService.getById(gameId);
+        GameAppletDTO gameAppletDTO = this.getByGameId(gameId);
+        if (gameDTO == null || gameAppletDTO == null) {
+            log.error("创建数据源失败, 游戏信息数据不全 gameDTO : {}, gameAppletDTO : {}",
+                    JsonUtil.toString(gameDTO), JsonUtil.toString(gameAppletDTO));
+            return Boolean.FALSE;
+        }
+        return this.createActionSet(gameDTO.getCategory(), gameDTO.getIsPut(), gameAppletDTO.getAppId());
+    }
+
+    private Boolean createActionSet(Long gameCategory, Boolean isPut, String appId) {
+        CreateUserActionSetRpcDTO actionSetRpcDTO = CreateUserActionSetRpcDTO.builder().appId(appId).build();
+        //小游戏和H5的类型才需要创建数据源
+        List<Long> categoryList = Arrays.asList(GameCategoryEnum.CATEGORY_WX_APPLET.getId(), GameCategoryEnum.CATEGORY_H5.getId());
+        //投放的游戏才需要设置数据源
+        if (!categoryList.contains(gameCategory) || !Objects.equals(isPut, Boolean.TRUE)) {
+            return Boolean.FALSE;
+        }
+        //调用回传服务创建数据源
+        ResultVO<Boolean> booleanResultVO = null;
+        try {
+            booleanResultVO = userActionSetRpc.create(actionSetRpcDTO);
+        } catch (Exception e) {
+            log.error("调用回传服务创建数据源异常, gameCategory : {}, appId : {}, actionSetRpcDTO : {}, e : {}",
+                    gameCategory, appId, JsonUtil.toString(actionSetRpcDTO), e.getMessage());
+        }
+        log.error("创建数据源结果 actionSetRpcDTO : {}, booleanResultVO : {}",
+                JsonUtil.toString(actionSetRpcDTO), JsonUtil.toString(booleanResultVO));
+        return booleanResultVO == null ? Boolean.FALSE : booleanResultVO.getData();
+    }
+
     @Override
     public GameAppletDTO getByGameId(Long gameId) {
         GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()

+ 10 - 4
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/PayController.java

@@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
@@ -35,7 +34,7 @@ import java.util.Map;
 @Slf4j
 public class PayController {
 
-    @Resource
+    @Autowired
     private IOrderPayService orderPayService;
 
     @Autowired
@@ -44,8 +43,15 @@ public class PayController {
     @UnSignCheck
     @ApiOperation(value = "获取客服支付参数")
     @GetMapping(value = "/param/applet")
-    public ResultVO<PayParamVO> getPayParam(@RequestParam String code, @RequestParam String orderId, HttpServletRequest request) {
-        return ResultVO.ok(orderPayService.getPayParam(code, orderId, request));
+    public ResultVO<PayParamVO> getCustomPayParam(@RequestParam String code, @RequestParam String orderId, HttpServletRequest request) {
+        return ResultVO.ok(orderPayService.getPayParam(code, null, orderId, request));
+    }
+
+    @ApiOperation(value = "获取公众号支付参数")
+    @GetMapping(value = "/param/mp")
+    public ResultVO<PayParamVO> getMpPayParam(@RequestParam String openId, @RequestParam String orderId,
+                                              @ValidLogin UserData userData, HttpServletRequest request) {
+        return ResultVO.ok(orderPayService.getPayParam(null, openId, orderId, request));
     }
 
     @ApiOperation(value = "获取小游戏支付方式")

+ 5 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/dto/ProductPayParamDTO.java

@@ -72,6 +72,11 @@ public class ProductPayParamDTO {
      */
     private String code;
 
+    /**
+     * 公众号支付的openId
+     */
+    private String openId;
+
     /**
      * 支付类型详情(android / ios/ window)
      */

+ 2 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IOrderPayService.java

@@ -21,9 +21,10 @@ public interface IOrderPayService {
      * @param code    代码
      * @param orderId 订单id
      * @param request 请求
+     * @param openId  用户公众号唯一标识
      * @return {@link PayParamVO}
      */
-    PayParamVO getPayParam(String code, String orderId, HttpServletRequest request);
+    PayParamVO getPayParam(String code, String openId, String orderId, HttpServletRequest request);
 
     /**
      * 获取小游戏支付方式

+ 3 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IOrderService.java

@@ -2,6 +2,7 @@ package com.zanxiang.game.module.sdk.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zanxiang.game.module.mybatis.entity.Order;
+import com.zanxiang.game.module.mybatis.entity.User;
 import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
 import com.zanxiang.game.module.sdk.pojo.param.ProductPayParam;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
@@ -20,9 +21,10 @@ public interface IOrderService extends IService<Order> {
      *
      * @param payParam 支付参数
      * @param userData 用户数据
+     * @param user     用户
      * @return {@link Boolean}
      */
-    Boolean createOrder(ProductPayParam payParam, UserData userData);
+    Boolean createOrder(ProductPayParam payParam, User user, UserData userData);
 
     /**
      * 单一订单详情获取

+ 51 - 42
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/OrderPayServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zanxiang.game.module.base.pojo.enums.PayDeviceEnum;
 import com.zanxiang.game.module.mybatis.entity.Order;
 import com.zanxiang.game.module.mybatis.entity.OrderPayParam;
+import com.zanxiang.game.module.mybatis.entity.User;
 import com.zanxiang.game.module.sdk.enums.DeviceTypeEnum;
 import com.zanxiang.game.module.sdk.enums.OrderStateEnum;
 import com.zanxiang.game.module.sdk.enums.PayTypeEnum;
@@ -17,6 +18,7 @@ import com.zanxiang.game.module.sdk.service.*;
 import com.zanxiang.game.module.sdk.service.pay.PayBaseService;
 import com.zanxiang.game.module.sdk.util.SpringUtils;
 import com.zanxiang.module.util.JsonUtil;
+import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.exception.BaseException;
 import com.zanxiang.module.web.util.IpUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -53,6 +55,9 @@ public class OrderPayServiceImpl implements IOrderPayService {
     @Autowired
     private IPayApplicationService payApplicationService;
 
+    @Autowired
+    private IUserService userService;
+
     @Value("${payConfig.wxPay.customH5Url}")
     private String customH5Url;
 
@@ -63,56 +68,59 @@ public class OrderPayServiceImpl implements IOrderPayService {
     private String serverUrl;
 
     @Override
-    public PayParamVO getPayParam(String code, String orderId, HttpServletRequest request) {
-        Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
-                .eq(Order::getOrderId, orderId));
-        log.error("获取订单支付参数, code : {}, orderId : {}", code, orderId);
-        if (order == null) {
-            throw new BaseException("参数错误, 订单信息不存在");
-        }
-        if (Objects.equals(order.getStatus(), OrderStateEnum.CANCEL_PAY.getCode())) {
-            throw new BaseException("订单已关闭, 请回到游戏重新下单");
-        }
-        if (Objects.equals(order.getStatus(), OrderStateEnum.SUCCESS_PAY.getCode())) {
-            throw new BaseException("订单已支付, 请勿重复支付");
-        }
+    public PayParamVO getPayParam(String code, String openId, String orderId, HttpServletRequest request) {
+        log.error("获取订单支付参数, code : {}, openId : {}, orderId : {}", code, openId, orderId);
+        Order order = this.orderFindAndCheck(orderId);
         OrderPayParam orderPayParam = orderPayParamService.getOne(new LambdaQueryWrapper<OrderPayParam>()
                 .eq(OrderPayParam::getOrderId, order.getOrderId()));
         if (orderPayParam != null) {
-            return PayParamVO.builder()
-                    .orderId(orderPayParam.getOrderId())
-                    .appId(orderPayParam.getAppId())
-                    .payParam(orderPayParam.getPayParam())
-                    .build();
+            return BeanUtil.copy(orderPayParam, PayParamVO.class);
         }
         //创建支付参数
-        ProductPayParamDTO bo = ProductPayParamDTO.builder()
-                .gameId(order.getGameId())
-                .userId(order.getUserId())
-                .payDevice(order.getPayDeviceId())
-                .deviceSystem(order.getDeviceSystem())
-                .spbillCreateIp(IpUtil.getRealIp(request))
-                .outTradeNo(order.getOrderId())
-                .payWay(order.getPayWayId())
-                .code(code)
-                .build();
+        ProductPayParamDTO productPayParamDTO = this.transform(order, code, openId, IpUtil.getRealIp(request));
         //调起支付
-        PayTypeEnum payTypeEnum = PayTypeEnum.getByPayType(bo.getPayWay().intValue());
+        PayTypeEnum payTypeEnum = PayTypeEnum.getByPayType(productPayParamDTO.getPayWay().intValue());
         PayBaseService service = SpringUtils.getBean(payTypeEnum.getClazz());
-        service.payCreate(bo);
+        service.payCreate(productPayParamDTO);
         //重新查询
         orderPayParam = orderPayParamService.getOne(new LambdaQueryWrapper<OrderPayParam>()
                 .eq(OrderPayParam::getOrderId, order.getOrderId()));
         if (orderPayParam == null) {
+            log.error("支付参数获取失败, orderId : {}", orderId);
             throw new BaseException("支付参数获取失败");
         }
-        return PayParamVO.builder()
-                .orderId(orderPayParam.getOrderId())
-                .appId(orderPayParam.getAppId())
-                .payParam(orderPayParam.getPayParam())
+        //返回支付参数
+        return BeanUtil.copy(orderPayParam, PayParamVO.class);
+    }
+
+    private ProductPayParamDTO transform(Order order, String code, String openId, String ip) {
+        return ProductPayParamDTO.builder()
+                .gameId(order.getGameId())
+                .userId(order.getUserId())
+                .payDevice(order.getPayDeviceId())
+                .deviceSystem(order.getDeviceSystem())
+                .spbillCreateIp(ip)
+                .outTradeNo(order.getOrderId())
+                .payWay(order.getPayWayId())
+                .code(code)
+                .openId(openId)
                 .build();
     }
 
+    private Order orderFindAndCheck(String orderId) {
+        Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderId, orderId));
+        if (order == null) {
+            throw new BaseException("参数错误, 订单信息不存在");
+        }
+        if (Objects.equals(order.getStatus(), OrderStateEnum.CANCEL_PAY.getCode())) {
+            throw new BaseException("订单已关闭, 请回到游戏重新下单");
+        }
+        if (Objects.equals(order.getStatus(), OrderStateEnum.SUCCESS_PAY.getCode())) {
+            throw new BaseException("订单已支付, 请勿重复支付");
+        }
+        return order;
+    }
+
     @Override
     public Long getAppletPayDevice(UserData userData) {
         log.error("获取支付类型参数, 请求信息 userData : {}", JsonUtil.toString(userData));
@@ -150,11 +158,15 @@ public class OrderPayServiceImpl implements IOrderPayService {
 
     @Override
     public Map<String, Object> payCreate(ProductPayParam product, UserData userData) {
+        //用户信息
+        User user = userService.getById(userData.getUserId());
+        if (user == null) {
+            throw new BaseException("参数错误, 用户信息不存在");
+        }
         //创建订单
-        orderService.createOrder(product, userData);
+        orderService.createOrder(product, user, userData);
         //判断游戏类型
-        if (Objects.equals(PayDeviceEnum.APPLET_PAY.getPayDeviceId(), product.getPayDevice())
-                || Objects.equals(PayDeviceEnum.CUSTOM_PAY.getPayDeviceId(), product.getPayDevice())) {
+        if (PayDeviceEnum.getByPayWayIdList().contains(product.getPayDevice())) {
             //查询支付配置
             GamePayWayDTO gamePayWayDTO = gamePayWayService.getGamePayWay(userData.getGameId(), product.getPayWay(), product.getPayDevice());
             //查询支付应用信息
@@ -166,12 +178,9 @@ public class OrderPayServiceImpl implements IOrderPayService {
             paramMap.put("orderId", product.getOrderId());
             paramMap.put("amount", product.getAmount());
             paramMap.put("payH5Url", this.customH5Url);
+            paramMap.put("openId", user.getOpenId());
             paramMap.put("description", "购买" + product.getAmount() + "元档充值");
-            if (this.serverUrl.contains("84game")) {
-                paramMap.put("serverUrl", this.serverUrl + "/sdk");
-            } else {
-                paramMap.put("serverUrl", this.serverUrl + "/api/sdk");
-            }
+            paramMap.put("serverUrl", this.serverUrl.contains("84game") ? this.serverUrl + "/sdk" : this.serverUrl + "/api/sdk");
             log.error("下单参数返回, paramMap : {}", JsonUtil.toString(paramMap));
             return paramMap;
         }

+ 8 - 21
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/OrderServiceImpl.java

@@ -9,6 +9,7 @@ import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
 import com.zanxiang.game.module.sdk.pojo.param.ProductPayParam;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
 import com.zanxiang.game.module.sdk.service.*;
+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;
@@ -33,9 +34,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
     @Autowired
     private IGameService gameService;
 
-    @Autowired
-    private IUserService userService;
-
     @Autowired
     private IGameUserService gameUserService;
 
@@ -50,34 +48,23 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
 
     @Override
     @Transactional(rollbackFor = {Exception.class, RuntimeException.class})
-    public Boolean createOrder(ProductPayParam payParam, UserData userData) {
-        //用户id
-        Long userId = userData.getUserId();
+    public Boolean createOrder(ProductPayParam payParam, User user, UserData userData) {
         //游戏id
         Long gameId = userData.getGameId();
         //游戏信息
-        Game game = gameService.getById(userData.getGameId());
-        if (game == null) {
-            throw new BaseException("参数错误, 游戏信息不存在");
-        }
-        //用户信息
-        User user = userService.getById(userId);
-        if (user == null) {
-            throw new BaseException("参数错误, 用户信息不存在");
-        }
+        Game game = gameService.getById(gameId);
         //玩家信息
         GameUser gameUser = gameUserService.getOne(new LambdaQueryWrapper<GameUser>()
                 .eq(GameUser::getUserId, userData.getUserId()));
-        if (gameUser == null) {
-            throw new BaseException("参数错误, 玩家信息不存在");
-        }
         //角色信息
         GameUserRole gameUserRole = gameUserRoleService.getOne(new LambdaQueryWrapper<GameUserRole>()
-                .eq(GameUserRole::getGameId, userData.getGameId())
+                .eq(GameUserRole::getGameId, gameId)
                 .eq(GameUserRole::getUserId, userData.getUserId())
                 .eq(GameUserRole::getRoleId, payParam.getRoleId()));
-        if (gameUserRole == null) {
-            throw new BaseException("参数错误, 角色信息不存在");
+        if (game == null || gameUser == null || gameUserRole == null) {
+            log.error("游戏用户信息不全, game : {}, gameUser : {}, gameUserRole : {}", JsonUtil.toString(game),
+                    JsonUtil.toString(gameUser), JsonUtil.toString(gameUserRole));
+            throw new BaseException("参数错误, 游戏用户信息不全");
         }
         //游戏支付配置信息
         GamePayWayDTO gamePayWayDTO = gamePayWayService.getGamePayWay(gameId, payParam.getPayWay(), payParam.getPayDevice());

+ 7 - 3
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/pay/WxPayService.java

@@ -240,9 +240,13 @@ public class WxPayService extends PayBaseService {
 
     private Map<String, Object> miniAppPay(ProductPayParamDTO product) {
         try {
-            //获取用户openId
-            String openId = wxApiService.getOpenIdByType(product.getCode(), config.getAppId(), config.getAppSecret(),
-                    config.getAppletType()).get("openid");
+            //用户openId
+            String openId = product.getOpenId();
+            //传了code, 自己获取openId
+            if (Strings.isBlank(openId) && Strings.isNotBlank(product.getCode())) {
+                openId = wxApiService.getOpenIdByType(product.getCode(), config.getAppId(), config.getAppSecret(),
+                        config.getAppletType()).get("openid");
+            }
             //下单
             Map<String, String> successMap = this.unifiedOrder(product, WX_PAY_JSAPI, openId);
             // 支付参数