Commit 3a77cc239b2efdc7a3ad1eeaff627b028adb5497
1 parent
ab19228c
yudao-user-server 接入支付模块
Showing
11 changed files
with
211 additions
and
4 deletions
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/PayOrderCoreService.java
| 1 | package cn.iocoder.yudao.coreservice.modules.pay.service.order; | 1 | package cn.iocoder.yudao.coreservice.modules.pay.service.order; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO; | ||
| 3 | import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderCreateReqDTO; | 4 | import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderCreateReqDTO; |
| 4 | import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitReqDTO; | 5 | import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitReqDTO; |
| 5 | import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitRespDTO; | 6 | import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitRespDTO; |
| @@ -14,6 +15,14 @@ import javax.validation.Valid; | @@ -14,6 +15,14 @@ import javax.validation.Valid; | ||
| 14 | public interface PayOrderCoreService { | 15 | public interface PayOrderCoreService { |
| 15 | 16 | ||
| 16 | /** | 17 | /** |
| 18 | + * 获得支付单 | ||
| 19 | + * | ||
| 20 | + * @param id 支付单编号 | ||
| 21 | + * @return 支付单 | ||
| 22 | + */ | ||
| 23 | + PayOrderDO getPayOrder(Long id); | ||
| 24 | + | ||
| 25 | + /** | ||
| 17 | * 创建支付单 | 26 | * 创建支付单 |
| 18 | * | 27 | * |
| 19 | * @param reqDTO 创建请求 | 28 | * @param reqDTO 创建请求 |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/dto/PayOrderSubmitReqDTO.java
| 1 | package cn.iocoder.yudao.coreservice.modules.pay.service.order.dto; | 1 | package cn.iocoder.yudao.coreservice.modules.pay.service.order.dto; |
| 2 | 2 | ||
| 3 | -import com.baomidou.mybatisplus.annotation.TableField; | ||
| 4 | -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | ||
| 5 | import lombok.Data; | 3 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 4 | import lombok.experimental.Accessors; |
| 7 | 5 | ||
| @@ -32,7 +30,7 @@ public class PayOrderSubmitReqDTO implements Serializable { | @@ -32,7 +30,7 @@ public class PayOrderSubmitReqDTO implements Serializable { | ||
| 32 | /** | 30 | /** |
| 33 | * 支付渠道 | 31 | * 支付渠道 |
| 34 | */ | 32 | */ |
| 35 | - @NotNull(message = "支付渠道") | 33 | + @NotEmpty(message = "支付渠道不能为空") |
| 36 | private String channelCode; | 34 | private String channelCode; |
| 37 | 35 | ||
| 38 | /** | 36 | /** |
| @@ -44,7 +42,6 @@ public class PayOrderSubmitReqDTO implements Serializable { | @@ -44,7 +42,6 @@ public class PayOrderSubmitReqDTO implements Serializable { | ||
| 44 | /** | 42 | /** |
| 45 | * 支付渠道的额外参数 | 43 | * 支付渠道的额外参数 |
| 46 | */ | 44 | */ |
| 47 | - @TableField(typeHandler = JacksonTypeHandler.class) | ||
| 48 | private Map<String, String> channelExtras; | 45 | private Map<String, String> channelExtras; |
| 49 | 46 | ||
| 50 | } | 47 | } |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/impl/PayOrderCoreServiceImpl.java
| @@ -57,6 +57,11 @@ public class PayOrderCoreServiceImpl implements PayOrderCoreService { | @@ -57,6 +57,11 @@ public class PayOrderCoreServiceImpl implements PayOrderCoreService { | ||
| 57 | private PayOrderExtensionCoreMapper payOrderExtensionCoreMapper; | 57 | private PayOrderExtensionCoreMapper payOrderExtensionCoreMapper; |
| 58 | 58 | ||
| 59 | @Override | 59 | @Override |
| 60 | + public PayOrderDO getPayOrder(Long id) { | ||
| 61 | + return payOrderCoreMapper.selectById(id); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 60 | public Long createPayOrder(PayOrderCreateReqDTO reqDTO) { | 65 | public Long createPayOrder(PayOrderCreateReqDTO reqDTO) { |
| 61 | // 校验 App | 66 | // 校验 App |
| 62 | PayAppDO app = payAppCoreService.validPayApp(reqDTO.getAppId()); | 67 | PayAppDO app = payAppCoreService.validPayApp(reqDTO.getAppId()); |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/PayOrderController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.pay.controller.order; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.bean.BeanUtil; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayOrderCoreService; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitReqDTO; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitRespDTO; | ||
| 8 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 9 | +import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayOrderSubmitReqVO; | ||
| 10 | +import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayOrderSubmitRespVO; | ||
| 11 | +import io.swagger.annotations.Api; | ||
| 12 | +import io.swagger.annotations.ApiOperation; | ||
| 13 | +import lombok.extern.slf4j.Slf4j; | ||
| 14 | +import org.springframework.validation.annotation.Validated; | ||
| 15 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 16 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 17 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 18 | +import org.springframework.web.bind.annotation.RestController; | ||
| 19 | + | ||
| 20 | +import javax.annotation.Resource; | ||
| 21 | + | ||
| 22 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 23 | +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | ||
| 24 | + | ||
| 25 | +@Api(tags = "支付订单") | ||
| 26 | +@RestController | ||
| 27 | +@RequestMapping("/pay/order") | ||
| 28 | +@Validated | ||
| 29 | +@Slf4j | ||
| 30 | +public class PayOrderController { | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private PayOrderCoreService payOrderCoreService; | ||
| 34 | + | ||
| 35 | + @PostMapping("/submit") | ||
| 36 | + @ApiOperation("提交支付订单") | ||
| 37 | +// @PreAuthenticated // TODO 暂时不加登陆验证,前端暂时没做好 | ||
| 38 | + public CommonResult<PayOrderSubmitRespVO> submit(@RequestBody PayOrderSubmitReqVO reqVO) { | ||
| 39 | + // 获得订单 | ||
| 40 | + PayOrderDO payOrder = payOrderCoreService.getPayOrder(reqVO.getId()); | ||
| 41 | + | ||
| 42 | + // 提交支付 | ||
| 43 | + PayOrderSubmitReqDTO reqDTO = new PayOrderSubmitReqDTO(); | ||
| 44 | + BeanUtil.copyProperties(reqVO, reqDTO, false); | ||
| 45 | + reqDTO.setUserIp(getClientIP()); | ||
| 46 | + reqDTO.setAppId(payOrder.getAppId()); | ||
| 47 | + PayOrderSubmitRespDTO respDTO = payOrderCoreService.submitPayOrder(reqDTO); | ||
| 48 | + | ||
| 49 | + // 拼接返回 | ||
| 50 | + return success(PayOrderSubmitRespVO.builder().invokeResponse(respDTO.getInvokeResponse()).build()); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.pay.controller.order.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.experimental.Accessors; | ||
| 7 | + | ||
| 8 | +import javax.validation.constraints.NotEmpty; | ||
| 9 | +import javax.validation.constraints.NotNull; | ||
| 10 | +import java.util.Map; | ||
| 11 | + | ||
| 12 | +@ApiModel("支付订单提交 Request VO") | ||
| 13 | +@Data | ||
| 14 | +@Accessors(chain = true) | ||
| 15 | +public class PayOrderSubmitReqVO { | ||
| 16 | + | ||
| 17 | + @ApiModelProperty(value = "支付单编号", required = true, example = "1024") | ||
| 18 | + @NotNull(message = "支付单编号不能为空") | ||
| 19 | + private Long id; | ||
| 20 | + | ||
| 21 | + @ApiModelProperty(value = "支付渠道", required = true, example = "wx_pub") | ||
| 22 | + @NotEmpty(message = "支付渠道不能为空") | ||
| 23 | + private String channelCode; | ||
| 24 | + | ||
| 25 | + @ApiModelProperty(value = "支付渠道的额外参数", notes = "例如说,微信公众号需要传递 openid 参数") | ||
| 26 | + private Map<String, String> channelExtras; | ||
| 27 | + | ||
| 28 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/vo/PayOrderSubmitRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.pay.controller.order.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import lombok.AllArgsConstructor; | ||
| 5 | +import lombok.Builder; | ||
| 6 | +import lombok.Data; | ||
| 7 | +import lombok.NoArgsConstructor; | ||
| 8 | +import lombok.experimental.Accessors; | ||
| 9 | + | ||
| 10 | +@ApiModel("支付订单提交 Response VO") | ||
| 11 | +@Data | ||
| 12 | +@Accessors(chain = true) | ||
| 13 | +@Builder | ||
| 14 | +@NoArgsConstructor | ||
| 15 | +@AllArgsConstructor | ||
| 16 | +public class PayOrderSubmitRespVO { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 调用支付渠道的响应结果 | ||
| 20 | + */ | ||
| 21 | + private String invokeResponse; | ||
| 22 | + | ||
| 23 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.pay.controller; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/package-info.java
0 → 100644
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/ShopOrderController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.shop.controller; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayOrderCoreService; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderCreateReqDTO; | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 6 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; | ||
| 7 | +import cn.iocoder.yudao.userserver.modules.shop.controller.vo.ShopOrderCreateRespVO; | ||
| 8 | +import io.swagger.annotations.Api; | ||
| 9 | +import io.swagger.annotations.ApiOperation; | ||
| 10 | +import lombok.extern.slf4j.Slf4j; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 14 | +import org.springframework.web.bind.annotation.RestController; | ||
| 15 | + | ||
| 16 | +import javax.annotation.Resource; | ||
| 17 | +import java.time.Duration; | ||
| 18 | + | ||
| 19 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 20 | +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | ||
| 21 | + | ||
| 22 | +@Api(tags = "商城订单") | ||
| 23 | +@RestController | ||
| 24 | +@RequestMapping("/shop/order") | ||
| 25 | +@Validated | ||
| 26 | +@Slf4j | ||
| 27 | +public class ShopOrderController { | ||
| 28 | + | ||
| 29 | + @Resource | ||
| 30 | + private PayOrderCoreService payOrderCoreService; | ||
| 31 | + | ||
| 32 | + @PostMapping("/create") | ||
| 33 | + @ApiOperation("创建商城订单") | ||
| 34 | +// @PreAuthenticated // TODO 暂时不加登陆验证,前端暂时没做好 | ||
| 35 | + public CommonResult<ShopOrderCreateRespVO> create() { | ||
| 36 | + // 假装创建商城订单 | ||
| 37 | + Long shopOrderId = System.currentTimeMillis(); | ||
| 38 | + | ||
| 39 | + // 创建对应的支付订单 | ||
| 40 | + PayOrderCreateReqDTO reqDTO = new PayOrderCreateReqDTO(); | ||
| 41 | + reqDTO.setAppId(6L); | ||
| 42 | + reqDTO.setUserIp(getClientIP()); | ||
| 43 | + reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis())); | ||
| 44 | + reqDTO.setSubject("标题:" + shopOrderId); | ||
| 45 | + reqDTO.setBody("内容:" + shopOrderId); | ||
| 46 | + reqDTO.setAmount(100); | ||
| 47 | + reqDTO.setExpireTime(DateUtils.addTime(Duration.ofDays(1))); | ||
| 48 | + Long payOrderId = payOrderCoreService.createPayOrder(reqDTO); | ||
| 49 | + | ||
| 50 | + // 拼接返回 | ||
| 51 | + return success(ShopOrderCreateRespVO.builder().id(shopOrderId) | ||
| 52 | + .payOrderId(payOrderId).build()); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/shop/controller/vo/ShopOrderCreateRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.shop.controller.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | +import lombok.AllArgsConstructor; | ||
| 6 | +import lombok.Builder; | ||
| 7 | +import lombok.Data; | ||
| 8 | + | ||
| 9 | +@ApiModel("商城订单创建 Response VO") | ||
| 10 | +@Data | ||
| 11 | +@Builder | ||
| 12 | +@AllArgsConstructor | ||
| 13 | +public class ShopOrderCreateRespVO { | ||
| 14 | + | ||
| 15 | + @ApiModelProperty(value = "商城订单编号", required = true, example = "1024") | ||
| 16 | + private Long id; | ||
| 17 | + | ||
| 18 | + @ApiModelProperty(value = "支付订单编号", required = true, example = "2048") | ||
| 19 | + private Long payOrderId; | ||
| 20 | + | ||
| 21 | +} |