Commit c2806b44 by 墨竹

fix:代码公用

parent 61a23544
......@@ -19,11 +19,11 @@ import com.gic.haoban.manage.service.service.MaterialCategoryService;
import com.gic.haoban.manage.service.service.MaterialService;
import com.gic.haoban.manage.service.service.MiniprogramSettingService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.util.CommonUtil;
import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
......@@ -31,8 +31,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -134,7 +132,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
if (type == 3) {
String imgUrl = materialDTO.getImgUrl();
logger.info("【上传图片】imgUrl={}", imgUrl);
JSONResponse response = qywxSuiteApiService.uploadImage(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(imgUrl));
JSONResponse response = qywxSuiteApiService.uploadImage(enterprise.getCorpid(), config.getWxSuiteid(), CommonUtil.getFileByte(imgUrl));
logger.info("【上传图片返回】response={}", JSON.toJSONString(response));
String wxImgUrl = response.getResult() == null ? "" : response.getResult().toString();
materialDTO.setWxImgUrl(wxImgUrl);
......@@ -142,7 +140,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
if (fileType != null) {
String[] arr = url.split("/");
int count = arr.length;
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode());
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), CommonUtil.getFileByte(url), arr[count - 1], fileType.getCode());
if (jp.getErrorCode() == 0) {
materialDTO.setWxLastUploadTime(new Date());
materialDTO.setMediaId(jp.getResult().toString());
......@@ -198,7 +196,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
String imgUrl = materialDTO.getImgUrl();
String oldImgUrl = materialDTO.getImgUrl();
if (!imgUrl.equals(oldImgUrl)) {
JSONResponse response = qywxSuiteApiService.uploadImage(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(imgUrl));
JSONResponse response = qywxSuiteApiService.uploadImage(enterprise.getCorpid(), config.getWxSuiteid(), CommonUtil.getFileByte(imgUrl));
String wxImgUrl = response.getResult() == null ? "" : response.getResult().toString();
materialDTO.setWxImgUrl(wxImgUrl);
}
......@@ -206,7 +204,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
if (fileType != null && !url.equals(oldUrl)) {
String[] arr = url.split("/");
int count = arr.length;
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode());
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), CommonUtil.getFileByte(url), arr[count - 1], fileType.getCode());
if (jp.getErrorCode() == 0) {
materialDTO.setWxLastUploadTime(new Date());
materialDTO.setMediaId(jp.getResult().toString());
......@@ -254,7 +252,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
}
String[] arr = url.split("/");
int count = arr.length;
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode());
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), CommonUtil.getFileByte(url), arr[count - 1], fileType.getCode());
if (jp.getErrorCode() == 0) {
old.setWxLastUploadTime(new Date());
old.setMediaId(jp.getResult().toString());
......@@ -308,18 +306,6 @@ public class MaterialApiServiceImpl implements MaterialApiService {
return PageUtil.changePageHelperToCurrentPage(page, MaterialDTO.class);
}
private static byte[] getFileByte(String url) {
try {
InputStream in = new URL(url).openStream();
byte[] data = IOUtils.toByteArray(in);
return data;
} catch (Exception e) {
logger.info("【异常】" + e.getMessage(), e);
}
return null;
}
@Override
public List<MaterialCategoryDTO> listByParentCategory(String categoryId) {
return materialCategoryService.listByParentCategory(categoryId);
......@@ -439,7 +425,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
// 先写死为图片类型, 以后有别的再扩展
QywxMediaTypeEnum fileType = QywxMediaTypeEnum.IMAGE;
int count = arr.length;
JSONResponse jp = qywxSuiteApiService.uploadMedia(corPid, config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode());
JSONResponse jp = qywxSuiteApiService.uploadMedia(corPid, config.getWxSuiteid(), CommonUtil.getFileByte(url), arr[count - 1], fileType.getCode());
if (jp.getErrorCode() == 0) {
return jp.getResult().toString();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment