|
|
@ -1,9 +1,15 @@
|
|
|
|
package com.kiisoo.ic.activity.controller;
|
|
|
|
package com.kiisoo.ic.activity.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.kiisoo.ic.common.BaseController;
|
|
|
|
import com.kiisoo.ic.common.BaseController;
|
|
|
|
|
|
|
|
import com.kiisoo.ic.config.WxCpConfiguration;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
|
|
|
|
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
|
|
|
|
import me.chanjar.weixin.cp.api.impl.WxCpServiceOkHttpImpl;
|
|
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
@ -12,6 +18,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
@ -25,7 +32,8 @@ public class FileController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "上传文件")
|
|
|
|
@ApiOperation(value = "上传文件")
|
|
|
|
@PostMapping(value = "/upload")
|
|
|
|
@PostMapping(value = "/upload")
|
|
|
|
public Map<String, Object> upload(@RequestParam(value = "file", required = false) MultipartFile file) {
|
|
|
|
public Map<String, Object> upload(@RequestParam(value = "file", required = false) MultipartFile file) throws WxErrorException {
|
|
|
|
|
|
|
|
WxCpServiceOkHttpImpl serviceOkHttp = WxCpConfiguration.getCpService(WxCpConfiguration.APPLICATIONID);
|
|
|
|
if (file == null) return fail();
|
|
|
|
if (file == null) return fail();
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
if (fileName == null) return fail();
|
|
|
|
if (fileName == null) return fail();
|
|
|
@ -43,6 +51,11 @@ public class FileController extends BaseController {
|
|
|
|
log.error("上传出错", e);
|
|
|
|
log.error("上传出错", e);
|
|
|
|
return fail();
|
|
|
|
return fail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WxMediaUploadResult result = serviceOkHttp.getMediaService().upload("image", new File(uploadPath + fileName));
|
|
|
|
|
|
|
|
log.info("上传成功: {}", result);
|
|
|
|
|
|
|
|
Map<String, Object> ret = new HashMap<>();
|
|
|
|
|
|
|
|
ret.put("mediaId", result.getMediaId());
|
|
|
|
|
|
|
|
ret.put("localPath", "/upload/" + fileName);
|
|
|
|
return data("/upload/" + fileName);
|
|
|
|
return data("/upload/" + fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|