提交 e85d4bd1 authored 作者: hzh's avatar hzh

支付修改

上级 e232d238
package org.dromara.common.pay.util;
import com.ijpay.core.kit.HttpKit;
import jakarta.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
/**
* @author hzh
* @date 2024-12-19
**/
public class CustomHttpKit extends HttpKit {
public static String readData(HttpServletRequest request) {
BufferedReader br = null;
try {
StringBuilder result = new StringBuilder();
br = request.getReader();
for (String line; (line = br.readLine()) != null; ) {
if (result.length() > 0) {
result.append("\n");
}
result.append(line);
}
return result.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
...@@ -4,12 +4,12 @@ import cn.hutool.http.ContentType; ...@@ -4,12 +4,12 @@ import cn.hutool.http.ContentType;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.ijpay.core.kit.HttpKit;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.R;
import org.dromara.common.pay.domain.JsapiNotifyModel; import org.dromara.common.pay.domain.JsapiNotifyModel;
import org.dromara.common.pay.util.CustomHttpKit;
import org.dromara.common.web.core.BaseController; import org.dromara.common.web.core.BaseController;
import org.dromara.order.service.IOrderPayService; import org.dromara.order.service.IOrderPayService;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -17,8 +17,9 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -17,8 +17,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -42,22 +43,23 @@ public class OrderController extends BaseController { ...@@ -42,22 +43,23 @@ public class OrderController extends BaseController {
/** /**
* 回调函数 * 回调函数
* *
* @param request request
* @param response response * @param response response
*/ */
@RequestMapping(value = "/v3/payNotify", method = {RequestMethod.POST, RequestMethod.GET}) @RequestMapping(value = "/v3/payNotify", method = {RequestMethod.POST, RequestMethod.GET})
public void payNotify(HttpServletRequest request, HttpServletResponse response) { public void payNotify(HttpServletResponse response) {
Map<String, String> map = new HashMap<>(12); Map<String, String> map = new HashMap<>(12);
try { try {
log.info("微信回调开始"); log.info("微信回调开始");
jakarta.servlet.http.HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder() ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder()
.put("timestamp", request.getHeader("Wechatpay-Timestamp")) .put("timestamp", request.getHeader("Wechatpay-Timestamp"))
.put("nonce", request.getHeader("Wechatpay-Nonce")) .put("nonce", request.getHeader("Wechatpay-Nonce"))
.put("serialNo", request.getHeader("Wechatpay-Serial")) .put("serialNo", request.getHeader("Wechatpay-Serial"))
.put("signature", request.getHeader("Wechatpay-Signature")) .put("signature", request.getHeader("Wechatpay-Signature"))
.put("result", HttpKit.readData(request)); .put("result", CustomHttpKit.readData(request));
boolean result = orderPayService.notify(JSON.toJSONString(builder)); boolean result = orderPayService.notify(JSON.toJSONString(builder));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论