2025-10-22 10:13:57 +08:00
|
|
|
|
package com.cdzy.payment.controller;
|
|
|
|
|
|
|
2025-10-24 10:09:53 +08:00
|
|
|
|
import com.cdzy.payment.model.vo.EbikeWxHandleNotifyVo;
|
|
|
|
|
|
import com.cdzy.payment.service.EbikeWxPayService;
|
2025-10-30 09:21:18 +08:00
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
2025-10-22 10:13:57 +08:00
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 微信支付通知回调接口
|
|
|
|
|
|
* <br>通知接口不能鉴权
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author: yanglei
|
|
|
|
|
|
* @since: 2025-10-21 15:00
|
|
|
|
|
|
*/
|
|
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/wxPayment/notify")
|
|
|
|
|
|
public class EbikeWxPayNotifyController {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
2025-10-24 10:09:53 +08:00
|
|
|
|
private EbikeWxPayService wxPayService;
|
2025-10-22 10:13:57 +08:00
|
|
|
|
|
2025-10-30 09:21:18 +08:00
|
|
|
|
@Resource
|
|
|
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
|
2025-10-22 10:13:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 支付回调通知
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param request 支付回调请求
|
|
|
|
|
|
* @param response 支付回调响应
|
|
|
|
|
|
* @return 支付回调响应
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/pay")
|
|
|
|
|
|
public String payNotify(HttpServletRequest request, HttpServletResponse response) {
|
2025-10-24 10:09:53 +08:00
|
|
|
|
EbikeWxHandleNotifyVo r = wxPayService.handlePayNotify(request);
|
2025-10-22 10:13:57 +08:00
|
|
|
|
if (!r.isSuccess()) {
|
|
|
|
|
|
response.setStatus(500);
|
2025-10-30 09:21:18 +08:00
|
|
|
|
return createErrorResponse(r.getMessage());
|
2025-10-22 10:13:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
response.setStatus(200);
|
2025-10-30 09:21:18 +08:00
|
|
|
|
return createSuccessResponse();
|
2025-10-22 10:13:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 退款回调通知
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param request 退款回调请求
|
|
|
|
|
|
* @param response 退款回调响应
|
|
|
|
|
|
* @return 退款回调响应
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/refund")
|
|
|
|
|
|
public String refundNotify(HttpServletRequest request, HttpServletResponse response) {
|
2025-10-24 10:09:53 +08:00
|
|
|
|
EbikeWxHandleNotifyVo r = wxPayService.handleRefundNotify(request);
|
2025-10-22 10:13:57 +08:00
|
|
|
|
if (!r.isSuccess()) {
|
|
|
|
|
|
response.setStatus(500);
|
2025-10-30 09:21:18 +08:00
|
|
|
|
return createErrorResponse(r.getMessage());
|
2025-10-22 10:13:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
response.setStatus(200);
|
2025-10-30 09:21:18 +08:00
|
|
|
|
return createSuccessResponse();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 创建成功响应
|
|
|
|
|
|
*/
|
|
|
|
|
|
private String createSuccessResponse() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
ObjectNode jsonObject = objectMapper.createObjectNode();
|
|
|
|
|
|
jsonObject.put("code", "SUCCESS");
|
|
|
|
|
|
jsonObject.put("message", "OK");
|
|
|
|
|
|
return objectMapper.writeValueAsString(jsonObject);
|
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
|
// 如果JSON序列化失败,返回简单的成功响应
|
|
|
|
|
|
return "{\"code\":\"SUCCESS\",\"message\":\"OK\"}";
|
|
|
|
|
|
}
|
2025-10-22 10:13:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-30 09:21:18 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 创建错误响应
|
|
|
|
|
|
*/
|
|
|
|
|
|
private String createErrorResponse(String message) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
ObjectNode jsonObject = objectMapper.createObjectNode();
|
|
|
|
|
|
jsonObject.put("code", "SYSTEM_ERROR");
|
|
|
|
|
|
jsonObject.put("message", message);
|
|
|
|
|
|
return objectMapper.writeValueAsString(jsonObject);
|
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
|
// 如果JSON序列化失败,返回简单的错误响应
|
|
|
|
|
|
return "{\"code\":\"SYSTEM_ERROR\",\"message\":\"" + message + "\"}";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|