|
@@ -12,8 +12,6 @@ import com.bosshand.virgo.api.workark.model.RefundInfo;
|
|
|
import com.bosshand.virgo.api.workark.util.AesUtil;
|
|
|
import com.bosshand.virgo.api.workark.util.QrRcodeGenUtil;
|
|
|
import com.google.gson.Gson;
|
|
|
-import com.wechat.pay.java.core.Config;
|
|
|
-import com.wechat.pay.java.core.RSAPublicKeyConfig;
|
|
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
import com.wechat.pay.java.service.payments.nativepay.NativePayService;
|
|
|
import com.wechat.pay.java.service.payments.nativepay.model.*;
|
|
@@ -25,15 +23,12 @@ import com.wechat.pay.java.service.refund.model.Refund;
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.InputStreamReader;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.GeneralSecurityException;
|
|
@@ -60,39 +55,15 @@ public class WxPayService {
|
|
|
@Autowired
|
|
|
private QuartzService quartzService;
|
|
|
|
|
|
- private final ReentrantLock lock = new ReentrantLock();
|
|
|
+ @Resource
|
|
|
+ private NativePayService nativePayService;
|
|
|
|
|
|
- private final static Log log = LogFactory.getLog(WxPayService.class);
|
|
|
+ @Resource
|
|
|
+ private RefundService refundService;
|
|
|
|
|
|
- public String getFileContent(String filePath) {
|
|
|
- try {
|
|
|
- ClassPathResource resource = new ClassPathResource(filePath);
|
|
|
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
|
|
|
- StringBuilder content = new StringBuilder();
|
|
|
- String line;
|
|
|
- while ((line = reader.readLine()) != null) {
|
|
|
- content.append(line).append("\n");
|
|
|
- }
|
|
|
- return content.toString();
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException("Error reading file: " + filePath, e);
|
|
|
- }
|
|
|
- }
|
|
|
+ private final ReentrantLock lock = new ReentrantLock();
|
|
|
|
|
|
- private Config getConfig(){
|
|
|
- // 初始化商户配置
|
|
|
- Config config =
|
|
|
- new RSAPublicKeyConfig.Builder()
|
|
|
- .merchantId(wxPayConfig.getMchId())
|
|
|
- .privateKey(getFileContent(wxPayConfig.getPrivateKeyPath()))
|
|
|
- .publicKey(getFileContent(wxPayConfig.getPublicKeyPath()))
|
|
|
- .publicKeyId(wxPayConfig.getPublicKeyId())
|
|
|
- .merchantSerialNumber(wxPayConfig.getMchSerialNo())
|
|
|
- .apiV3Key(wxPayConfig.getApiV3Key())
|
|
|
- .build();
|
|
|
- return config;
|
|
|
- }
|
|
|
+ private final static Log log = LogFactory.getLog(WxPayService.class);
|
|
|
|
|
|
/**
|
|
|
* 创建订单,调用Native支付接口
|
|
@@ -121,9 +92,6 @@ public class WxPayService {
|
|
|
|
|
|
log.info("调用统一下单API");
|
|
|
|
|
|
- // 初始化服务
|
|
|
- NativePayService service = new NativePayService.Builder().config(getConfig()).build();
|
|
|
-
|
|
|
PrepayRequest request = new PrepayRequest();
|
|
|
request.setAppid(wxPayConfig.getAppid());
|
|
|
request.setMchid(wxPayConfig.getMchId());
|
|
@@ -142,7 +110,7 @@ public class WxPayService {
|
|
|
request.setAmount(amount);
|
|
|
|
|
|
// 调用下单方法,得到应答
|
|
|
- PrepayResponse response = service.prepay(request);
|
|
|
+ PrepayResponse response = nativePayService.prepay(request);
|
|
|
|
|
|
// 使用微信扫描 code_url 对应的二维码
|
|
|
codeUrl = response.getCodeUrl();
|
|
@@ -171,14 +139,12 @@ public class WxPayService {
|
|
|
|
|
|
log.info("关单接口的调用,订单号 ===>"+ orderNo);
|
|
|
|
|
|
- NativePayService service = new NativePayService.Builder().config(getConfig()).build();
|
|
|
-
|
|
|
CloseOrderRequest request = new CloseOrderRequest();
|
|
|
|
|
|
request.setMchid(wxPayConfig.getMchId());
|
|
|
request.setOutTradeNo(orderNo);
|
|
|
|
|
|
- service.closeOrder(request);
|
|
|
+ nativePayService.closeOrder(request);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -230,13 +196,11 @@ public class WxPayService {
|
|
|
|
|
|
log.info("查单接口调用 ===>" + orderNo);
|
|
|
|
|
|
- NativePayService service = new NativePayService.Builder().config(getConfig()).build();
|
|
|
-
|
|
|
QueryOrderByOutTradeNoRequest request = new QueryOrderByOutTradeNoRequest();
|
|
|
request.setMchid(wxPayConfig.getMchId());
|
|
|
request.setOutTradeNo(orderNo);
|
|
|
|
|
|
- Transaction transaction = service.queryOrderByOutTradeNo(request);
|
|
|
+ Transaction transaction = nativePayService.queryOrderByOutTradeNo(request);
|
|
|
|
|
|
String name = transaction.getTradeState().name();
|
|
|
|
|
@@ -262,8 +226,6 @@ public class WxPayService {
|
|
|
|
|
|
log.info("调用退款API");
|
|
|
|
|
|
- RefundService service = new RefundService.Builder().config(getConfig()).build();
|
|
|
-
|
|
|
CreateRequest request = new CreateRequest();
|
|
|
|
|
|
request.setOutTradeNo(orderNo);//订单编号
|
|
@@ -284,7 +246,7 @@ public class WxPayService {
|
|
|
|
|
|
request.setAmount(amount);
|
|
|
|
|
|
- Refund refund1 = service.create(request);
|
|
|
+ Refund refund1 = refundService.create(request);
|
|
|
|
|
|
//更新订单状态
|
|
|
orderInfoService.updateStatusByOrderNo(orderNo, OrderStatus.REFUND_PROCESSING);
|
|
@@ -302,14 +264,12 @@ public class WxPayService {
|
|
|
|
|
|
log.info("查询退款接口调用 ===>"+ refundNo);
|
|
|
|
|
|
- RefundService service = new RefundService.Builder().config(getConfig()).build();
|
|
|
-
|
|
|
QueryByOutRefundNoRequest request = new QueryByOutRefundNoRequest();
|
|
|
|
|
|
request.setOutRefundNo(refundNo);
|
|
|
request.setSubMchid(wxPayConfig.getMchId());
|
|
|
|
|
|
- Refund refund = service.queryByOutRefundNo(request);
|
|
|
+ Refund refund = refundService.queryByOutRefundNo(request);
|
|
|
|
|
|
return JSONObject.toJSONString(refund);
|
|
|
|