|
|
@@ -388,6 +388,11 @@ public class PayController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 微信批量提现
|
|
|
+ * @param openId
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
@RequestMapping("/batchTransfer")
|
|
|
@ApiOperation("微信批量提现")
|
|
|
@ResponseBody
|
|
|
@@ -444,36 +449,19 @@ public class PayController {
|
|
|
@RequestMapping("/refund")
|
|
|
@ResponseBody
|
|
|
public String refund(@RequestParam(required = false) String outRefundNo, @RequestParam(required = false) BigDecimal amount, @RequestParam(required = false) String transactionId, @RequestParam(required = false) String outTradeNo) {
|
|
|
- return rechargeService.refund(outRefundNo, transactionId, outTradeNo, amount);
|
|
|
+ try {
|
|
|
+ return rechargeService.refund(outRefundNo, transactionId, outTradeNo, amount);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("退款异常", e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // /**
|
|
|
-// * 退款通知
|
|
|
-// */
|
|
|
-// @RequestMapping(value = "/refundNotify", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
-// @ResponseBody
|
|
|
-// @ApiOperation("微信退款回调接口")
|
|
|
-// public String refundNotify(HttpServletRequest request) {
|
|
|
-// String xmlMsg = HttpKit.readData(request);
|
|
|
-// log.info("退款通知=" + xmlMsg);
|
|
|
-// Map<String, String> params = WxPayKit.xmlToMap(xmlMsg);
|
|
|
-// log.info("退款通知parms:{}",params);
|
|
|
-// String returnCode = params.get("event_type");
|
|
|
-// // 注意重复通知的情况,同一订单号可能收到多次通知,请注意一定先判断订单状态
|
|
|
-// if (returnCode.equals("REFUND.SUCCESS")) {
|
|
|
-// String reqInfo = params.get("resource");
|
|
|
-// String decryptData = WxPayKit.decryptData(reqInfo, WxPayApiConfigKit.getWxPayApiConfig().getPartnerKey());
|
|
|
-// log.info("退款通知解密后的数据=" + decryptData);
|
|
|
-//// refundVoucherService.
|
|
|
-// // 更新订单信息
|
|
|
-// // 发送通知等
|
|
|
-// Map<String, String> xml = new HashMap<String, String>(2);
|
|
|
-// xml.put("return_code", "SUCCESS");
|
|
|
-// xml.put("return_msg", "OK");
|
|
|
-// return WxPayKit.toXml(xml);
|
|
|
-// }
|
|
|
-// return null;
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * 微信退款回调接口
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
@ApiOperation("微信退款回调接口")
|
|
|
@RequestMapping(value = "/refundNotify", method = {org.springframework.web.bind.annotation.RequestMethod.POST, org.springframework.web.bind.annotation.RequestMethod.GET})
|
|
|
public void refundWechatCallback(HttpServletRequest request, HttpServletResponse response) {
|
|
|
@@ -518,4 +506,54 @@ public class PayController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据商户订单号查询微信支付订单
|
|
|
+ *
|
|
|
+ * @param outTradeNo 商户订单号
|
|
|
+ * @return R 订单详情
|
|
|
+ */
|
|
|
+ @GetMapping("/query/order/{outTradeNo}")
|
|
|
+ @ApiOperation("根据商户订单号查询微信支付订单")
|
|
|
+ public R<String> queryOrderByOutTradeNo(@PathVariable("outTradeNo") String outTradeNo) {
|
|
|
+ try {
|
|
|
+ log.info("查询微信支付订单,商户订单号:{}", outTradeNo);
|
|
|
+
|
|
|
+ // V3 API:根据商户订单号查询订单接口路径
|
|
|
+ // GET /v3/pay/transactions/out-trade-no/{out_trade_no}
|
|
|
+ String queryUrl = String.format("/v3/pay/transactions/out-trade-no/%s", outTradeNo);
|
|
|
+ // 调用微信支付V3接口查询订单
|
|
|
+ IJPayHttpResponse response = WxPayApi.v3(
|
|
|
+ RequestMethodEnum.GET,
|
|
|
+ WxDomainEnum.CHINA.toString(),
|
|
|
+ queryUrl,
|
|
|
+ wxPayProperties.getMchId(),
|
|
|
+ getSerialNumber(),
|
|
|
+ null,
|
|
|
+ wxPayProperties.getCertKeyPath(),
|
|
|
+ ""
|
|
|
+ );
|
|
|
+ log.info("查询订单响应状态:{},响应体:{}", response.getStatus(), response.getBody());
|
|
|
+ // 处理响应
|
|
|
+ if (response.getStatus() == SUCCESS) {
|
|
|
+ // 验证响应签名
|
|
|
+ boolean verifySignature = WxPayKit.verifySignature(response, wxPayProperties.getPlatFormPath());
|
|
|
+ log.info("响应签名验证结果:{}", verifySignature);
|
|
|
+
|
|
|
+ if (verifySignature) {
|
|
|
+ log.info("商户订单号 {} 查询成功,订单信息:{}", outTradeNo, response.getBody());
|
|
|
+ return R.ok(response.getBody());
|
|
|
+ } else {
|
|
|
+ log.error("商户订单号 {} 查询响应签名验证失败", outTradeNo);
|
|
|
+ return R.fail("查询订单响应签名验证失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("商户订单号 {} 查询失败,状态码:{},响应:{}", outTradeNo, response.getStatus(), response.getBody());
|
|
|
+ return R.fail("查询订单失败:" + response.getBody());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询微信支付订单异常,商户订单号:{},错误:{}", outTradeNo, e.getMessage(), e);
|
|
|
+ return R.fail("查询订单异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|