From 882959fb6bb60c72b39cb1d66a49634c4579159e Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期三, 21 八月 2024 20:29:37 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile --- ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/controller/WxPayController.java | 76 +++++++++++++++++++++++++------------ 1 files changed, 51 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..adeb678 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,33 @@ * 支付回调 */ @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>>() {}); 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 +144,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