修复文件路径
This commit is contained in:
@ -21,6 +21,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -135,11 +136,15 @@ public class SysWxSaleAccountController extends BaseController {
|
|||||||
redisCache.setCacheObject(WxTokenUtils.KEY_ACCESS_TOKEN, wxAccessToken.getAccessToken(), wxAccessToken.getExpiresIn(), TimeUnit.SECONDS);
|
redisCache.setCacheObject(WxTokenUtils.KEY_ACCESS_TOKEN, wxAccessToken.getAccessToken(), wxAccessToken.getExpiresIn(), TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
WxFileUploadResult result = WxTokenUtils.uploadImage(oriFilePath, oriFileName, accessToken);
|
File uploadFile = new File(oriFilePath);
|
||||||
|
|
||||||
|
WxFileUploadResult result = WxTokenUtils.uploadImage(uploadFile, oriFileName, accessToken);
|
||||||
|
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
ajax.put("fileName", fileName);
|
ajax.put("fileName", fileName);
|
||||||
ajax.put("wxInfo", result);
|
ajax.put("wxInfo", result);
|
||||||
|
ajax.put("file", uploadFile);
|
||||||
|
ajax.put("accessToken", accessToken);
|
||||||
ajax.put("url", url);
|
ajax.put("url", url);
|
||||||
return ajax;
|
return ajax;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -45,10 +45,10 @@ public class WxTokenUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WxFileUploadResult uploadImage(String filePath, String fileName, String accessToken) throws Exception {
|
public static WxFileUploadResult uploadImage(File file, String fileName, String accessToken) throws Exception {
|
||||||
String url = uploadMaterialUrl + "?access_token=" + accessToken + "&type=image";
|
String url = uploadMaterialUrl + "?access_token=" + accessToken + "&type=image";
|
||||||
HttpPostUtil post = new HttpPostUtil(url);
|
HttpPostUtil post = new HttpPostUtil(url);
|
||||||
post.addParameter("media", new File(filePath));
|
post.addParameter("media", file);
|
||||||
String resultStr = post.send();
|
String resultStr = post.send();
|
||||||
JSONObject obj = JSONObject.parseObject(resultStr);
|
JSONObject obj = JSONObject.parseObject(resultStr);
|
||||||
WxFileUploadResult result = JSONObject.toJavaObject(obj, WxFileUploadResult.class);
|
WxFileUploadResult result = JSONObject.toJavaObject(obj, WxFileUploadResult.class);
|
||||||
|
Reference in New Issue
Block a user