Kaynağa Gözat

支付openAPI

wujiefeng 1 yıl önce
ebeveyn
işleme
5561c03b87

+ 38 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/openApi/params/PayParam.java

@@ -0,0 +1,38 @@
+package com.zhongshu.card.client.openApi.params;
+
+import com.github.microservice.types.payment.PaymentType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import java.math.BigDecimal;
+
+@Data
+public class PayParam {
+
+    @Schema(description = "项目oid")
+    @NotNull(message = "projectOid不能为null")
+    private String projectOid;
+
+    @Schema(description = "机构oid")
+    @NotNull(message = "oid不能为null")
+    private String oid;
+
+    @Schema(description = "用户userId")
+    @NotNull(message = "userId不能为null")
+    private String userId;
+
+    @Schema(description = "金额")
+    private BigDecimal total;
+
+    @Schema(description = "订单号")
+    @NotNull(message = "orderNo不能为null")
+    private String orderNo;
+
+    @Schema(description = "支付方式")
+    private PaymentType paymentType;
+
+    @Schema(description = "备注")
+    private String remark;
+}

+ 43 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/openApi/params/RefundParam.java

@@ -0,0 +1,43 @@
+package com.zhongshu.card.client.openApi.params;
+
+import com.github.microservice.types.payment.PaymentType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.math.BigDecimal;
+
+@Data
+public class RefundParam {
+
+    @Schema(description = "项目oid")
+    @NotNull(message = "projectOid不能为null")
+    private String projectOid;
+
+    @Schema(description = "机构oid")
+    @NotNull(message = "oid不能为null")
+    private String oid;
+
+    @Schema(description = "用户userId")
+    @NotNull(message = "userId不能为null")
+    private String userId;
+
+    @Schema(description = "金额")
+    private BigDecimal total;
+
+    @Schema(description = "订单号")
+    @NotNull(message = "orderNo不能为null")
+    private String orderNo;
+
+    @Schema(description = "支付方式")
+    private PaymentType paymentType;
+
+    @Schema(description = "备注")
+    private String remark;
+
+    @Schema(description = "退款单号,支付方式为银联无感支付时,必传")
+    private String refundOrderNo;
+
+    @Schema(description = "支付订单id,支付方式为银联无感支付时,必传")
+    private String targetOrderId;
+}

+ 80 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/openAPI/PayOpenApiController.java

