增加支付宝支付实现
This commit is contained in:
@ -34,6 +34,9 @@ public class SimpleUserInfoDTO {
|
||||
@ApiModelProperty("支付宝小程序 userid")
|
||||
private String alipayUserid;
|
||||
|
||||
@ApiModelProperty("支付宝小程序 openid")
|
||||
private String alipayOpenid;
|
||||
|
||||
|
||||
@ApiModelProperty("是否认证0未认证1已认证")
|
||||
private Integer authed;
|
||||
|
||||
@ -23,6 +23,7 @@ import com.sczx.order.service.OrderDistribService;
|
||||
import com.sczx.order.service.OrderService;
|
||||
import com.sczx.order.service.PayService;
|
||||
import com.sczx.order.thirdpart.dto.*;
|
||||
import com.sczx.order.thirdpart.dto.req.AlipayCloseRequest;
|
||||
import com.sczx.order.thirdpart.dto.req.CarQueryConditionReq;
|
||||
import com.sczx.order.thirdpart.integration.CarInteg;
|
||||
import com.sczx.order.thirdpart.integration.PayInteg;
|
||||
@ -413,6 +414,12 @@ public class OrderServiceImpl implements OrderService {
|
||||
if(StringUtils.equalsIgnoreCase(orderSubPO.getPaymentMethod(), PaymentTypeEnum.WX_PAY.getCode())){
|
||||
log.info("开始关闭支付单");
|
||||
closePayOrder = payInteg.closeOrder(Long.valueOf(companyStoreDTO.getOperatingCompanyId()), orderSubPO.getPaymentId());
|
||||
} else if(StringUtils.equalsIgnoreCase(orderSubPO.getPaymentMethod(), PaymentTypeEnum.ZFB_PAY.getCode())){
|
||||
log.info("开始关闭支付宝支付单");
|
||||
AlipayCloseRequest alipayCloseRequest = new AlipayCloseRequest();
|
||||
alipayCloseRequest.setCompanyId(Long.valueOf(companyStoreDTO.getOperatingCompanyId()));
|
||||
alipayCloseRequest.setOutTradeNo(orderSubPO.getPaymentId());
|
||||
closePayOrder = payInteg.alipayCloseOrder(alipayCloseRequest);
|
||||
}
|
||||
|
||||
if(closePayOrder){
|
||||
@ -692,6 +699,12 @@ public class OrderServiceImpl implements OrderService {
|
||||
String orderState = paySuccessOrder(orderMainPO, orderSubPO);
|
||||
orderDetailDTO.setOrderStatus(orderState);
|
||||
}
|
||||
}else if(PaymentTypeEnum.ZFB_PAY.getCode().equals(orderSubPO.getPaymentMethod())){
|
||||
AlipayQueryResponse alipayQueryResponse = payInteg.alipayOrderQuery((long)companyStoreDTO.getOperatingCompanyId(), orderSubPO.getPaymentId());
|
||||
if(StringUtils.equalsIgnoreCase(alipayQueryResponse.getCode(), "SUCCESS")){
|
||||
String orderState = paySuccessOrder(orderMainPO, orderSubPO);
|
||||
orderDetailDTO.setOrderStatus(orderState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@ import com.sczx.order.common.enums.PaymentTypeEnum;
|
||||
import com.sczx.order.dto.SimpleUserInfoDTO;
|
||||
import com.sczx.order.service.PayService;
|
||||
import com.sczx.order.thirdpart.dto.UnifiedPaymentInfoDTO;
|
||||
import com.sczx.order.thirdpart.dto.req.AlipayCreateRequest;
|
||||
import com.sczx.order.thirdpart.dto.req.AlipayRefundRequest;
|
||||
import com.sczx.order.thirdpart.dto.req.PaymentRequest;
|
||||
import com.sczx.order.thirdpart.dto.req.RefundRequest;
|
||||
import com.sczx.order.thirdpart.integration.PayInteg;
|
||||
@ -41,6 +43,16 @@ public class PayServiceImpl implements PayService {
|
||||
// paymentRequest.setTotalFee(10);
|
||||
unifiedPaymentInfoDTO = payInteg.unifiedOrder(paymentRequest);
|
||||
// TODO 其他支付类型
|
||||
} else if (StringUtils.equalsIgnoreCase(payType, PaymentTypeEnum.ZFB_PAY.getCode())) {
|
||||
String openId = userInfoDTO.getAlipayOpenid();
|
||||
AlipayCreateRequest alipayCreateRequest = new AlipayCreateRequest();
|
||||
alipayCreateRequest.setCompanyId(companyId);
|
||||
alipayCreateRequest.setOpenId(openId);
|
||||
alipayCreateRequest.setSubject(body);
|
||||
alipayCreateRequest.setBody(body);
|
||||
alipayCreateRequest.setOutTradeNo(outTradeNo);
|
||||
alipayCreateRequest.setTotalAmount(totalFee.toString());
|
||||
unifiedPaymentInfoDTO = payInteg.alipayUnifiedOrder(alipayCreateRequest);
|
||||
}
|
||||
return unifiedPaymentInfoDTO;
|
||||
}
|
||||
@ -61,6 +73,14 @@ public class PayServiceImpl implements PayService {
|
||||
// refundRequest.setTotalFee(10);
|
||||
// refundRequest.setRefundFee(10);
|
||||
payInteg.refund(refundRequest);
|
||||
} else if (StringUtils.equalsIgnoreCase(payType, PaymentTypeEnum.ZFB_PAY.getCode())) {
|
||||
AlipayRefundRequest request = new AlipayRefundRequest();
|
||||
request.setCompanyId(companyId);
|
||||
request.setOutTradeNo(outTradeNo);
|
||||
request.setOutRequestNo(outRefundNo);
|
||||
request.setRefundAmount(refundFee.toString());
|
||||
request.setRefundReason("退款");
|
||||
payInteg.alipayRefund(request);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("退款失败", e);
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.sczx.order.thirdpart.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
// 支付宝支付响应
|
||||
@Data
|
||||
public class AlipayCreateResponse {
|
||||
private boolean success;
|
||||
private String message;
|
||||
private String tradeNo; // 支付宝交易号
|
||||
private String outTradeNo; // 商户订单号
|
||||
private String orderStr; // 支付串(用于前端调起支付)
|
||||
private String code; // 状态码
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.sczx.order.thirdpart.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
// 支付宝订单查询响应
|
||||
@Data
|
||||
public class AlipayQueryResponse {
|
||||
private boolean success;
|
||||
private String message;
|
||||
private String tradeNo; // 支付宝交易号
|
||||
private String outTradeNo; // 商户订单号
|
||||
private String tradeStatus; // 交易状态
|
||||
private String code; // 状态码
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.sczx.order.thirdpart.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AlipayResponse {
|
||||
private boolean success;
|
||||
private String message;
|
||||
private String code; // 状态码
|
||||
}
|
||||
@ -59,4 +59,7 @@ public class UnifiedPaymentInfoDTO {
|
||||
*/
|
||||
@ApiModelProperty(value = "商户订单号")
|
||||
private String outTradeNo;
|
||||
|
||||
@ApiModelProperty(value = "支付宝交易号")
|
||||
private String tradeNo; // 支付宝交易号
|
||||
}
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.sczx.order.thirdpart.dto.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
// 支付宝查询请求
|
||||
@Data
|
||||
public class AlipayCloseRequest {
|
||||
private Long companyId;
|
||||
private String outTradeNo; // 商户订单号
|
||||
private String reasonCode; //原因编码
|
||||
private String reasonDesc;
|
||||
private String openId; //买家支付宝用户唯一标识
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.sczx.order.thirdpart.dto.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
// 支付宝支付请求
|
||||
@Data
|
||||
public class AlipayCreateRequest {
|
||||
private Long companyId; // 公司ID
|
||||
private String outTradeNo; // 商户订单号
|
||||
private String subject; // 订单标题
|
||||
private String totalAmount; // 订单总金额
|
||||
private String body; // 订单描述
|
||||
private String openId; // 用户ID
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.sczx.order.thirdpart.dto.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
// 支付宝查询请求
|
||||
@Data
|
||||
public class AlipayQueryRequest {
|
||||
private Long companyId;
|
||||
private String outTradeNo; // 商户订单号
|
||||
private String tradeNo; // 支付宝交易号(可选,与outTradeNo二选一)
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.sczx.order.thirdpart.dto.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
// 支付宝退款请求
|
||||
@Data
|
||||
public class AlipayRefundRequest {
|
||||
private Long companyId;
|
||||
private String outTradeNo; // 商户订单号
|
||||
private String refundAmount; // 退款金额
|
||||
private String refundReason; // 退款原因
|
||||
private String outRequestNo; // 退款请求号
|
||||
private String tradeNo; // 支付宝交易号(可选,与outTradeNo二选一)
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
package com.sczx.order.thirdpart.facade;
|
||||
|
||||
import com.sczx.order.thirdpart.dto.AlipayCreateResponse;
|
||||
import com.sczx.order.thirdpart.dto.AlipayQueryResponse;
|
||||
import com.sczx.order.thirdpart.dto.AlipayResponse;
|
||||
import com.sczx.order.thirdpart.dto.PaymentResponse;
|
||||
import com.sczx.order.thirdpart.dto.req.PaymentRequest;
|
||||
import com.sczx.order.thirdpart.dto.req.RefundRequest;
|
||||
import com.sczx.order.thirdpart.dto.req.*;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -53,4 +55,35 @@ public interface PayFacade {
|
||||
*/
|
||||
@PostMapping("/api/payment/close/{companyId}/{outTradeNo}")
|
||||
Map<String, String> closeOrder(@PathVariable Long companyId, @PathVariable String outTradeNo);
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝统一下单接口
|
||||
*/
|
||||
@PostMapping("/api/alipay/unifiedOrder")
|
||||
AlipayCreateResponse alipayUnifiedOrder(@RequestBody AlipayCreateRequest request);
|
||||
|
||||
/**
|
||||
* 查询订单接口
|
||||
*/
|
||||
@GetMapping("/api/alipay/query/{companyId}/{outTradeNo}")
|
||||
AlipayQueryResponse alipayOrderQuery(@PathVariable Long companyId, @PathVariable String outTradeNo);
|
||||
|
||||
/**
|
||||
* 关闭订单接口
|
||||
*/
|
||||
@PostMapping("/api/alipay/close")
|
||||
AlipayResponse alipayCloseOrder(@RequestBody AlipayCloseRequest request);
|
||||
|
||||
/**
|
||||
* 申请退款接口
|
||||
*/
|
||||
@PostMapping("/api/alipay/refund")
|
||||
AlipayResponse alipayRefund(@RequestBody AlipayRefundRequest request);
|
||||
|
||||
/**
|
||||
* 查询退款接口
|
||||
*/
|
||||
@PostMapping("/api/alipay/refundQuery")
|
||||
AlipayResponse alipayRefundQuery(@RequestBody AlipayRefundRequest request);
|
||||
}
|
||||
|
||||
@ -2,10 +2,8 @@ package com.sczx.order.thirdpart.integration;
|
||||
|
||||
import com.sczx.order.common.enums.PaymentTypeEnum;
|
||||
import com.sczx.order.exception.InnerException;
|
||||
import com.sczx.order.thirdpart.dto.PaymentResponse;
|
||||
import com.sczx.order.thirdpart.dto.UnifiedPaymentInfoDTO;
|
||||
import com.sczx.order.thirdpart.dto.req.PaymentRequest;
|
||||
import com.sczx.order.thirdpart.dto.req.RefundRequest;
|
||||
import com.sczx.order.thirdpart.dto.*;
|
||||
import com.sczx.order.thirdpart.dto.req.*;
|
||||
import com.sczx.order.thirdpart.facade.PayFacade;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -133,4 +131,93 @@ public class PayInteg {
|
||||
throw new InnerException("关闭订单失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝统一下单接口
|
||||
*/
|
||||
public UnifiedPaymentInfoDTO alipayUnifiedOrder(AlipayCreateRequest request){
|
||||
try {
|
||||
AlipayCreateResponse result = payFacade.alipayUnifiedOrder(request);
|
||||
if(StringUtils.isNotBlank(result.getCode()) && "SUCCESS".equals(result.getCode())){
|
||||
UnifiedPaymentInfoDTO unifiedPaymentInfo = new UnifiedPaymentInfoDTO();
|
||||
unifiedPaymentInfo.setOutTradeNo(result.getOutTradeNo());
|
||||
unifiedPaymentInfo.setTradeNo(result.getTradeNo());
|
||||
return unifiedPaymentInfo;
|
||||
} else {
|
||||
throw new InnerException("支付宝统一下单失败");
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error("支付宝统一下单失败",e);
|
||||
throw new InnerException("支付宝统一下单失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单接口
|
||||
*/
|
||||
|
||||
public AlipayQueryResponse alipayOrderQuery(Long companyId, String outTradeNo){
|
||||
try {
|
||||
AlipayQueryResponse result = payFacade.alipayOrderQuery(companyId, outTradeNo);
|
||||
if(StringUtils.isNotBlank(result.getCode()) && "SUCCESS".equals(result.getCode())){
|
||||
return result;
|
||||
} else {
|
||||
throw new InnerException("支付宝查询订单失败");
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error("支付宝查询订单失败",e);
|
||||
throw new InnerException("支付宝查询订单失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭订单接口
|
||||
*/
|
||||
public Boolean alipayCloseOrder(AlipayCloseRequest request){
|
||||
try {
|
||||
AlipayResponse result = payFacade.alipayCloseOrder(request);
|
||||
if(StringUtils.isNotBlank(result.getCode()) && "SUCCESS".equals(result.getCode())){
|
||||
return true;
|
||||
} else {
|
||||
throw new InnerException("支付宝关闭订单失败");
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error("支付宝关闭订单失败",e);
|
||||
throw new InnerException("支付宝关闭订单失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请退款接口
|
||||
*/
|
||||
public AlipayResponse alipayRefund(AlipayRefundRequest request){
|
||||
try {
|
||||
AlipayResponse result = payFacade.alipayRefund(request);
|
||||
if(StringUtils.isNotBlank(result.getCode()) && "SUCCESS".equals(result.getCode())){
|
||||
return result;
|
||||
} else {
|
||||
throw new InnerException("支付宝申请退款失败");
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error("支付宝申请退款失败",e);
|
||||
throw new InnerException("支付宝申请退款失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询退款接口
|
||||
*/
|
||||
public AlipayResponse alipayRefundQuery(AlipayRefundRequest request){
|
||||
try {
|
||||
AlipayResponse result = payFacade.alipayRefundQuery(request);
|
||||
if(StringUtils.isNotBlank(result.getCode()) && "SUCCESS".equals(result.getCode())){
|
||||
return result;
|
||||
} else {
|
||||
throw new InnerException("支付宝查询退款失败");
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error("支付宝查询退款失败",e);
|
||||
throw new InnerException("支付宝查询退款失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user