| | |
| | | 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; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | |
| | | /** |
| | | * 按实际修改 |
| | | */ |
| | | @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); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 支付回调 |
| | | */ |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 退款回调 |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询订单信息 |
| | | * @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); |
| | | } |
| | | } |