yudao-user-server 接入支付模块

This commit is contained in:
YunaiV 2021-10-24 00:34:40 +08:00
parent ab19228ca6
commit 3a77cc239b
11 changed files with 211 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.coreservice.modules.pay.service.order;
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO;
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitReqDTO;
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitRespDTO;
@ -13,6 +14,14 @@ import javax.validation.Valid;
*/
public interface PayOrderCoreService {
/**
* 获得支付单
*
* @param id 支付单编号
* @return 支付单
*/
PayOrderDO getPayOrder(Long id);
/**
* 创建支付单
*

View File

@ -1,7 +1,5 @@
package cn.iocoder.yudao.coreservice.modules.pay.service.order.dto;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import lombok.experimental.Accessors;
@ -32,7 +30,7 @@ public class PayOrderSubmitReqDTO implements Serializable {
/**
* 支付渠道
*/
@NotNull(message = "支付渠道")
@NotEmpty(message = "支付渠道不能为空")
private String channelCode;
/**
@ -44,7 +42,6 @@ public class PayOrderSubmitReqDTO implements Serializable {
/**
* 支付渠道的额外参数
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private Map<String, String> channelExtras;
}

View File

@ -56,6 +56,11 @@ public class PayOrderCoreServiceImpl implements PayOrderCoreService {
@Resource
private PayOrderExtensionCoreMapper payOrderExtensionCoreMapper;
@Override
public PayOrderDO getPayOrder(Long id) {
return payOrderCoreMapper.selectById(id);
}
@Override
public Long createPayOrder(PayOrderCreateReqDTO reqDTO) {
// 校验 App

View File

@ -0,0 +1,53 @@
package cn.iocoder.yudao.userserver.modules.pay.controller.order;
import cn.hutool.core.bean.BeanUtil;
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO;
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayOrderCoreService;
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitReqDTO;
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitRespDTO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayOrderSubmitReqVO;
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayOrderSubmitRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
@Api(tags = "支付订单")
@RestController
@RequestMapping("/pay/order")
@Validated
@Slf4j
public class PayOrderController {
@Resource
private PayOrderCoreService payOrderCoreService;
@PostMapping("/submit")
@ApiOperation("提交支付订单")
// @PreAuthenticated // TODO 暂时不加登陆验证前端暂时没做好
public CommonResult<PayOrderSubmitRespVO> submit(@RequestBody PayOrderSubmitReqVO reqVO) {
// 获得订单
PayOrderDO payOrder = payOrderCoreService.getPayOrder(reqVO.getId());
// 提交支付
PayOrderSubmitReqDTO reqDTO = new PayOrderSubmitReqDTO();
BeanUtil.copyProperties(reqVO, reqDTO, false);
reqDTO.setUserIp(getClientIP());
reqDTO.setAppId(payOrder.getAppId());
PayOrderSubmitRespDTO respDTO = payOrderCoreService.submitPayOrder(reqDTO);
// 拼接返回
return success(PayOrderSubmitRespVO.builder().invokeResponse(respDTO.getInvokeResponse()).build());
}
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.yudao.userserver.modules.pay.controller.order.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Map;
@ApiModel("支付订单提交 Request VO")
@Data
@Accessors(chain = true)
public class PayOrderSubmitReqVO {
@ApiModelProperty(value = "支付单编号", required = true, example = "1024")
@NotNull(message = "支付单编号不能为空")
private Long id;
@ApiModelProperty(value = "支付渠道", required = true, example = "wx_pub")
@NotEmpty(message = "支付渠道不能为空")
private String channelCode;
@ApiModelProperty(value = "支付渠道的额外参数", notes = "例如说,微信公众号需要传递 openid 参数")
private Map<String, String> channelExtras;
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.userserver.modules.pay.controller.order.vo;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@ApiModel("支付订单提交 Response VO")
@Data
@Accessors(chain = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PayOrderSubmitRespVO {
/**
* 调用支付渠道的响应结果
*/
private String invokeResponse;
}

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.userserver.modules.pay.controller;

View File

@ -0,0 +1,7 @@
/**
* pay 包下我们放支付业务提供业务的支付能力
* 例如说商户应用支付退款等等
*
* 缩写pay
*/
package cn.iocoder.yudao.userserver.modules.pay;

View File

@ -0,0 +1,55 @@
package cn.iocoder.yudao.userserver.modules.shop.controller;
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayOrderCoreService;
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.userserver.modules.shop.controller.vo.ShopOrderCreateRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.Duration;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
@Api(tags = "商城订单")
@RestController
@RequestMapping("/shop/order")
@Validated
@Slf4j
public class ShopOrderController {
@Resource
private PayOrderCoreService payOrderCoreService;
@PostMapping("/create")
@ApiOperation("创建商城订单")
// @PreAuthenticated // TODO 暂时不加登陆验证前端暂时没做好
public CommonResult<ShopOrderCreateRespVO> create() {
// 假装创建商城订单
Long shopOrderId = System.currentTimeMillis();
// 创建对应的支付订单
PayOrderCreateReqDTO reqDTO = new PayOrderCreateReqDTO();
reqDTO.setAppId(6L);
reqDTO.setUserIp(getClientIP());
reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis()));
reqDTO.setSubject("标题:" + shopOrderId);
reqDTO.setBody("内容:" + shopOrderId);
reqDTO.setAmount(100);
reqDTO.setExpireTime(DateUtils.addTime(Duration.ofDays(1)));
Long payOrderId = payOrderCoreService.createPayOrder(reqDTO);
// 拼接返回
return success(ShopOrderCreateRespVO.builder().id(shopOrderId)
.payOrderId(payOrderId).build());
}
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.userserver.modules.shop.controller.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ApiModel("商城订单创建 Response VO")
@Data
@Builder
@AllArgsConstructor
public class ShopOrderCreateRespVO {
@ApiModelProperty(value = "商城订单编号", required = true, example = "1024")
private Long id;
@ApiModelProperty(value = "支付订单编号", required = true, example = "2048")
private Long payOrderId;
}

View File

@ -0,0 +1,8 @@
/**
* shop 包下我们放商城业务
* 例如说商品订单等等
* 注意目前仅仅作为 demo 演示对接 pay 支付系统
*
* 缩写shop
*/
package cn.iocoder.yudao.userserver.modules.shop;