no message
This commit is contained in:
@ -3,6 +3,7 @@ package com.sczx.pay.controller;
|
||||
import com.sczx.pay.dto.PaymentRequest;
|
||||
import com.sczx.pay.dto.PaymentResponse;
|
||||
import com.sczx.pay.dto.RefundRequest;
|
||||
import com.sczx.pay.mapper.CompanyWechatConfigMapper;
|
||||
import com.sczx.pay.service.WechatPayService;
|
||||
import com.sczx.pay.utils.WXPayUtil;
|
||||
import org.slf4j.Logger;
|
||||
@ -27,6 +28,9 @@ public class PaymentController {
|
||||
@Autowired
|
||||
private WechatPayService wechatPayService;
|
||||
|
||||
@Autowired
|
||||
private CompanyWechatConfigMapper companyWechatConfigMapper;
|
||||
|
||||
/**
|
||||
* 小程序统一下单接口
|
||||
*/
|
||||
@ -165,7 +169,59 @@ public class PaymentController {
|
||||
return buildResponse("FAIL", "处理异常");
|
||||
}
|
||||
}
|
||||
@PostMapping("/refundNotify")
|
||||
public String refundNotify(@PathVariable HttpServletRequest request) {
|
||||
|
||||
try {
|
||||
// 读取微信退款回调数据
|
||||
StringBuilder sb = new StringBuilder();
|
||||
BufferedReader reader = request.getReader();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
|
||||
String xmlData = sb.toString();
|
||||
logger.info("收到微信退款通知, 数据: {}", xmlData);
|
||||
|
||||
// 解析XML数据
|
||||
Map<String, String> notifyMap = WXPayUtil.xmlToMap(xmlData);
|
||||
|
||||
Long companyId = companyWechatConfigMapper.getCompanyIdByMchId(notifyMap.get("mch_id"));
|
||||
|
||||
// 验证签名
|
||||
if (!wechatPayService.verifyNotifySign(companyId, notifyMap)) {
|
||||
logger.warn("微信退款通知签名验证失败,公司ID: {}", companyId);
|
||||
return buildResponse("FAIL", "签名失败");
|
||||
}
|
||||
|
||||
String returnCode = notifyMap.get("return_code");
|
||||
if (!"SUCCESS".equals(returnCode)) {
|
||||
logger.warn("微信退款通知返回失败,公司ID: {}: {}", companyId, notifyMap.get("return_msg"));
|
||||
return buildResponse("FAIL", "返回失败");
|
||||
}
|
||||
|
||||
// 处理退款通知的业务逻辑
|
||||
String outRefundNo = notifyMap.get("out_refund_no");
|
||||
String refundId = notifyMap.get("refund_id");
|
||||
String refundStatus = notifyMap.get("refund_status");
|
||||
|
||||
// 更新数据库中的退款状态
|
||||
boolean success = wechatPayService.processRefundNotify(companyId, notifyMap);
|
||||
if (success) {
|
||||
logger.info("退款处理完成,公司ID: {}, 退款单号: {}, 微信退款单号: {}, 状态: {}",
|
||||
companyId, outRefundNo, refundId, refundStatus);
|
||||
return buildResponse("SUCCESS", "OK");
|
||||
} else {
|
||||
logger.error("更新退款状态失败,公司ID: {}, 退款单号: {}", companyId, outRefundNo);
|
||||
return buildResponse("FAIL", "更新退款状态失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("处理微信退款通知异常", e);
|
||||
return buildResponse("FAIL", "处理异常");
|
||||
}
|
||||
}
|
||||
private String buildResponse(String returnCode, String returnMsg) {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("return_code", returnCode);
|
||||
|
||||
Reference in New Issue
Block a user