瀏覽代碼

支付参数打印

yh 6 天之前
父節點
當前提交
17e1713ac6

+ 7 - 5
fs-service/src/main/java/com/fs/his/service/impl/FsStoreAfterSalesServiceImpl.java

@@ -82,6 +82,7 @@ import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
 import com.google.gson.Gson;
+import lombok.extern.slf4j.Slf4j;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -97,6 +98,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
  * @author fs
  * @date 2023-06-13
  */
+@Slf4j
 @Service
 public class FsStoreAfterSalesServiceImpl implements IFsStoreAfterSalesService {
     @Autowired
@@ -626,10 +628,10 @@ public class FsStoreAfterSalesServiceImpl implements IFsStoreAfterSalesService {
                 refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
                 refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
                 try {
-                    logger.info("微信api证书路径:{}",fsPayConfig.getWxAppKeyPath());
-                    logger.info("微信请求退款入参:{}",refundRequest);
+                    log.info("微信api证书路径:{}",fsPayConfig.getWxAppKeyPath());
+                    log.info("微信请求退款入参:{}",refundRequest);
                     WxPayRefundResult refundResult = wxPayService.refund(refundRequest);
-                    logger.info("微信请求退款出参:{}",refundResult);
+                    log.info("微信请求退款出参:{}",refundResult);
                     WxPayRefundQueryResult refundQueryResult = wxPayService.refundQuery("", refundResult.getOutTradeNo(), refundResult.getOutRefundNo(), refundResult.getRefundId());
                     if (refundQueryResult != null && refundQueryResult.getResultCode().equals("SUCCESS")) {
                         FsStorePayment paymentMap = new FsStorePayment();
@@ -656,10 +658,10 @@ public class FsStoreAfterSalesServiceImpl implements IFsStoreAfterSalesService {
                 model.setOutTradeNo(orderType+"-"+payment.getPayCode());
                 model.setRefundAmount(payment.getPayMoney().toString());
                 request.setBizModel(model);
-                logger.info("支付宝请求退款入参:{}",request);
+                log.info("支付宝请求退款入参:{}",request);
                 try {
                     AlipayTradeRefundResponse response = alipayClient.execute(request);
-                    logger.info("支付宝请求退款出参:{}",response);
+                    log.info("支付宝请求退款出参:{}",response);
                     if (response.isSuccess()) {
                         FsStorePayment paymentMap = new FsStorePayment();
                         paymentMap.setPaymentId(payment.getPaymentId());

+ 14 - 7
fs-service/src/main/java/com/fs/his/service/impl/FsStorePaymentServiceImpl.java

@@ -113,6 +113,7 @@ import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
 import com.google.gson.Gson;
 import com.hc.openapi.tool.fastjson.JSON;
+import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
 
 import org.apache.commons.lang3.exception.ExceptionUtils;
@@ -140,6 +141,7 @@ import javax.servlet.http.HttpServletRequest;
  * @date 2023-08-11
  */
 @Service
+@Slf4j
 @EnableAspectJAutoProxy(exposeProxy = true, proxyTargetClass = true)
 public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
     Logger logger = LoggerFactory.getLogger(getClass());
@@ -698,16 +700,21 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
                     throw new CustomException("退款请求失败"+refund.getResp_desc());
                 }
             } else if ("appPay".equals(fsStorePayment.getPayMode()) && "wx".equals(fsStorePayment.getPayTypeCode())) {
+                MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsStorePayment.getPaymentId());
+                FsPayConfig fsPayConfig = com.alibaba.fastjson.JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
+
                 // 处理微信退款
-                WxPayService wxPayService = getWxPayService();
+                WxPayService wxPayService = getWxPayService(fsPayConfig);
                 WxPayRefundRequest refundRequest = new WxPayRefundRequest();
                 refundRequest.setOutTradeNo(orderType+"-"+fsStorePayment.getPayCode());
                 refundRequest.setOutRefundNo(orderType+"-"+fsStorePayment.getPayCode());
                 refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(fsStorePayment.getPayMoney().toString()));
                 refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(fsStorePayment.getPayMoney().toString()));
+                log.info("微信退款入参:{}",refundRequest);
                 try {
                     WxPayRefundResult refundResult = wxPayService.refund(refundRequest);
                     WxPayRefundQueryResult refundQueryResult = wxPayService.refundQuery("", refundResult.getOutTradeNo(), refundResult.getOutRefundNo(), refundResult.getRefundId());
+                    log.info("微信退款出参:{}",refundQueryResult);
                     if (refundQueryResult != null && refundQueryResult.getResultCode().equals("SUCCESS")) {
                         FsStorePayment paymentMap = new FsStorePayment();
                         paymentMap.setPaymentId(fsStorePayment.getPaymentId());
@@ -724,9 +731,8 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
                 }
 
             } else if ("appPay".equals(fsStorePayment.getPayMode()) && "ali".equals(fsStorePayment.getPayTypeCode())) {
-                // 实例化客户端
-                SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.pay");
-                FsPayConfig fsPayConfig = new Gson().fromJson(sysConfig.getConfigValue(), FsPayConfig.class);
+                MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsStorePayment.getPaymentId());
+                FsPayConfig fsPayConfig = com.alibaba.fastjson.JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
                 AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", fsPayConfig.getAliAppId(), fsPayConfig.getAliPrivateKey(), "json", "utf-8", fsPayConfig.getAliPublicKey(), "RSA2");
                 // 构造请求参数以调用接口
                 AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
@@ -734,8 +740,10 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
                 model.setOutTradeNo(orderType+"-"+fsStorePayment.getPayCode());
                 model.setRefundAmount(fsStorePayment.getPayMoney().toString());
                 request.setBizModel(model);
+                log.info("支付宝请求退款入参:{}",request);
                 try {
                     AlipayTradeRefundResponse response = alipayClient.execute(request);
+                    log.info("支付宝请求退款出参:{}",response);
                     if (response.isSuccess()) {
                         FsStorePayment paymentMap = new FsStorePayment();
                         paymentMap.setPaymentId(fsStorePayment.getPaymentId());
@@ -758,9 +766,8 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
     }
 
 
-    private WxPayService getWxPayService(){
-        SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.pay");
-        FsPayConfig fsPayConfig = new Gson().fromJson(sysConfig.getConfigValue(), FsPayConfig.class);
+    private WxPayService getWxPayService(FsPayConfig fsPayConfig){
+
         WxPayConfig payConfig = new WxPayConfig();
         payConfig.setAppId(fsPayConfig.getWxAppAppId());
         payConfig.setMchId(fsPayConfig.getWxAppMchId());