|
@ -246,7 +246,7 @@ public class WeixinBaseController extends BaseController {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public String fetchWxImages() {
|
|
|
public String Images() {
|
|
|
String photos = "";
|
|
|
try {
|
|
|
String images = request.getParameter("mediaIds");
|
|
@ -326,7 +326,84 @@ public class WeixinBaseController extends BaseController {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public String saveImageToDiskNoImageCompress(String mediaId) throws Exception {
|
|
|
// 文件保存的临时路径
|
|
|
String tempPath = SystemConf.getInstance().getImagePath() + File.separator;
|
|
|
// 拼接年月日路径
|
|
|
String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
|
|
|
// 重命名文件
|
|
|
String newFileName = DateUtil.dateToStr(new Date(), DateUtil.YYYYMMDDHHMMSS) + "_" + new Random().nextInt(1000) + ".png";
|
|
|
// 保存路径
|
|
|
File uploadFile = new File(tempPath + datePath + newFileName);
|
|
|
|
|
|
InputStream inputStream = null;
|
|
|
FileOutputStream fileOutputStream = null;
|
|
|
try {
|
|
|
if (!uploadFile.getParentFile().exists()) {
|
|
|
uploadFile.getParentFile().mkdirs();
|
|
|
}
|
|
|
inputStream = getInputStream(mediaId);//下载微信图片
|
|
|
byte[] data = new byte[1024];
|
|
|
int len = 0;
|
|
|
fileOutputStream = new FileOutputStream(uploadFile);
|
|
|
while ((len = inputStream.read(data)) != -1) {
|
|
|
fileOutputStream.write(data, 0, len);
|
|
|
}
|
|
|
// 生成缩略图
|
|
|
//ImageCompress.compress(uploadFile.getAbsolutePath(), uploadFile.getAbsolutePath() + "_small", 300, 300);
|
|
|
// 返回保存路径
|
|
|
return datePath + newFileName;
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
if (inputStream != null) {
|
|
|
try {
|
|
|
inputStream.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
if (fileOutputStream != null) {
|
|
|
try {
|
|
|
fileOutputStream.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
/**
|
|
|
* 获取微信服务器图片
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public String fetchWxImages() {
|
|
|
String photos = "";
|
|
|
try {
|
|
|
String images = request.getParameter("mediaIds");
|
|
|
if (StringUtils.isEmpty(images)) {
|
|
|
return photos;
|
|
|
}
|
|
|
String[] mediaIds = images.split(",");
|
|
|
for (String mediaId : mediaIds) {
|
|
|
if (StringUtils.isEmpty(mediaId)) {
|
|
|
continue;
|
|
|
}
|
|
|
String temp = saveImageToDisk(mediaId);
|
|
|
if (StringUtils.isNotEmpty(temp)) {
|
|
|
if (photos.length() == 0) {
|
|
|
photos = temp;
|
|
|
} else {
|
|
|
photos += "," + temp;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
error(e);
|
|
|
}
|
|
|
return photos;
|
|
|
}
|
|
|
/**
|
|
|
* 获取微信服务器语音
|
|
|
*
|