This commit is contained in:
wucongxing8150 2025-07-16 09:21:42 +08:00
parent 075b7a58e9
commit afc851ee65

View File

@ -365,33 +365,33 @@ public class ExpertController {
@ApiOperation(value = "上传图片", notes = "仅在上传执业医师资格证使用") @ApiOperation(value = "上传图片", notes = "仅在上传执业医师资格证使用")
@PostMapping("/user/uoloadImg") @PostMapping("/user/uoloadImg")
public ResponseDTO<String> uoloadImg(@RequestParam("file") MultipartFile file) throws IOException { public ResponseDTO<String> uoloadImg(@RequestParam("file") MultipartFile file) throws IOException {
HashMap<String, Object> params = new HashMap<>(); // HashMap<String, Object> params = new HashMap<>();
//文件上传只需将参数中的键指定默认file值设为文件对象即可对于使用者来说文件上传与普通表单提交并无区别 // //文件上传只需将参数中的键指定默认file值设为文件对象即可对于使用者来说文件上传与普通表单提交并无区别
// 创建一个临时文件 // // 创建一个临时文件
File tempFile = File.createTempFile("temp", file.getOriginalFilename()); // File tempFile = File.createTempFile("temp", file.getOriginalFilename());
// MultipartFile 的内容写入到临时文件中 // // MultipartFile 的内容写入到临时文件中
try (InputStream inputStream = file.getInputStream(); // try (InputStream inputStream = file.getInputStream();
OutputStream outputStream = new FileOutputStream(tempFile)) { // OutputStream outputStream = new FileOutputStream(tempFile)) {
//
byte[] buffer = new byte[1024]; // byte[] buffer = new byte[1024];
int bytesRead; // int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) { // while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead); // outputStream.write(buffer, 0, bytesRead);
} // }
params.put("platform", IGANDAN_WX_PLATFORM); // params.put("platform", IGANDAN_WX_PLATFORM);
params.put("timestamp", System.currentTimeMillis()/1000); // params.put("timestamp", System.currentTimeMillis()/1000);
String signature = Sha256Util.getSign(params, IGANDAN_WX_token); // String signature = Sha256Util.getSign(params, IGANDAN_WX_token);
params.put("signature", signature); // params.put("signature", signature);
params.put("file", tempFile); // params.put("file", tempFile);
String result= HttpUtil.post(IGANDAN_WX_HOST + UOLOADIMGV2_URL, params); // String result= HttpUtil.post(IGANDAN_WX_HOST + UOLOADIMGV2_URL, params);
ResponseDTO responseDTO = JSON.parseObject(result, ResponseDTO.class); // ResponseDTO responseDTO = JSON.parseObject(result, ResponseDTO.class);
if(responseDTO.getCode() == 200){ // if(responseDTO.getCode() == 200){
String data = (String) responseDTO.getData(); // String data = (String) responseDTO.getData();
return ResponseDTO.app_ok(IGANDAN_DOC_HOST + data); // return ResponseDTO.app_ok(IGANDAN_DOC_HOST + data);
} // }
}finally { // }finally {
tempFile.deleteOnExit(); // tempFile.deleteOnExit();
} // }
return ResponseDTO.userErrorParam(); return ResponseDTO.userErrorParam();
} }