From 7fd3525256b0e4a0dbb6f08405368990619adf36 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期五, 20 十月 2023 14:08:26 +0800 Subject: [PATCH] 对接第三方分账接口 --- ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java | 80 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java index d1b2c7b..6e3df59 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java @@ -1,5 +1,6 @@ package com.ruoyi.order.controller.miniapp; +import com.alibaba.fastjson.JSONObject; import com.github.binarywang.wxpay.bean.ecommerce.*; import com.github.binarywang.wxpay.bean.notify.WxPayNotifyV3Response; import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingNotifyData; @@ -11,11 +12,19 @@ import com.github.binarywang.wxpay.v3.util.AesUtils; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.order.domain.pojo.account.OrderRefund; import com.ruoyi.order.domain.vo.ProfitSharingNotifyNewResult; +import com.ruoyi.order.domain.vo.WeixinPaymentNotifyVo; +import com.ruoyi.order.domain.vo.WeixinPaymentRefundVo; +import com.ruoyi.order.enums.RefundStatusEnum; import com.ruoyi.order.enums.WxPayNotifyEventTypeEnum; +import com.ruoyi.order.enums.dict.IDict; import com.ruoyi.order.service.account.BackMessageService; +import com.ruoyi.order.service.account.OrderRefundService; import com.ruoyi.order.service.order.OrderService; +import com.ruoyi.order.util.HuiFuTianXiaUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.log4j.Log4j2; @@ -26,6 +35,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.util.Collection; @@ -59,6 +69,9 @@ private WxPayService wxService; @Resource private BackMessageService backMessageService; + + @Resource + private OrderRefundService orderRefundService; @PostMapping(value = "/payNotify") @ApiOperation(value = "微信支付/退款通知") @@ -211,4 +224,71 @@ return signatureHeader; } + + + + @RequestMapping(value = "/wechatPaymentCallback", method = RequestMethod.POST) + @ApiOperation(value = "微信支付通知(汇付天下)") + public void wechatPaymentCallback(@RequestBody JSONObject jsonObject, HttpServletResponse response){ + R<WeixinPaymentNotifyVo> r = HuiFuTianXiaUtil.weixinPaymentNotify(jsonObject); + if(r.getCode() == 200){ + WeixinPaymentNotifyVo data = r.getData(); + String transStat = data.getTransStat(); + if("S".equals(transStat)){ + PartnerTransactionsResult transaction = new PartnerTransactionsResult(); + transaction.setOutTradeNo(data.getReqSeqId()); + //开始处理业务数据 + orderService.payBack(transaction); + + response.setStatus(200); + PrintWriter out = null; + try { + out = response.getWriter(); + out.print("RECV_ORD_ID_" + data.getReqSeqId()); + out.flush(); + } catch (IOException e) { + e.printStackTrace(); + }finally { + out.close(); + } + + } + } + } + + + + @RequestMapping(value = "/wechatPaymentRefundCallback", method = RequestMethod.POST) + @ApiOperation(value = "微信支付退款通知(汇付天下)") + public void wechatPaymentRefundCallback(@RequestBody JSONObject jsonObject, HttpServletResponse response){ + R<WeixinPaymentRefundVo> r = HuiFuTianXiaUtil.weixinPaymentRefundNotify(jsonObject); + if(r.getCode() == 200){ + WeixinPaymentRefundVo data = r.getData(); + String transStat = data.getTransStat(); + if("S".equals(transStat)){ + //开始处理业务数据 + String reqSeqId = data.getReqSeqId(); + OrderRefund orderRefund = orderRefundService.getById(reqSeqId); + if(null != orderRefund){ + orderRefund.setWxRefundId(data.getPartyOrderId()); + orderRefund.setBackTime(data.getTransDate() + data.getTransTime()); + orderRefund.setRefundStatus(2); + orderRefundService.saveOrUpdate(orderRefund); + } + + response.setStatus(200); + PrintWriter out = null; + try { + out = response.getWriter(); + out.print("RECV_ORD_ID_" + data.getReqSeqId()); + out.flush(); + } catch (IOException e) { + e.printStackTrace(); + }finally { + out.close(); + } + + } + } + } } -- Gitblit v1.7.1