|
@ -663,14 +663,64 @@ public class ImService {
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public InputStream getInputStream(String mediaId,String wechat_appid) {
|
|
|
|
|
|
public InputStream getInputStream(String mediaId,String wechat_appid) throws Exception {
|
|
String accessToken = "";
|
|
String accessToken = "";
|
|
//中山医院互联网医院
|
|
|
|
if("xm_zsyy_wx".equals(wechat_appid)){
|
|
|
|
accessToken = entranceService.getAccessToken("100033");
|
|
|
|
}else{
|
|
|
|
accessToken = wxAccessTokenService.getWxAccessTokenById(wechat_appid).getAccessToken();
|
|
|
|
|
|
// //中山医院互联网医院
|
|
|
|
// if("xm_zsyy_wx".equals(wechat_appid)){
|
|
|
|
// accessToken = entranceService.getAccessToken("100033");
|
|
|
|
// }else{
|
|
|
|
// accessToken = wxAccessTokenService.getWxAccessTokenById(wechat_appid).getAccessToken();
|
|
|
|
// }
|
|
|
|
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=30_OBJbMMPW9TnyGHKf32bcjkXtxWnzBrtqWlSMBnNk8MWpJ6qis2TnsecRYNZImgahdx30WrsI1bGco6K67-j4sT1QkDxYKBrVvjaYF6QgbY8dgBMzuoARKoaxtX3ehiYvdCLSUHvogrpF3n0GANIfCHAHUP&media_id=R_060hnyXAFyHD9HaOLl15xhDIzDvcA61-Wz34GkXmCakdrsFJqxrPEBHewmAEK9";
|
|
|
|
logger.info("media/get"+url);
|
|
|
|
try {
|
|
|
|
URL urlGet = new URL(url);
|
|
|
|
HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
|
|
|
|
http.setRequestMethod("GET"); // 必须是get方式请求
|
|
|
|
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
http.setDoOutput(true);
|
|
|
|
http.setDoInput(true);
|
|
|
|
System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
|
|
|
|
System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
|
|
|
|
http.connect();
|
|
|
|
|
|
|
|
// 获取文件转化为byte流
|
|
|
|
is = http.getInputStream();
|
|
|
|
if(is.available() <= 200){
|
|
|
|
logger.info("下载多媒体文件 accessToken 过期");
|
|
|
|
//中山医院互联网医院
|
|
|
|
if("xm_zsyy_wx".equals(wechat_appid)){
|
|
|
|
accessToken = entranceService.getAccessToken("100033");
|
|
|
|
}else{
|
|
|
|
wxAccessTokenService.deleteByWechatId(wechat_appid);
|
|
|
|
accessToken = wxAccessTokenService.updateAccessToken(wechat_appid);
|
|
|
|
is = getInputStreamReLoad(mediaId,wechat_appid,accessToken);
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.info(e.getMessage());
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new Exception("下载失败,"+e.getMessage());
|
|
}
|
|
}
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* accessToken 过期时重新下载多媒体文件
|
|
|
|
* 下载多媒体文件(请注意,视频文件不支持下载,调用该接口需http协议)
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public InputStream getInputStreamReLoad(String mediaId,String wechat_appid,String accessToken) throws Exception {
|
|
|
|
logger.info("accessToken 过期时重新下载多媒体文件:accessToken:"+accessToken);
|
|
|
|
logger.info("accessToken 过期时重新下载多媒体文件:wechat_appid:"+wechat_appid);
|
|
|
|
logger.info("accessToken 过期时重新下载多媒体文件:mediaId:"+mediaId);
|
|
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;
|
|
logger.info("media/get"+url);
|
|
logger.info("media/get"+url);
|
|
@ -686,13 +736,19 @@ public class ImService {
|
|
http.connect();
|
|
http.connect();
|
|
// 获取文件转化为byte流
|
|
// 获取文件转化为byte流
|
|
is = http.getInputStream();
|
|
is = http.getInputStream();
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
logger.info(e.getMessage());
|
|
logger.info(e.getMessage());
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
throw new Exception("下载失败,"+e.getMessage());
|
|
}
|
|
}
|
|
return is;
|
|
return is;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取微信服务器图片
|
|
* 获取微信服务器图片
|
|
* @param wechat_appid 微信公众号appid
|
|
* @param wechat_appid 微信公众号appid
|