|
|
@@ -42,6 +42,7 @@ import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
import com.wechat.pay.java.service.refund.RefundService;
|
|
|
import com.wechat.pay.java.service.refund.model.*;
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
+import jakarta.servlet.ServletInputStream;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -52,10 +53,7 @@ import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -181,14 +179,22 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
LOGGER.info("微信支付回调{}:\n Request参数:\n signature:{},serial:{},nonce:{},timestamp:{},signatureType:{}", no, signature, serial, nonce, timestamp, signatureType);
|
|
|
|
|
|
// request中获取body
|
|
|
- BufferedReader br = request.getReader();
|
|
|
- String str;
|
|
|
- var requestBody = new StringBuilder();
|
|
|
- while ((str = br.readLine()) != null) {
|
|
|
- requestBody.append(str);
|
|
|
+// BufferedReader br = request.getReader();
|
|
|
+// String str;
|
|
|
+// var requestBody = new StringBuilder();
|
|
|
+// while ((str = br.readLine()) != null) {
|
|
|
+// requestBody.append(str);
|
|
|
+// }
|
|
|
+
|
|
|
+ ServletInputStream inputStream = request.getInputStream();
|
|
|
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ for (int lenght; (lenght = inputStream.read(buffer)) != -1; ) {
|
|
|
+ result.write(buffer, 0, lenght);
|
|
|
}
|
|
|
|
|
|
- LOGGER.info("微信支付回调{}:\nBody数据:\n{}", no, requestBody);
|
|
|
+
|
|
|
+ LOGGER.info("微信支付回调{}:\nBody数据:\n{}", no, result);
|
|
|
|
|
|
// 构造 RequestParam
|
|
|
RequestParam requestParam = new RequestParam.Builder()
|
|
|
@@ -196,7 +202,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
.nonce(nonce) // 随机数
|
|
|
.signature(signature)
|
|
|
.timestamp(timestamp)
|
|
|
- .body(requestBody.toString())
|
|
|
+ .body(result.toString())
|
|
|
.build();
|
|
|
LOGGER.info("微信支付回调{}:构造 RequestParam完毕", no);
|
|
|
|