2025-04-27 17:50:45 +08:00
|
|
|
|
package com.cdzy.payment.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
|
import com.cdzy.common.model.JsonResult;
|
|
|
|
|
|
import com.cdzy.payment.model.dto.EbikeRefundDto;
|
2025-04-29 14:31:26 +08:00
|
|
|
|
import com.cdzy.payment.model.dto.HandleNotifyResult;
|
2025-04-27 17:50:45 +08:00
|
|
|
|
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;
|
2025-04-29 14:31:26 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2025-05-09 17:49:33 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2025-04-27 17:50:45 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 用户订单微信支付 控制层。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author dingchao
|
|
|
|
|
|
* @since 2025-04-24
|
|
|
|
|
|
*/
|
2025-04-29 14:31:26 +08:00
|
|
|
|
@Slf4j
|
2025-04-27 17:50:45 +08:00
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/wxPayment")
|
|
|
|
|
|
public class EbikeWxPaymentController {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private WxPayService wxPayService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 微信支付下单
|
|
|
|
|
|
*
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* @param orderId 骑行订单id
|
2025-04-27 17:50:45 +08:00
|
|
|
|
* @return 下单成功返回true,否则返回false
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/prepay")
|
2025-05-09 17:49:33 +08:00
|
|
|
|
public JsonResult<?> prepay(@RequestParam(name = "orderId") String orderId) {
|
|
|
|
|
|
JSONObject r = wxPayService.prepay(orderId);
|
2025-05-12 11:07:14 +08:00
|
|
|
|
return r.containsKey("error")?JsonResult.failed("下单失败: "+ r.getString("error")):JsonResult.success(r);
|
2025-04-27 17:50:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 通过商户(骑行)订单号查询支付订单
|
|
|
|
|
|
*
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* @param orderId 商户(骑行)订单号
|
2025-04-27 17:50:45 +08:00
|
|
|
|
* @return 支付订单信息
|
|
|
|
|
|
*/
|
2025-05-09 17:49:33 +08:00
|
|
|
|
@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);
|
2025-04-27 17:50:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-30 16:28:43 +08:00
|
|
|
|
/**
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* 通过商户(骑行)订单订单号查询支付订单状态
|
2025-04-30 16:28:43 +08:00
|
|
|
|
*
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* @param orderId 微信支付订单号
|
|
|
|
|
|
* @return 订单信息支付状态
|
2025-04-30 16:28:43 +08:00
|
|
|
|
*/
|
2025-05-09 17:49:33 +08:00
|
|
|
|
@GetMapping("/queryOrderStatus/{orderId}")
|
|
|
|
|
|
public JsonResult<?> queryOrderStatusById(@PathVariable String orderId) {
|
|
|
|
|
|
HandleNotifyResult r = wxPayService.queryOrderStatusByOutTradeNo(orderId);
|
2025-04-30 16:28:43 +08:00
|
|
|
|
return JsonResult.success(r);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-12 11:07:14 +08:00
|
|
|
|
// 拆分为两个接口,一个是退款申请(生成退款记录),一个是提交退款(调用微信退款接口)
|
2025-04-27 17:50:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 退款申请
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param refundDto 退款信息
|
|
|
|
|
|
* @return 退款成功返回true,否则返回false
|
|
|
|
|
|
*/
|
2025-05-12 11:07:14 +08:00
|
|
|
|
@PostMapping("/refundApply")
|
|
|
|
|
|
public JsonResult<?> refundApply(@RequestBody EbikeRefundDto refundDto) {
|
|
|
|
|
|
String r = wxPayService.refundApply(refundDto.getOrderId(), refundDto.getReason());
|
2025-04-27 17:50:45 +08:00
|
|
|
|
return r == null?JsonResult.failed("退款失败"):JsonResult.success(r);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-12 11:07:14 +08:00
|
|
|
|
/**
|
2025-05-12 18:10:11 +08:00
|
|
|
|
* 调用退款接口
|
2025-05-12 11:07:14 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @param orderId 订单id
|
|
|
|
|
|
* @return 退款成功返回true,否则返回false
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/refund")
|
|
|
|
|
|
public JsonResult<?> refund(@RequestParam(name = "orderId") String orderId) {
|
|
|
|
|
|
boolean r = wxPayService.refund(orderId);
|
|
|
|
|
|
return r?JsonResult.failed("退款失败"):JsonResult.success(r);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-27 17:50:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 通过退款单号查询退款信息
|
|
|
|
|
|
*
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* @param refundId 商户(骑行)退款单号
|
2025-04-27 17:50:45 +08:00
|
|
|
|
* @return 退款信息
|
|
|
|
|
|
*/
|
2025-05-09 17:49:33 +08:00
|
|
|
|
@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);
|
2025-04-27 17:50:45 +08:00
|
|
|
|
}
|
2025-04-29 14:31:26 +08:00
|
|
|
|
|
2025-04-27 17:50:45 +08:00
|
|
|
|
}
|