From a84ec20993bc390c82a50a47b9ea0e12f3dbba43 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 23 八月 2024 17:12:45 +0800
Subject: [PATCH] 消息监听处理
---
ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/controller/WxPayController.java | 86 ++++++++++++++++++++++++++++++------------
1 files changed, 61 insertions(+), 25 deletions(-)
diff --git a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/controller/WxPayController.java b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/controller/WxPayController.java
index 30c22cb..f3e7274 100644
--- a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/controller/WxPayController.java
+++ b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/controller/WxPayController.java
@@ -1,9 +1,12 @@
package com.ruoyi.payment.wx.controller;
import com.fasterxml.jackson.core.type.TypeReference;
+import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
+import com.ruoyi.payment.api.vo.PaymentOrder;
import com.ruoyi.payment.wx.enums.RefundEnum;
import com.ruoyi.payment.wx.model.WxPaymentRefundModel;
+import com.ruoyi.payment.wx.resp.NotifyV3PayDecodeRespBody;
import com.ruoyi.payment.wx.utils.WxV3Pay;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -13,6 +16,7 @@
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
+import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;
@@ -32,22 +36,22 @@
/**
* 按实际修改
*/
- @PostMapping("order")
+ @PostMapping("orderPay")
@ApiOperation("订单支付")
- public AjaxResult<Map<String, Object>> orderPay(@RequestParam Long orderId) {
+ public R<Map<String, Object>> orderPay(@RequestBody PaymentOrder paymentOrder) {
// 查询订单
// 0元订单不走支付
// 价格
- Integer totalPrice = 0;
+ Integer totalPrice = paymentOrder.getAmount().multiply(new BigDecimal(100)).intValue();
// 生成订单号
- String orderNo = "";
+ String orderNo = paymentOrder.getCode();
// 查询用户信息 用户openid
- String openId = "";
+ String openId = paymentOrder.getOpenId();
// 订单做修改
// 调用支付方法
- Map<String, Object> result = wxV3Pay.jsApi(orderNo, totalPrice, openId,"");
+ Map<String, Object> result = wxV3Pay.jsApi(orderNo, totalPrice, openId, paymentOrder.getNotifyUrl(),paymentOrder.getDescription());
log.info("支付参数:{}", result);
- return AjaxResult.ok(result);
+ return R.ok(result);
}
/**
@@ -80,31 +84,43 @@
* 支付回调
*/
@PostMapping("pay/notify")
- public void payNotify(HttpServletRequest request) throws IOException {
+ public R<Map<String, Object>> payNotify(HttpServletRequest request) throws Exception {
try {
- Map<String, Object> params = wxV3Pay.verifyNotify(request, new TypeReference<Map<String, Object>>() {
- });
+ Map<String, Object> params = wxV3Pay.verifyNotify(request, new TypeReference<Map<String, Object>>() {});
+ String outRefundNo = (String) params.get("out_refund_no");
+ String substring = outRefundNo.substring(0, 2);
+ switch (substring){
+ //购物订单
+ case "GW":
+ //更改订单状态
+ //如果是优惠卷赠送优惠卷
+ break;
+ }
+
log.info("支付回调:{}", params);
- // 商户订单号
- String tradeNo = params.get("out_trade_no").toString();
- // 交易状态
- String trade_state = params.get("trade_state").toString();
- // 交易状态描述
- String trade_state_desc = params.get("trade_state_desc").toString();
- // 微信支付订单号
- String transaction_id = params.get("transaction_id").toString();
- // 支付完成时间
- // 时间不对的话,可以调用 WxTimeUtils.toRfc3339Date(success_time)转换一下
- String success_time = params.get("success_time").toString();
- // 附加数据
- Integer attach = Integer.parseInt(params.get("attach").toString());
- // TODO 业务处理
+ return R.ok(params);
} catch (Exception e) {
log.error("支付回调异常:{}", e, e);
wxV3Pay.ack(false, e.getMessage());
+ return R.fail("回调异常");
}
}
+
+ /**
+ * 支付回调成功后
+ */
+ @PostMapping("pay/ack")
+ public void ack(){
+ try {
+ wxV3Pay.ack();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+
/**
* 退款回调
@@ -138,5 +154,25 @@
}
}
-
+
+ /**
+ * 查询订单信息
+ * @param orderId
+ * @return
+ */
+ @PostMapping("query/queryOrderInfo")
+ public R<NotifyV3PayDecodeRespBody> queryOrderInfo(@RequestParam("orderId") String orderId){
+ NotifyV3PayDecodeRespBody query = wxV3Pay.query(orderId);
+ return R.ok(query);
+ }
+
+
+ /**
+ * 关闭订单
+ * @param outTradeNo
+ */
+ @PostMapping("pay/close")
+ public void close(@RequestParam("outTradeNo") String outTradeNo){
+ wxV3Pay.close(outTradeNo);
+ }
}
--
Gitblit v1.7.1