@@ -0,0 +1,80 @@
+package com.zhongshu.card.server.core.controller.openAPI;
+
+import com.github.microservice.net.ResultContent;
+import com.github.microservice.types.payment.PaymentType;
+import com.zhongshu.card.client.openApi.params.PayParam;
+import com.zhongshu.card.client.openApi.params.RefundParam;
+import com.zhongshu.card.server.core.service.pay.BalancePayService;
+import com.zhongshu.card.server.core.service.pay.ChinaumsSenselessPayService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
+@RestController
+@RequestMapping("/openAPI/v1/pay")
+@Tag(name = "openAPI-支付管理")
+public class PayOpenApiController {
+
+    @Autowired
+    BalancePayService balancePayService;
+
+    @Autowired
+    ChinaumsSenselessPayService chinaumsSenselessPayService;
+
+    @Operation(summary = "查询个人钱包账户余额", description = "查询个人钱包账户余额")
+    @RequestMapping(value = "queryDeviceBindUsers", method = {RequestMethod.GET})
+    public ResultContent<Long> queryUserWallet(@RequestParam("projectOid") String projectOid,
+                                               @RequestParam("userId") String userId){
+        return balancePayService.queryUserBalance(projectOid, userId);
+    }
+
+    @Operation(summary = "支付", description = "支付")
+    @RequestMapping(value = "pay", method = {RequestMethod.POST})
+    public ResultContent pay(@RequestBody @Valid PayParam param){
+
+        if (param.getPaymentType()==null){
+            return ResultContent.buildFail("paymentType is null");
+        }
+
+        if (param.getPaymentType().equals(PaymentType.UserWallet)){
+            return balancePayService.balancePay(param.getProjectOid(), param.getOid(), param.getUserId(), param.getTotal(), param.getOrderNo(), param.getRemark());
+        }else if (param.getPaymentType().equals(PaymentType.UnionFrictionlessPay)){
+            return chinaumsSenselessPayService.senselessPay(param.getProjectOid(), param.getOid(), param.getUserId(), param.getTotal(), param.getOrderNo(), param.getRemark());
+        }
+        return ResultContent.buildFail("参数传入错误,paymentType");
+    }
+
+    @Operation(summary = "退款", description = "退款")
+    @RequestMapping(value = "refund", method = {RequestMethod.POST})
+    public ResultContent refund(@RequestBody @Valid RefundParam param){
+        if (param.getPaymentType()==null){
+            return ResultContent.buildFail("paymentType is null");
+        }
+
+        if (param.getPaymentType().equals(PaymentType.UserWallet)){
+            return balancePayService.refund(param.getProjectOid(), param.getOid(), param.getUserId(), param.getOrderNo(), param.getTotal(), param.getRemark());
+        }else if (param.getPaymentType().equals(PaymentType.UnionFrictionlessPay)){
+            return chinaumsSenselessPayService.refund(param.getProjectOid(), param.getOid(), param.getUserId(), param.getTotal(), param.getOrderNo(), param.getRefundOrderNo(), param.getRemark(), param.getTargetOrderId());
+        }
+        return ResultContent.buildFail("参数传入错误,paymentType");
+    }
+
+    /**
+     * 支付结果查询
+     */
+
+    /**
+     * 退款结果查询
+     */
+
+    /**
+     * 账本
+     */
+
+    /**
+     * 账单
+     */
+}

+ 15 - 19
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/BalancePayService.java

@@ -1,13 +1,8 @@
 package com.zhongshu.card.server.core.service.pay;
 
-import cn.hutool.json.JSONUtil;
 import com.github.microservice.core.util.JsonUtil;
 import com.github.microservice.core.util.bean.BeanUtil;
-import com.github.microservice.core.util.net.apache.HttpClientUtil;
-import com.github.microservice.core.util.net.apache.HttpModel;
-import com.github.microservice.core.util.net.apache.ResponseModel;
 import com.github.microservice.pay.client.model.PayProductParameter;
-import com.github.microservice.pay.client.model.ledger.GeneralLedgerModel;
 import com.github.microservice.pay.client.model.ledger.GeneralLedgerQueryModel;
 import com.github.microservice.pay.client.model.ledger.TransactionLogModel;
 import com.github.microservice.pay.client.model.ledger.TransferTransactionsModel;
@@ -21,18 +16,14 @@ import com.github.microservice.pay.client.type.ledger.TransactionStatus;
 import com.github.microservice.pay.client.type.ledger.TransactionType;
 import com.github.microservice.types.payment.PaymentChannelType;
 import com.github.microservice.types.payment.PaymentType;
-import com.wechat.pay.java.service.payments.model.Transaction;
 import com.zhongshu.card.client.model.mqtt.SendMessageModel;
-import com.zhongshu.card.client.model.pay.PayAccountParam;
 import com.zhongshu.card.client.model.pay.QueryRechargeParam;
 import com.zhongshu.card.client.model.pay.RechargeOrderModel;
 import com.zhongshu.card.client.model.pay.RechargeParam;
 import com.zhongshu.card.client.model.wechat.MiniAppUserInfoVo;
-import com.zhongshu.card.client.type.payAccount.PayAccountLevel;
 import com.zhongshu.card.client.type.payAccount.RechargeOrderStatus;
 import com.zhongshu.card.client.utils.DateUtils;
 import com.zhongshu.card.server.core.dao.pay.BalanceRechargeOrderDao;
