This commit is contained in:
磷叶 2024-09-16 14:34:34 +08:00
parent ad2f6bdfba
commit 957ab5abd8
4 changed files with 78 additions and 62 deletions

View File

@ -1,9 +1,10 @@
package com.ruoyi.common.pay.syb.enums; package com.ruoyi.common.pay.syb.enums;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import java.util.Map;
/** /**
* 交易结果 * 交易结果
* @author wjh * @author wjh
@ -27,6 +28,10 @@ public enum SybTrxStatus {
return SUCCESS.getCode().equals(code); return SUCCESS.getCode().equals(code);
} }
public static boolean isSuccess(Map<String, String> result) {
return result != null && isSuccess(result.get("trxstatus"));
}
public static SybTrxStatus getByCode(String code) { public static SybTrxStatus getByCode(String code) {
for (SybTrxStatus value : SybTrxStatus.values()) { for (SybTrxStatus value : SybTrxStatus.values()) {
if (value.getCode().equals(code)) { if (value.getCode().equals(code)) {

View File

@ -1,12 +1,9 @@
package com.ruoyi.common.pay.syb.service; package com.ruoyi.common.pay.syb.service;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.Map;
@RestController @RestController
@ -16,39 +13,44 @@ public class ApiTestV2 extends BaseController {
@Autowired @Autowired
private SybPayClient service; private SybPayClient service;
@GetMapping("/scanPay") // @GetMapping("/scanPay")
public AjaxResult testScanPay() throws Exception { // public AjaxResult testScanPay() throws Exception {
// TODO Auto-generated method stub // // TODO Auto-generated method stub
String reqsn = String.valueOf(System.currentTimeMillis()); // String reqsn = String.valueOf(System.currentTimeMillis());
Map<String, String> map = service.scanPay(1, reqsn, "标题", "备注", "134775931316089668", "", "", "", ""); // Map<String, String> map = service.scanPay(1, reqsn, "标题", "备注", "134775931316089668", "", "", "", "");
return success(map); // return success(map);
} // }
//
@GetMapping("/query") // @GetMapping("/query")
public AjaxResult testQuery(@RequestParam String trxid) throws Exception { // public AjaxResult testQuery(@RequestParam String trxid) throws Exception {
Map<String, String> map = service.query("", trxid); // Map<String, String> map = service.query("", trxid);
return success(map); // return success(map);
} // }
//
@PostMapping("/refund") // @PostMapping("/refund")
public AjaxResult testRefund() throws Exception { // public AjaxResult testRefund(@RequestParam String sn,@RequestParam Integer amount) throws Exception {
String reqsn = String.valueOf(System.currentTimeMillis()); // Map<String, String> map = service.refund(amount, null, "", sn);
Map<String, String> map = service.refund(1, reqsn, "", "20160712167578.2547"); // return success(map);
return success(map); // }
} //
// @PostMapping("/cancel")
@PostMapping("/cancel") // public AjaxResult testCancel() throws Exception {
public AjaxResult testCancel() throws Exception { // String reqsn = String.valueOf(System.currentTimeMillis());
String reqsn = String.valueOf(System.currentTimeMillis()); // Map<String, String> map = service.cancel(1, reqsn, "112094120001088316", "");
Map<String, String> map = service.cancel(1, reqsn, "112094120001088316", ""); // return success(map);
return success(map); // }
} //
// @PostMapping("/close")
@PostMapping("/pay") // public AjaxResult close(@RequestParam String id, @RequestParam String sn) throws Exception {
public AjaxResult testPay() throws Exception { // Map<String, String> map = service.close(id, sn);
// return success(map);
String reqsn = String.valueOf(System.currentTimeMillis()); // }
Map<String, String> map = service.pay(1L, reqsn, "W06", "标题", "备注", "ol5kD7eeXNGeYE5z7uIhk12K-rBA", "123", "https://test.allinpaygd.com/JWeb/NotifyServlet", "", "", "", "", "", "", "", "", "", "", "", ""); //
return success(map); // @PostMapping("/pay")
} // public AjaxResult testPay() throws Exception {
//
// String reqsn = String.valueOf(System.currentTimeMillis());
// Map<String, String> map = service.pay(1L, reqsn, "W06", "标题", "备注", "ol5kD7eeXNGeYE5z7uIhk12K-rBA", "123", "https://test.allinpaygd.com/JWeb/NotifyServlet", "", "", "", "", "", "", "", "", "", "", "", "");
// return success(map);
// }
} }

View File

@ -1,24 +1,20 @@
package com.ruoyi.ss.payBill.service.impl; package com.ruoyi.ss.payBill.service.impl;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.ruoyi.common.core.redis.RedisLock; import com.ruoyi.common.core.redis.RedisLock;
import com.ruoyi.common.core.redis.enums.RedisLockKey; import com.ruoyi.common.core.redis.enums.RedisLockKey;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.pay.syb.enums.SybTrxStatus; import com.ruoyi.common.pay.syb.enums.SybTrxStatus;
import com.ruoyi.common.pay.syb.service.SybPayService; import com.ruoyi.common.pay.syb.service.SybPayService;
import com.ruoyi.common.pay.wx.service.WxPayService;
import com.ruoyi.common.pay.wx.util.WxPayUtil; import com.ruoyi.common.pay.wx.util.WxPayUtil;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil; import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.SnowFlakeUtil; import com.ruoyi.common.utils.SnowFlakeUtil;
import com.ruoyi.common.utils.collection.CollectionUtils; import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.ss.payBill.domain.PayBill;
import com.ruoyi.ss.payBill.domain.PayBillQuery;
import com.ruoyi.ss.payBill.domain.PayBillVO;
import com.ruoyi.ss.payBill.domain.bo.PayBillRefundBO; import com.ruoyi.ss.payBill.domain.bo.PayBillRefundBO;
import com.ruoyi.ss.payBill.domain.bo.RefundSuccessBO; import com.ruoyi.ss.payBill.domain.bo.RefundSuccessBO;
import com.ruoyi.ss.payBill.domain.dto.PayBillRefundDTO; import com.ruoyi.ss.payBill.domain.dto.PayBillRefundDTO;
@ -28,23 +24,27 @@ import com.ruoyi.ss.payBill.domain.vo.DoPayVO;
import com.ruoyi.ss.payBill.domain.vo.PayResultVO; import com.ruoyi.ss.payBill.domain.vo.PayResultVO;
import com.ruoyi.ss.payBill.interfaces.AfterPay; import com.ruoyi.ss.payBill.interfaces.AfterPay;
import com.ruoyi.ss.payBill.interfaces.AfterRefund; import com.ruoyi.ss.payBill.interfaces.AfterRefund;
import com.ruoyi.ss.payBill.mapper.PayBillMapper;
import com.ruoyi.ss.payBill.service.PayBillConverter; import com.ruoyi.ss.payBill.service.PayBillConverter;
import com.ruoyi.ss.payBill.service.PayBillService;
import com.ruoyi.ss.refund.domain.RefundVO; import com.ruoyi.ss.refund.domain.RefundVO;
import com.ruoyi.ss.refund.service.RefundConverter; import com.ruoyi.ss.refund.service.RefundConverter;
import com.ruoyi.ss.refund.service.RefundService; import com.ruoyi.ss.refund.service.RefundService;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillPayType; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillPayType;
import com.ruoyi.common.pay.wx.service.WxPayService;
import com.wechat.pay.java.service.payments.model.Transaction; import com.wechat.pay.java.service.payments.model.Transaction;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.ss.payBill.mapper.PayBillMapper;
import com.ruoyi.ss.payBill.domain.PayBill;
import com.ruoyi.ss.payBill.domain.PayBillVO;
import com.ruoyi.ss.payBill.domain.PayBillQuery;
import com.ruoyi.ss.payBill.service.PayBillService;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/** /**
* 支付订单Service业务层处理 * 支付订单Service业务层处理
* *
@ -165,11 +165,11 @@ public class PayBillServiceImpl implements PayBillService
return null; return null;
}; };
try { try {
return transactionTemplate.execute(status -> { // 尝试关闭旧的支付订单
// 关闭旧的支付订单 boolean close = this.closeByBstId(bill.getBstId(), bill.getBstType());
boolean close = this.closeByBstId(bill.getBstId(), bill.getBstType()); ServiceUtil.assertion(!close, "关闭旧支付订单失败");
ServiceUtil.assertion(!close, "关闭旧支付订单失败");
return transactionTemplate.execute(status -> {
// 插入订单 // 插入订单
bill.setStatus(PayBillStatus.PAYING.getStatus()); bill.setStatus(PayBillStatus.PAYING.getStatus());
int insert = this.insertPayBill(bill); int insert = this.insertPayBill(bill);
@ -218,7 +218,16 @@ public class PayBillServiceImpl implements PayBillService
} }
// 通联微信 // 通联微信
else if (TransactionBillPayType.TL_WX.getType().equals(bill.getChannelId())) { else if (TransactionBillPayType.TL_WX.getType().equals(bill.getChannelId())) {
sybPayService.closeOrderWx(bill.getPayNo()); try {
sybPayService.closeOrderWx(bill.getPayNo());
} catch (Exception e) {
Map<String, String> result = sybPayService.queryOrderByOutTradeNo(bill.getPayNo());
if (SybTrxStatus.isSuccess(result)) {
throw new ServiceException("交易已成功,无法关闭");
} else {
log.error("关闭通联支付订单出错:{}", e.getMessage());
}
}
} }
} }
} }
@ -473,7 +482,7 @@ public class PayBillServiceImpl implements PayBillService
} else if (TransactionBillPayType.TL_WX.getType().equals(bill.getChannelId())) { } else if (TransactionBillPayType.TL_WX.getType().equals(bill.getChannelId())) {
// 通联微信支付 // 通联微信支付
Map<String, String> result = sybPayService.queryOrderByOutTradeNo(bill.getPayNo()); Map<String, String> result = sybPayService.queryOrderByOutTradeNo(bill.getPayNo());
if (SybTrxStatus.isSuccess(result.get("trxstatus"))) { if (SybTrxStatus.isSuccess(result)) {
return PayResultVO.success(DateUtils.toLocalDate(result.get("fintime"), "yyyyMMddHHmmss")); return PayResultVO.success(DateUtils.toLocalDate(result.get("fintime"), "yyyyMMddHHmmss"));
} else { } else {
return PayResultVO.fail("暂未支付成功"); return PayResultVO.fail("暂未支付成功");

View File

@ -26,7 +26,7 @@ wx:
# 转账回调地址 # 转账回调地址
transferNotifyUrl: https://kg-dev.chuangtewl.com/dev-api/app/pay/notify/wx/transfer transferNotifyUrl: https://kg-dev.chuangtewl.com/dev-api/app/pay/notify/wx/transfer
# 密钥所在位置 # 密钥所在位置
privateKeyPath: D:/project/证书/wxpay-kg/apiclient_key.pem privateKeyPath: H:/project/创特/证书/wxpay-kg/apiclient_key.pem
# 证书序列号 # 证书序列号
merchantSerialNumber: 6AD69237C0F22A9AE51A64F1927E3A0962AC1FB0 merchantSerialNumber: 6AD69237C0F22A9AE51A64F1927E3A0962AC1FB0