77 lines
2.4 KiB
Java
77 lines
2.4 KiB
Java
package com.cdzy.payment.controller;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.cdzy.payment.model.vo.HandleNotifyVo;
|
|
import com.cdzy.payment.service.WxPayService;
|
|
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
|
|
private WxPayService wxPayService;
|
|
|
|
/**
|
|
* 支付回调通知
|
|
*
|
|
* @param request 支付回调请求
|
|
* @param response 支付回调响应
|
|
* @return 支付回调响应
|
|
*/
|
|
@PostMapping("/pay")
|
|
public String payNotify(HttpServletRequest request, HttpServletResponse response) {
|
|
HandleNotifyVo r = wxPayService.handlePayNotify(request);
|
|
if (!r.isSuccess()) {
|
|
response.setStatus(500);
|
|
JSONObject jsonObject = new JSONObject();
|
|
jsonObject.put("code", "SYSTEM_ERROR");
|
|
jsonObject.put("message", r.getMessage());
|
|
return jsonObject.toJSONString();
|
|
}
|
|
response.setStatus(200);
|
|
JSONObject jsonObject = new JSONObject();
|
|
jsonObject.put("code", "SUCCESS");
|
|
jsonObject.put("message", "OK");
|
|
return jsonObject.toJSONString();
|
|
}
|
|
|
|
/**
|
|
* 退款回调通知
|
|
*
|
|
* @param request 退款回调请求
|
|
* @param response 退款回调响应
|
|
* @return 退款回调响应
|
|
*/
|
|
@PostMapping("/refund")
|
|
public String refundNotify(HttpServletRequest request, HttpServletResponse response) {
|
|
HandleNotifyVo r = wxPayService.handleRefundNotify(request);
|
|
if (!r.isSuccess()) {
|
|
response.setStatus(500);
|
|
JSONObject jsonObject = new JSONObject();
|
|
jsonObject.put("code", "SYSTEM_ERROR");
|
|
jsonObject.put("message", r.getMessage());
|
|
return jsonObject.toJSONString();
|
|
}
|
|
response.setStatus(200);
|
|
JSONObject jsonObject = new JSONObject();
|
|
jsonObject.put("code", "SUCCESS");
|
|
jsonObject.put("message", "OK");
|
|
return jsonObject.toJSONString();
|
|
}
|
|
|
|
}
|