|
@ -7,13 +7,14 @@ import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
import com.yihu.jw.im.dao.ConsultDao;
|
|
import com.yihu.jw.im.dao.ConsultDao;
|
|
import com.yihu.jw.im.dao.ConsultTeamDao;
|
|
import com.yihu.jw.im.dao.ConsultTeamDao;
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
|
|
import com.yihu.jw.im.util.ImageCompress;
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
import com.yihu.jw.util.common.FileUtil;
|
|
import com.yihu.jw.util.common.FileUtil;
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
import org.apache.http.NameValuePair;
|
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
|
|
|
import com.yihu.jw.wechat.service.WxAccessTokenService;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
@ -51,6 +52,29 @@ public class ImService {
|
|
@Autowired
|
|
@Autowired
|
|
protected HttpServletRequest request;
|
|
protected HttpServletRequest request;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public WxAccessTokenService wxAccessTokenService;
|
|
|
|
|
|
|
|
@Value("${im.data_base_name}")
|
|
|
|
private String data_base_name;
|
|
|
|
|
|
|
|
@Value("${FileTempPath.upload_temp_path}")
|
|
|
|
private String upload_temp_path;
|
|
|
|
|
|
|
|
@Value("${FileTempPath.image_path}")
|
|
|
|
private String image_path;
|
|
|
|
|
|
|
|
@Value("${FileTempPath.voice_path}")
|
|
|
|
private String voice_path;
|
|
|
|
|
|
|
|
@Value("${FileTempPath.chat_file_path}")
|
|
|
|
private String chat_file_path;
|
|
|
|
|
|
|
|
@Value("${fastDFS.fastdfs_file_url}")
|
|
|
|
private String fastdfs_file_url;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询患者所有的咨询记录
|
|
* 查询患者所有的咨询记录
|
|
* @param patient 患者标识
|
|
* @param patient 患者标识
|
|
@ -160,9 +184,11 @@ public class ImService {
|
|
* @param content 消息内容
|
|
* @param content 消息内容
|
|
* @param type 消息类型
|
|
* @param type 消息类型
|
|
* @param times 次数
|
|
* @param times 次数
|
|
|
|
* @param patientcode 发送的居民CODE
|
|
|
|
* @param wechat_appid 微信公众号appid
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public List<String> append(String consult, String content, Integer type, Integer times,String patientcode) throws Exception {
|
|
|
|
|
|
public List<String> append(String consult, String content, Integer type, Integer times,String patientcode,String wechat_appid) throws Exception {
|
|
List<ConsultTeamLogDo> logs = new ArrayList<ConsultTeamLogDo>();
|
|
List<ConsultTeamLogDo> logs = new ArrayList<ConsultTeamLogDo>();
|
|
ConsultTeamDo consultModel = consultTeamDao.findByConsult(consult);
|
|
ConsultTeamDo consultModel = consultTeamDao.findByConsult(consult);
|
|
|
|
|
|
@ -176,11 +202,11 @@ public class ImService {
|
|
|
|
|
|
String[] arr = null;
|
|
String[] arr = null;
|
|
if (type == 3) {
|
|
if (type == 3) {
|
|
String path = fetchWxVoices();
|
|
|
|
|
|
String path = fetchWxVoices(wechat_appid);
|
|
JSONObject obj = new JSONObject();
|
|
JSONObject obj = new JSONObject();
|
|
// 将临时语音拷贝到正式存储路径下
|
|
// 将临时语音拷贝到正式存储路径下
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(path)) {
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(path)) {
|
|
content = CommonUtil.copyTempVoice(path);
|
|
|
|
|
|
content = fileUtil.copyTempVoice(path,fastdfs_file_url);
|
|
obj.put("path", content);
|
|
obj.put("path", content);
|
|
obj.put("times", times);
|
|
obj.put("times", times);
|
|
content = obj.toString();
|
|
content = obj.toString();
|
|
@ -194,13 +220,14 @@ public class ImService {
|
|
logs.add(log);
|
|
logs.add(log);
|
|
} else if (type == 2) {
|
|
} else if (type == 2) {
|
|
// 图片消息
|
|
// 图片消息
|
|
content = fetchWxImages();
|
|
|
|
|
|
content = fetchWxImages(wechat_appid);
|
|
// 将临时图片拷贝到正式存储路径下
|
|
// 将临时图片拷贝到正式存储路径下
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(content)) {
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(content)) {
|
|
content = CommonUtil.copyTempImage(content);
|
|
|
|
|
|
content = fileUtil.copyTempImage(content,upload_temp_path);
|
|
}
|
|
}
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(content)) {
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(content)) {
|
|
return error(-1, "图片上传失败!");
|
|
|
|
|
|
throw new Exception("图片上传失败!");
|
|
|
|
// return error(-1, "图片上传失败!");
|
|
}
|
|
}
|
|
String[] images = content.split(",");
|
|
String[] images = content.split(",");
|
|
for (String image : images) {
|
|
for (String image : images) {
|
|
@ -228,118 +255,90 @@ public class ImService {
|
|
int i = 0;
|
|
int i = 0;
|
|
List<String> failed = new ArrayList<>();
|
|
List<String> failed = new ArrayList<>();
|
|
|
|
|
|
String agent = getUID()==getRepUID()?null:getUID();
|
|
|
|
for (ConsultTeamLogDo log : logs) {
|
|
for (ConsultTeamLogDo log : logs) {
|
|
// String response = ImUtill.sendTopicIM(getUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent());
|
|
// String response = ImUtill.sendTopicIM(getUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent());
|
|
String response = ImUtill.sendTopicIM(getRepUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent(),agent);
|
|
|
|
|
|
String response = imUtil.sendTopicIM(patientcode, patient.getName(), consult, String.valueOf(log.getType()), log.getContent(),null);
|
|
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(response)) {
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(response)) {
|
|
JSONObject resObj = new JSONObject(response);
|
|
JSONObject resObj = new JSONObject(response);
|
|
if (resObj.getInt("status") == -1) {
|
|
if (resObj.getInt("status") == -1) {
|
|
return invalidUserException(new RuntimeException(resObj.getString("message")), -1, "追问失败!" + resObj.getString("message"));
|
|
|
|
|
|
throw new Exception("追问失败!" + resObj.getString("message"));
|
|
|
|
// return invalidUserException(new RuntimeException(resObj.getString("message")), -1, "追问失败!" + resObj.getString("message"));
|
|
}
|
|
}
|
|
failed.add(String.valueOf(resObj.get("data")));
|
|
failed.add(String.valueOf(resObj.get("data")));
|
|
try {
|
|
|
|
/*if(messageService.getMessageNoticeSettingByMessageType(consultModel.getDoctor(),"1",MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue())){
|
|
|
|
// 新增发送医生助手模板消息 v1.4.0 by wujunjie
|
|
|
|
Doctor doctor = doctorDao.findByCode(consultModel.getDoctor());
|
|
|
|
String doctorOpenID = doctor.getOpenid();
|
|
|
|
if (StringUtils.isNotEmpty(doctorOpenID)) {
|
|
|
|
String title = "";
|
|
|
|
Consult consultSingle = consultDao.findByCode(log.getConsult());
|
|
|
|
if (consultSingle!=null){
|
|
|
|
Integer singleType = consultSingle .getType();
|
|
|
|
if (singleType != null && singleType ==8 ){
|
|
|
|
title = consultSingle.getTitle();
|
|
|
|
}else if(singleType != null && singleType !=8 ){
|
|
|
|
title = consultSingle.getSymptoms();
|
|
|
|
}
|
|
|
|
String repContent = parseContentType(type+"",content);
|
|
|
|
String first = "居民" +patient.getName()+"的健康咨询有新的回复。";
|
|
|
|
String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
|
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
|
params.add(new BasicNameValuePair("type", "8"));
|
|
|
|
params.add(new BasicNameValuePair("openId", doctorOpenID));
|
|
|
|
params.add(new BasicNameValuePair("url", targetUrl));
|
|
|
|
params.add(new BasicNameValuePair("first", first));
|
|
|
|
params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
|
|
|
|
String keywords = title + "," + repContent +","+ doctor.getName();
|
|
|
|
params.add(new BasicNameValuePair("keywords", keywords));
|
|
|
|
|
|
|
|
httpClientUtil.post(url, params, "UTF-8");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
String sql = "";
|
|
|
|
if (consultModel.getType() == 2){
|
|
|
|
//家庭咨询
|
|
|
|
sql = "SELECT t.participant_id FROM " + im +
|
|
|
|
".participants t where t.session_id = '" +
|
|
|
|
patient.getId() + "_" + consultModel.getTeam() + "_" + consultModel.getType() +
|
|
|
|
"' and t.participant_role = 0";
|
|
|
|
}else if (consultModel.getType() == 8 || consultModel.getType() == 9 || consultModel.getType() == 11){
|
|
|
|
//8-续方咨询 9-在线复诊咨询 11-上门预约服务
|
|
|
|
sql = "SELECT t.participant_id FROM " + im +
|
|
|
|
".participants t where t.session_id = '" +
|
|
|
|
patient.getId() + "_" + consultModel.getConsult() + "_" + consultModel.getType() +
|
|
|
|
"' and t.participant_role = 0";
|
|
|
|
}
|
|
|
|
|
|
// try {
|
|
|
|
//
|
|
|
|
// String sql = "";
|
|
|
|
// if (consultModel.getType() == 2){
|
|
|
|
// //家庭咨询
|
|
|
|
// sql = "SELECT t.participant_id FROM " + data_base_name +
|
|
|
|
// ".participants t where t.session_id = '" +
|
|
|
|
// patient.getId() + "_" + consultModel.getTeam() + "_" + consultModel.getType() +
|
|
|
|
// "' and t.participant_role = 0";
|
|
|
|
// }else if (consultModel.getType() == 8 || consultModel.getType() == 9 || consultModel.getType() == 11){
|
|
|
|
// //8-续方咨询 9-在线复诊咨询 11-上门预约服务
|
|
|
|
// sql = "SELECT t.participant_id FROM " + data_base_name +
|
|
|
|
// ".participants t where t.session_id = '" +
|
|
|
|
// patient.getId() + "_" + consultModel.getConsult() + "_" + consultModel.getType() +
|
|
|
|
// "' and t.participant_role = 0";
|
|
|
|
// }
|
|
|
|
|
|
if(org.apache.commons.lang3.StringUtils.isEmpty(sql)){
|
|
|
|
return write(-1, "追问失败!", "data", "不存在该类型!【type】:" + type);
|
|
|
|
}
|
|
|
|
List<Map<String, Object>> participants = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
|
|
for (Map<String, Object> participant : participants) {
|
|
|
|
|
|
// if(org.apache.commons.lang3.StringUtils.isEmpty(sql)){
|
|
|
|
// throw new Exception("追问失败!不存在该类型!【type】:" + type);
|
|
|
|
// return write(-1, "追问失败!", "data", "不存在该类型!【type】:" + type);
|
|
|
|
// }
|
|
|
|
// List<Map<String, Object>> participants = jdbcTemplate.queryForList(sql);
|
|
|
|
//
|
|
|
|
// for (Map<String, Object> participant : participants) {
|
|
// //有居民、健管、全科
|
|
// //有居民、健管、全科
|
|
String doctorCode = participant.get("participant_id").toString();
|
|
|
|
if (doctorCode.equals(patient.getCode())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
// String doctorCode = participant.get("participant_id").toString();
|
|
|
|
// if (doctorCode.equals(patient.getCode())) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
//健管
|
|
//健管
|
|
Boolean flag = messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue());
|
|
|
|
|
|
// Boolean flag = messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue());
|
|
//全科
|
|
//全科
|
|
// Boolean flag2 = !messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.familyTopicSwitch.getValue());
|
|
// Boolean flag2 = !messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.familyTopicSwitch.getValue());
|
|
if (flag) {
|
|
|
|
// 新增发送医生助手模板消息 v1.4.0 by wujunjie
|
|
|
|
Doctor doctor = doctorDao.findByCode(doctorCode);
|
|
|
|
String doctorOpenID = doctor.getOpenid();
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(doctorOpenID)) {
|
|
|
|
String title = "";
|
|
|
|
Consult consultSingle = consultDao.findByCode(log.getConsult());
|
|
|
|
if (consultSingle != null) {
|
|
|
|
Integer singleType = consultSingle.getType();
|
|
|
|
if (singleType != null && singleType == 8) {
|
|
|
|
title = consultSingle.getTitle();
|
|
|
|
} else if (singleType != null && singleType != 8) {
|
|
|
|
title = consultSingle.getSymptoms();
|
|
|
|
}
|
|
|
|
String repContent = parseContentType(type + "", content);
|
|
|
|
String first = "居民" + patient.getName() + "的咨询有新的回复。";
|
|
|
|
String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
|
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
|
params.add(new BasicNameValuePair("type", "8"));
|
|
|
|
params.add(new BasicNameValuePair("openId", doctorOpenID));
|
|
|
|
params.add(new BasicNameValuePair("url", targetUrl));
|
|
|
|
params.add(new BasicNameValuePair("first", first));
|
|
|
|
params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
|
|
|
|
String keywords = title + "," + repContent + "," + doctor.getName();
|
|
|
|
params.add(new BasicNameValuePair("keywords", keywords));
|
|
|
|
|
|
|
|
httpClientUtil.post(url, params, "UTF-8");
|
|
|
|
System.out.println("发送对象:"+doctorCode);
|
|
|
|
System.out.println("发送对象名字:"+doctor.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
// if (flag) {
|
|
|
|
// // 新增发送医生助手模板消息 v1.4.0 by wujunjie
|
|
|
|
// Doctor doctor = doctorDao.findByCode(doctorCode);
|
|
|
|
// String doctorOpenID = doctor.getOpenid();
|
|
|
|
// if (org.apache.commons.lang3.StringUtils.isNotEmpty(doctorOpenID)) {
|
|
|
|
// String title = "";
|
|
|
|
// Consult consultSingle = consultDao.findByCode(log.getConsult());
|
|
|
|
// if (consultSingle != null) {
|
|
|
|
// Integer singleType = consultSingle.getType();
|
|
|
|
// if (singleType != null && singleType == 8) {
|
|
|
|
// title = consultSingle.getTitle();
|
|
|
|
// } else if (singleType != null && singleType != 8) {
|
|
|
|
// title = consultSingle.getSymptoms();
|
|
|
|
// }
|
|
|
|
// String repContent = parseContentType(type + "", content);
|
|
|
|
// String first = "居民" + patient.getName() + "的咨询有新的回复。";
|
|
|
|
// String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
|
|
|
|
// List<NameValuePair> params = new ArrayList<>();
|
|
|
|
// params.add(new BasicNameValuePair("type", "8"));
|
|
|
|
// params.add(new BasicNameValuePair("openId", doctorOpenID));
|
|
|
|
// params.add(new BasicNameValuePair("url", targetUrl));
|
|
|
|
// params.add(new BasicNameValuePair("first", first));
|
|
|
|
// params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
|
|
|
|
// String keywords = title + "," + repContent + "," + doctor.getName();
|
|
|
|
// params.add(new BasicNameValuePair("keywords", keywords));
|
|
|
|
//
|
|
|
|
// httpClientUtil.post(url, params, "UTF-8");
|
|
|
|
// System.out.println("发送对象:"+doctorCode);
|
|
|
|
// System.out.println("发送对象名字:"+doctor.getName());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// } catch (Exception e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return failed;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@ -347,7 +346,7 @@ public class ImService {
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public String fetchWxVoices() {
|
|
|
|
|
|
public String fetchWxVoices(String wecha_appid) {
|
|
String voiceIds = "";
|
|
String voiceIds = "";
|
|
try {
|
|
try {
|
|
String voices = request.getParameter("voices");
|
|
String voices = request.getParameter("voices");
|
|
@ -359,7 +358,7 @@ public class ImService {
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(mediaId)) {
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(mediaId)) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
String temp = saveVoiceToDisk(mediaId);
|
|
|
|
|
|
String temp = saveVoiceToDisk(mediaId,wecha_appid);
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(temp)) {
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(temp)) {
|
|
if (voiceIds.length() == 0) {
|
|
if (voiceIds.length() == 0) {
|
|
voiceIds = temp;
|
|
voiceIds = temp;
|
|
@ -369,7 +368,8 @@ public class ImService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
error(e);
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
// error(e);
|
|
}
|
|
}
|
|
return voiceIds;
|
|
return voiceIds;
|
|
}
|
|
}
|
|
@ -380,9 +380,9 @@ public class ImService {
|
|
* @param mediaId 文件的id
|
|
* @param mediaId 文件的id
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public String saveVoiceToDisk(String mediaId) throws Exception {
|
|
|
|
|
|
public String saveVoiceToDisk(String mediaId,String wechat_appid) throws Exception {
|
|
// 文件保存的临时路径
|
|
// 文件保存的临时路径
|
|
String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
|
|
|
|
|
|
String tempPath = upload_temp_path + File.separator;
|
|
// 拼接年月日路径
|
|
// 拼接年月日路径
|
|
String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
|
|
String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
|
|
// 重命名文件
|
|
// 重命名文件
|
|
@ -398,7 +398,7 @@ public class ImService {
|
|
if (!uploadFile.getParentFile().exists()) {
|
|
if (!uploadFile.getParentFile().exists()) {
|
|
uploadFile.getParentFile().mkdirs();
|
|
uploadFile.getParentFile().mkdirs();
|
|
}
|
|
}
|
|
inputStream = getInputStream(mediaId);
|
|
|
|
|
|
inputStream = getInputStream(mediaId,wechat_appid);
|
|
byte[] data = new byte[1024];
|
|
byte[] data = new byte[1024];
|
|
int len = 0;
|
|
int len = 0;
|
|
fileOutputStream = new FileOutputStream(uploadFile);
|
|
fileOutputStream = new FileOutputStream(uploadFile);
|
|
@ -436,8 +436,8 @@ public class ImService {
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public InputStream getInputStream(String mediaId) {
|
|
|
|
String accessToken = getAccessToken();
|
|
|
|
|
|
public InputStream getInputStream(String mediaId,String wechat_appid) {
|
|
|
|
String accessToken = wxAccessTokenService.getWxAccessTokenById(wechat_appid).getAccessToken();
|
|
InputStream is = null;
|
|
InputStream is = null;
|
|
String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + accessToken + "&media_id=" + mediaId;
|
|
String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + accessToken + "&media_id=" + mediaId;
|
|
try {
|
|
try {
|
|
@ -458,4 +458,92 @@ public class ImService {
|
|
return is;
|
|
return is;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取微信服务器图片
|
|
|
|
* @param wechat_appid 微信公众号appid
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String fetchWxImages(String wechat_appid) {
|
|
|
|
String photos = "";
|
|
|
|
try {
|
|
|
|
String images = request.getParameter("mediaIds");
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(images)) {
|
|
|
|
return photos;
|
|
|
|
}
|
|
|
|
String[] mediaIds = images.split(",");
|
|
|
|
for (String mediaId : mediaIds) {
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isEmpty(mediaId)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String temp = saveImageToDisk(mediaId,wechat_appid);
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(temp)) {
|
|
|
|
if (photos.length() == 0) {
|
|
|
|
photos = temp;
|
|
|
|
} else {
|
|
|
|
photos += "," + temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
// error(e);
|
|
|
|
}
|
|
|
|
return photos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取下载图片信息(jpg)
|
|
|
|
*
|
|
|
|
* @param mediaId 文件的id
|
|
|
|
* @param wechat_appid 微信appid
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public String saveImageToDisk(String mediaId,String wechat_appid) throws Exception {
|
|
|
|
// 文件保存的临时路径
|
|
|
|
String tempPath = upload_temp_path + 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,wechat_appid);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|