ebike-share/ebike-payment/src/main/java/com/cdzy/payment/controller/EbikeWxPaymentController.java

91 lines
3.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.cdzy.payment.controller;
import com.alibaba.fastjson2.JSONObject;
import com.cdzy.common.model.JsonResult;
import com.cdzy.payment.model.dto.EbikePaymentDto;
import com.cdzy.payment.model.dto.EbikeRefundDto;
import com.cdzy.payment.service.WxPayService;
import com.wechat.pay.java.service.payments.model.Transaction;
import com.wechat.pay.java.service.refund.model.Refund;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 用户订单微信支付 控制层。
*
* @author dingchao
* @since 2025-04-24
*/
@RestController
@RequestMapping("/wxPayment")
public class EbikeWxPaymentController {
@Resource
private WxPayService wxPayService;
/**
* 微信支付下单
*
* @param paymentDto 支付信息
* @return 下单成功返回true否则返回false
*/
@PostMapping("/prepay")
public JsonResult<?> prepay(@RequestBody EbikePaymentDto paymentDto) {
JSONObject r = wxPayService.prepay(paymentDto.getOrderId(), paymentDto.getDescription(), paymentDto.getGoodsTag(), paymentDto.getOpenId(), paymentDto.getAmount(), paymentDto.getDetail(), paymentDto.getClientIp());
return r == null?JsonResult.failed("下单失败"):JsonResult.success(r);
}
/**
* 通过交易订单号查询支付订单
*
* @param transactionId 微信支付订单号
* @return 支付订单信息
*/
@GetMapping("/queryOrderById/{transactionId}")
public JsonResult<?> queryOrderById(@PathVariable String transactionId) {
Transaction r = wxPayService.queryOrderById(transactionId);
return r == null?JsonResult.failed(String.format("交易订单号{%s}查询支付订单失败", transactionId)):JsonResult.success(r);
}
/**
* 通过商户(骑行)订单号查询支付订单
*
* @param outTradeNo 商户(骑行)订单号
* @return 支付订单信息
*/
@GetMapping("/queryOrderByOutTradeNo/{outTradeNo}")
public JsonResult<?> queryOrderByOutTradeNo(@PathVariable String outTradeNo) {
Transaction r = wxPayService.queryOrderByOutTradeNo(outTradeNo);
return r == null?JsonResult.failed(String.format("骑行订单号{%s}查询支付订单失败", outTradeNo)):JsonResult.success(r);
}
/**
* 退款申请
*
* @param refundDto 退款信息
* @return 退款成功返回true否则返回false
*/
@PostMapping("/refund")
public JsonResult<?> refund(@RequestBody EbikeRefundDto refundDto) {
String r = wxPayService.refund(refundDto.getPaymentId(), refundDto.getOrderId(), refundDto.getReason(), refundDto.getAmount());
return r == null?JsonResult.failed("退款失败"):JsonResult.success(r);
}
/**
* 通过退款单号查询退款信息
*
* @param outRefundNo 商户(骑行)退款单号
* @return 退款信息
*/
@GetMapping("/refundQuery/{outRefundNo}")
public JsonResult<?> refundQuery(@PathVariable String outRefundNo) {
Refund r = wxPayService.queryRefundByOutNo(outRefundNo);
return r == null?JsonResult.failed(String.format("退款单号{%s}查询退款失败", outRefundNo)):JsonResult.success(r);
}
}