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

89 lines
2.9 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.EbikeRefundDto;
import com.cdzy.payment.model.dto.HandleNotifyResult;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
/**
* 用户订单微信支付 控制层。
*
* @author dingchao
* @since 2025-04-24
*/
@Slf4j
@RestController
@RequestMapping("/wxPayment")
public class EbikeWxPaymentController {
@Resource
private WxPayService wxPayService;
/**
* 微信支付下单
*
* @param orderId 骑行订单id
* @return 下单成功返回true否则返回false
*/
@PostMapping("/prepay")
public JsonResult<?> prepay(@RequestParam(name = "orderId") String orderId) {
JSONObject r = wxPayService.prepay(orderId);
return r == null?JsonResult.failed("下单失败"):JsonResult.success(r);
}
/**
* 通过商户(骑行)订单号查询支付订单
*
* @param orderId 商户(骑行)订单号
* @return 支付订单信息
*/
@GetMapping("/queryOrder/{orderId}")
public JsonResult<?> queryOrderByOutTradeNo(@PathVariable String orderId) {
Transaction r = wxPayService.queryOrderByOutTradeNo(orderId);
return r == null?JsonResult.failed(String.format("骑行订单号{%s}查询支付订单失败", orderId)):JsonResult.success(r);
}
/**
* 通过商户(骑行)订单订单号查询支付订单状态
*
* @param orderId 微信支付订单号
* @return 订单信息支付状态
*/
@GetMapping("/queryOrderStatus/{orderId}")
public JsonResult<?> queryOrderStatusById(@PathVariable String orderId) {
HandleNotifyResult r = wxPayService.queryOrderStatusByOutTradeNo(orderId);
return JsonResult.success(r);
}
/**
* 退款申请
*
* @param refundDto 退款信息
* @return 退款成功返回true否则返回false
*/
@PostMapping("/refund")
public JsonResult<?> refund(@RequestBody EbikeRefundDto refundDto) {
String r = wxPayService.refund(refundDto.getOrderId(), refundDto.getReason());
return r == null?JsonResult.failed("退款失败"):JsonResult.success(r);
}
/**
* 通过退款单号查询退款信息
*
* @param refundId 商户(骑行)退款单号
* @return 退款信息
*/
@GetMapping("/queryRefund/{refundId}")
public JsonResult<?> refundQuery(@PathVariable String refundId) {
Refund r = wxPayService.queryRefundByOutNo(refundId);
return r == null?JsonResult.failed(String.format("退款单号{%s}查询退款失败", refundId)):JsonResult.success(r);
}
}