-import com.zhongshu.card.server.core.domain.org.UserAccount;
 import com.zhongshu.card.server.core.domain.pay.BalanceRechargeOrder;
 import com.zhongshu.card.server.core.domain.pay.PayAccount;
 import com.zhongshu.card.server.core.service.base.SuperService;
@@ -51,11 +42,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
-import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -203,7 +191,7 @@ public class BalancePayService extends SuperService {
         rechargeOrderDao.save(rechargeOrder);
     }
 
-    public ResultContent<List<TransactionLogModel>> balancePay(String projectOid, String oid, String userId, BigDecimal total, String orderNo, String remark) {
+    public com.github.microservice.net.ResultContent balancePay(String projectOid, String oid, String userId, BigDecimal total, String orderNo, String remark) {
         //获取用户余额支付子账户
         PayAccount userBalancePayment = payAccountService.getUserChildren(projectOid, userId, PaymentChannelType.BalancePayment);
         //获取机构待结算账户
@@ -232,7 +220,11 @@ public class BalancePayService extends SuperService {
         destinationTransaction.setMeta(Map.of("paymentType",PaymentType.UserWallet, "description", "用户余额支付"));
         transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
         //发起转账
-        return transactionLogService.transfer(transferModel);
+        ResultContent<List<TransactionLogModel>> transfer = transactionLogService.transfer(transferModel);
+        if (transfer.getState().equals(ResultState.Success)) {
+            return com.github.microservice.net.ResultContent.buildContent(transfer.getContent());
+        }
+        return com.github.microservice.net.ResultContent.buildFail(transfer.getMsg());
     }
 
     public ResultContent queryRechargeOrder(QueryRechargeParam param) {
@@ -253,7 +245,7 @@ public class BalancePayService extends SuperService {
         return ResultContent.buildContent(Map.of("list", balanceRechargeOrders.stream().map(this::toModel).toList(), "amountTotal", amountTotal));
     }
 
-    public ResultContent<Long> queryUserBalance(String projectOid, String userId) {
+    public com.github.microservice.net.ResultContent<Long> queryUserBalance(String projectOid, String userId) {
 
         if (StringUtils.isEmpty(projectOid)){
             projectOid = getCurrentProjectOid();
@@ -265,9 +257,9 @@ public class BalancePayService extends SuperService {
         PayAccount userBalance = payAccountService.getUserChildren(projectOid, userId, PaymentChannelType.BalancePayment);
         ResultContent<GeneralLedgerQueryModel> ret = generalLedgerService.get(userBalance.getLedgerId());
         if (ret.getState().equals(ResultState.Success)) {
-            return ResultContent.buildContent(ret.getContent().getBalance());
+            return com.github.microservice.net.ResultContent.buildContent(ret.getContent().getBalance());
         }
-        return ResultContent.build(ResultState.Fail);
+        return com.github.microservice.net.ResultContent.buildFail(ret.getMsg());
     }
 
     public ResultContent queryInfo(String orderNo){
@@ -301,7 +293,7 @@ public class BalancePayService extends SuperService {
     /**
      * 商家退款
      */
-    public ResultContent<List<TransactionLogModel>> refund(String projectOid, String oid, String userId, String orderNo, BigDecimal total, String remark){
+    public com.github.microservice.net.ResultContent<List<TransactionLogModel>> refund(String projectOid, String oid, String userId, String orderNo, BigDecimal total, String remark){
         //获取用户余额支付子账户
         PayAccount userAccount = payAccountService.getUserChildren(projectOid, userId, PaymentChannelType.BalancePayment);
         //获取机构待结算子账户
@@ -328,7 +320,11 @@ public class BalancePayService extends SuperService {
         destinationTransaction.setRemark(remark);
         transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
         //调用支付中心转账接口
-        return transactionLogService.transfer(transferModel);
+        ResultContent<List<TransactionLogModel>> transfer = transactionLogService.transfer(transferModel);
+        if (transfer.getState().equals(ResultState.Success)) {
+            return com.github.microservice.net.ResultContent.buildContent(transfer.getContent());
+        }
+        return com.github.microservice.net.ResultContent.buildFail(transfer.getMsg());
     }
 
     /**

+ 1 - 4
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/ChinaumsSenselessPayService.java

@@ -186,10 +186,7 @@ public class ChinaumsSenselessPayService extends SuperService {
         ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
         String mid = conf.getMchId();
         ChinaumsSenselessUserSignInfo topByUserIdAndMidAndExpire = chinaumsSenselessUserSignInfoDao.findTopByUserIdAndMidAndExpire(userId, mid, false);
-        if (topByUserIdAndMidAndExpire.getContractState().equals(ContractState.SIGNED)) {
-            return true;
-        }
-        return false;
+        return topByUserIdAndMidAndExpire.getContractState().equals(ContractState.SIGNED);
     }
 
     /**

+ 6 - 6
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/PayCallService.java

@@ -175,8 +175,8 @@ public class PayCallService extends SuperService {
         paymentProcess.setPayStartTime(System.currentTimeMillis());
 
         entity.setPayStartTime(System.currentTimeMillis());
-        com.github.microservice.pay.client.ret.ResultContent<List<TransactionLogModel>> resultContent = balancePayService.balancePay(entity.getProjectOid(), entity.getShopOid(), entity.getUserId(), entity.getPayAmount(), entity.getPaymentNo(), entity.getRemark());
-        if (resultContent.getState() == ResultState.Success) {
+        com.github.microservice.net.ResultContent<List<TransactionLogModel>> resultContent = balancePayService.balancePay(entity.getProjectOid(), entity.getShopOid(), entity.getUserId(), entity.getPayAmount(), entity.getPaymentNo(), entity.getRemark());
+        if (resultContent.getState() == com.github.microservice.net.ResultState.Success) {
             // 关联参数
             String msg = "支付成功";
             List<TransactionLogModel> list = resultContent.getContent();
@@ -409,8 +409,8 @@ public class PayCallService extends SuperService {
     public BigDecimal queryBalance(ExpenseFlow entity) {
         BigDecimal balance = BigDecimal.ZERO;
         if (entity.getPaymentType() == PaymentType.UserWallet) {
-            com.github.microservice.pay.client.ret.ResultContent<Long> resultContent = balancePayService.queryUserBalance(entity.getProjectOid(), entity.getUserId());
-            if (resultContent.getState() == ResultState.Success) {
+            com.github.microservice.net.ResultContent<Long> resultContent = balancePayService.queryUserBalance(entity.getProjectOid(), entity.getUserId());
+            if (resultContent.getState() == com.github.microservice.net.ResultState.Success) {
                 long number = resultContent.getContent();
                 balance = BigDecimal.valueOf(number);
             } else {
@@ -465,8 +465,8 @@ public class PayCallService extends SuperService {
         refundRecord.setProjectOid(entity.getProjectOid());
         refundRecord.setPaymentType(entity.getPaymentType());
 
-        com.github.microservice.pay.client.ret.ResultContent<List<TransactionLogModel>> resultContent = balancePayService.refund(entity.getProjectOid(), entity.getShopOid(), entity.getUserId(), refundNo, payAmount, param.getRemark());
-        if (resultContent.getState() == ResultState.Success) {
+        com.github.microservice.net.ResultContent<List<TransactionLogModel>> resultContent = balancePayService.refund(entity.getProjectOid(), entity.getShopOid(), entity.getUserId(), refundNo, payAmount, param.getRemark());
+        if (resultContent.getState() == com.github.microservice.net.ResultState.Success) {
             entity.setIsRefund(Boolean.TRUE);
             entity.setRefundRemark(param.getRemark());
             entity.setRefundTime(System.currentTimeMillis());