修复文件路径

This commit is contained in:
huangdeliang
2021-02-01 13:49:59 +08:00
parent e35fedef8b
commit c53d40777a
2 changed files with 8 additions and 17 deletions

View File

@ -136,9 +136,6 @@ public class SysWxSaleAccountController extends BaseController {
}
WxFileUploadResult result = WxTokenUtils.uploadImage(oriFilePath, oriFileName, accessToken);
if (StringUtils.isEmpty(result.getUrl())) {
return AjaxResult.error(result.getMediaId());
}
AjaxResult ajax = AjaxResult.success();
ajax.put("fileName", fileName);

View File

@ -45,20 +45,14 @@ public class WxTokenUtils {
}
}
public static WxFileUploadResult uploadImage(String filePath, String fileName, String accessToken) {
try {
String url = uploadMaterialUrl + "?access_token=" + accessToken + "&type=image";
HttpPostUtil post = new HttpPostUtil(url);
post.addParameter("media", new File(filePath));
String resultStr = post.send();
JSONObject obj = JSONObject.parseObject(resultStr);
WxFileUploadResult result = JSONObject.toJavaObject(obj, WxFileUploadResult.class);
return result;
} catch (Exception e) {
WxFileUploadResult result = new WxFileUploadResult();
result.setMediaId(e.getMessage());
return result;
}
public static WxFileUploadResult uploadImage(String filePath, String fileName, String accessToken) throws Exception {
String url = uploadMaterialUrl + "?access_token=" + accessToken + "&type=image";
HttpPostUtil post = new HttpPostUtil(url);
post.addParameter("media", new File(filePath));
String resultStr = post.send();
JSONObject obj = JSONObject.parseObject(resultStr);
WxFileUploadResult result = JSONObject.toJavaObject(obj, WxFileUploadResult.class);
return result;
}
/**