From 037c144cd417410deb8137c6f3fd271a34691742 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 12 十二月 2023 18:18:17 +0800
Subject: [PATCH] 服务商支付版本

---
 server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java |  106 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 78 insertions(+), 28 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java b/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java
index fa41272..7439fd9 100644
--- a/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java
+++ b/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java
@@ -14,28 +14,25 @@
 import com.doumee.dao.business.model.Transactions;
 import com.doumee.dao.business.web.request.RefundDTO;
 import com.doumee.dao.system.model.SystemDictData;
-import com.doumee.service.business.RefundService;
-import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
-import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
-import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
-import com.github.binarywang.wxpay.exception.WxPayException;
-import io.netty.handler.codec.base64.Base64Decoder;
-import io.netty.handler.codec.base64.Base64Encoder;
+import com.wechat.pay.java.service.refund.model.AmountReq;
+import com.wechat.pay.java.service.refund.model.CreateRequest;
 import lombok.extern.slf4j.Slf4j;
 import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import okhttp3.Response;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import sun.misc.BASE64Decoder;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
 import java.math.BigDecimal;
-import java.util.*;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
 
 /**
  * 寰俊灏忕▼搴�-鍏叡鏂规硶
@@ -52,24 +49,73 @@
 
     @Autowired
     private SystemDictDataBiz systemDictDataBiz;
-
+    @Autowired
+    private WxPayProperties wxPayProperties;
 
     @Transactional(rollbackFor = {BusinessException.class,Exception.class})
-    public Refund wxRefund(RefundDTO refundDTO) {
+    public boolean wxRefund(RefundDTO refundDTO) {
+        // 鍙戦�侀��娆捐姹�
+        Refund refund = new Refund();
+        refund.setId(Constants.getUUID());
+        refund.setCreateDate(new Date());
+        refund.setMemberId(refundDTO.getMemberId());
+        refund.setMoney(refundDTO.getRefundAmount());
+//        refund.setOnlineOrderid(refNum);
+        refund.setPayWay(Constants.ZERO);
+        refund.setStatus(Constants.ZERO);
+        refund.setDoneDate(new Date());
+        refund.setCreator(refundDTO.getCreator());
+        refund.setType(refundDTO.getType());
+        refund.setObjId(refundDTO.getOrderId());
+        refund.setReason(refundDTO.getReason());
+        refund.setCanBalance(refundDTO.getCanBalance());
+        refundMapper.insert(refund);
+
+        CreateRequest request = new CreateRequest();
+        request.setOutTradeNo(refundDTO.getOrderId());
+        request.setOutRefundNo(refund.getId());
+        request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId());
+        request.setNotifyUrl(WxMiniConfig.wxProperties.getRefundNotifyUrl());
+        AmountReq amountReq = new AmountReq();
+        amountReq.setTotal(refundDTO.getTotalAmount().longValue());
+        amountReq.setRefund(refundDTO.getRefundAmount().longValue());
+        amountReq.setCurrency("CNY");
+        request.setAmount(amountReq);
         try {
-            // 鍙戦�侀��娆捐姹�
-            String refNum = ID.nextGUID();
-            WxPayRefundRequest request = new WxPayRefundRequest();
-            request.setOutTradeNo(refundDTO.getOrderId());
-            request.setOutRefundNo(refNum);
-            request.setTotalFee(refundDTO.getTotalAmount().intValue());
-            request.setRefundFee(refundDTO.getRefundAmount().intValue());
-            System.out.println("瀹為檯鎬婚噾棰�" + refundDTO.getTotalAmount());
-            System.out.println("瀹為檯閫�娆鹃噾棰�" + refundDTO.getRefundAmount());
+            com.wechat.pay.java.service.refund.model.Refund response = WxMiniConfig.refundService.create(request);
+            if ("SUCCESS".equals(response.getStatus().name())
+                    || "PROCESSING".equals(response.getStatus().name()) ) {
+                return  true;
+            }else{
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝閫�娆剧敵璇峰け璐ュ摝锛�");
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝閫�娆剧敵璇峰け璐ワ紒");
+        }
+
+    }
+    public Refund wxRefundOld(RefundDTO refundDTO) {
+        // 鍙戦�侀��娆捐姹�
+        String refNum = ID.nextGUID();
+        CreateRequest request = new CreateRequest();
+        request.setOutTradeNo(refundDTO.getOrderId());
+        request.setOutRefundNo(refNum);
+        request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId());
+        request.setNotifyUrl(WxMiniConfig.wxProperties.getRefundNotifyUrl());
+//
+        AmountReq amountReq = new AmountReq();
+        amountReq.setTotal(refundDTO.getTotalAmount().longValue());
+        amountReq.setRefund(refundDTO.getRefundAmount().longValue());
+        amountReq.setCurrency("CNY");
+        request.setAmount(amountReq);
+        System.out.println("瀹為檯鎬婚噾棰�" + refundDTO.getTotalAmount());
+        System.out.println("瀹為檯閫�娆鹃噾棰�" + refundDTO.getRefundAmount());
 //            request.setTotalFee(1);
 //            request.setRefundFee(1);
-            WxPayRefundResult response = WxMiniConfig.wxPayService.refund(request);
-            if ("SUCCESS".equals(response.getReturnCode()) && "SUCCESS".equals(response.getResultCode())) {
+        try {
+            com.wechat.pay.java.service.refund.model.Refund response = WxMiniConfig.refundService.create(request);
+            if ("SUCCESS".equals(response.getStatus().name()) ) {
                 //瀛樺偍閫�娆捐褰� 涓� 娴佹按璁板綍
                 Refund refund = new Refund();
                 refund.setId(Constants.getUUID());
@@ -119,12 +165,16 @@
                 transactionsMapper.insert(transactions);
                 return refund;
             } else{
-                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),response.getErrCode() + response.getErrCodeDes());
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝閫�娆惧け璐ワ紒");
             }
-        } catch (WxPayException e) {
+        }catch (BusinessException e){
+            throw e;
+        }catch (Exception e){
             e.printStackTrace();
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝閫�娆惧け璐ワ紒");
         }
-        throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"閫�娆惧彂鐢熷紓甯歌鑱旂郴绠$悊鍛�");
+
+
     }
 
 

--
Gitblit v1.9.3