diff --git a/src/main/java/com/yn/bftl/thirdparty/modules/chinaums/controller/ChinaumsCallBackController.java b/src/main/java/com/yn/bftl/thirdparty/modules/chinaums/controller/ChinaumsCallBackController.java index c483e56..aef9ffb 100644 --- a/src/main/java/com/yn/bftl/thirdparty/modules/chinaums/controller/ChinaumsCallBackController.java +++ b/src/main/java/com/yn/bftl/thirdparty/modules/chinaums/controller/ChinaumsCallBackController.java @@ -19,7 +19,13 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; /** * @Author:Vance @@ -39,9 +45,36 @@ @ApiOperation(value = "回调") @RequestMapping(value = "/byx/result", method = RequestMethod.POST) - public ChinaumsCallBackVO callbackForByx(@RequestBody byte[] data) { + public ChinaumsCallBackVO callbackForByx(HttpServletRequest request) { log.info("comming"); - ByxMchApplicationsNoticeDTO byxMchApplicationsNoticeDTO = byteToObject(data); + String requestBody = ""; + try { + // 获取ServletInputStream + ServletInputStream inputStream = request.getInputStream(); + + // 创建一个BufferedReader来读取输入流,这里使用InputStreamReader将字节流转换为字符流 + // 假设请求体是UTF-8编码的,你可以根据实际情况调整编码 + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + + StringBuilder stringBuilder = new StringBuilder(); + String line; + + // 逐行读取输入流直到结束 + while ((line = reader.readLine()) != null) { + stringBuilder.append(line); + } + reader.close(); + inputStream.close(); + + // 此时stringBuilder中包含了请求体的全部内容 + requestBody = stringBuilder.toString(); + + } catch (IOException e) { + throw new RuntimeException(e); + } + + ByxMchApplicationsNoticeDTO byxMchApplicationsNoticeDTO = JSON.parseObject(requestBody, ByxMchApplicationsNoticeDTO.class); +// ByxMchApplicationsNoticeDTO byxMchApplicationsNoticeDTO = byteToObject(data); validateParams(byxMchApplicationsNoticeDTO); log.info("回调通知,数据:" + JSON.toJSONString(byxMchApplicationsNoticeDTO)); return chinaumsCallBackService.callbackForByx(byxMchApplicationsNoticeDTO);