From 6acf6357094588946b5528f1ef1ed84a0f1037fd Mon Sep 17 00:00:00 2001
From: huliguo <2023611923@qq.com>
Date: 星期五, 13 六月 2025 19:45:27 +0800
Subject: [PATCH] 小程序收付款

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java |   61 +++++++++++++++++++-----------
 1 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
index c08a457..9594278 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
@@ -24,6 +24,9 @@
 import com.ruoyi.order.service.OrderService;
 import com.ruoyi.order.util.payment.model.RefundCallbackResult;
 import com.ruoyi.order.util.payment.model.UniPayCallbackResult;
+import com.ruoyi.order.util.payment.wechat.PayMoneyUtil;
+import com.ruoyi.order.util.payment.wx.WechatPayService;
+import com.ruoyi.order.util.payment.wx.vo.PayResult;
 import com.ruoyi.order.util.vo.MapTrackKD100Vo;
 import com.ruoyi.order.util.vo.ShopAnalysisVO;
 import com.ruoyi.order.vo.*;
@@ -37,10 +40,12 @@
 import com.ruoyi.system.api.model.LoginUser;
 import io.swagger.annotations.*;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -82,7 +87,10 @@
 
     @Resource
     private ShopClient shopClient;
-
+    @Resource
+    private PayMoneyUtil payMoneyUtil;
+    @Resource
+    private WechatPayService wechatPayService;
 
 
     @ResponseBody
@@ -104,12 +112,19 @@
      * 订单支付回调通知
      */
     @ResponseBody
-    @GetMapping("/orderPaymentCallback")
-    public void orderPaymentCallback(UniPayCallbackResult uniPayCallbackResult, HttpServletResponse response){
-        String jsonString = JSONObject.toJSONString(uniPayCallbackResult);
+    @PostMapping("/orderPaymentCallback")
+    public void orderPaymentCallback(HttpServletRequest request, HttpServletResponse response){
+//        String jsonString = JSONObject.toJSONString(uniPayCallbackResult);
+        System.err.println("1111111111111");
+        PayResult  payResult= null;
+        try {
+            payResult = wechatPayService.processNotify(request);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
         System.out.println("1111111111111111111111");
-        System.out.println(jsonString);
-        R callback = orderService.orderPaymentCallback(uniPayCallbackResult);
+//        System.out.println(jsonString);
+        R callback = orderService.orderPaymentCallback(payResult);
         if(callback.getCode() == 200){
             response.setStatus(200);
             PrintWriter out = null;
@@ -406,26 +421,16 @@
 */
     /**
      * 订单取消支付回退
-     *
-     * @param refundCallbackResult
-     * @param response
-     * @return
      */
     @ResponseBody
-    @GetMapping("/refundPayMoneyCallback")
-    public void refundPayMoneyCallback(RefundCallbackResult refundCallbackResult, HttpServletResponse response) {
-        R callback = orderService.refundPayMoneyCallback(refundCallbackResult);
+    @PostMapping("/refundPayMoneyCallback")
+    public String refundPayMoneyCallback( @RequestBody(required = false) String xmlData) {
+        R callback = orderService.refundPayMoneyCallback(xmlData);
         if (callback.getCode() == 200) {
-            response.setStatus(200);
-            PrintWriter out = null;
-            try {
-                out = response.getWriter();
-            } catch (IOException e) {
-                throw new RuntimeException(e);
-            }
-            out.println("success");
-            out.flush();
-            out.close();
+          return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
+        }else {
+            System.err.println("支付回退错误:"+callback.getMsg());
+            return "<xml><return_code><![CDATA[FAIL]]></return_code></xml>";
         }
     }
 
@@ -778,5 +783,15 @@
         return R.ok(orderService.getMap(queryWrapper));
     }
 
+    /**
+     * 获取商户RSA加密公钥
+     */
+
+    @GetMapping("/getRsaPublicKey")
+    public R<Void> getRsaPublicKey(){
+        wechatPayService.getRsaPublicKey();
+        return R.ok();
+    }
+
 }
 

--
Gitblit v1.7.1