Commit 837ecbbf by danmo

消息发送图片改为发送时换取素材id修改

1 parent 00b63b88
......@@ -36,13 +36,4 @@ public interface WeMediaClient {
@Post(url = "/media/upload")
WeMediaDto upload(@DataFile(value = "media", fileName = "${1}") InputStream file, String filename, @Query("type") String type);
/**
* 上传临时素材
* Inputstream 对象
* 使用byte数组和Inputstream对象时一定要定义fileName属性
*/
@Post(url = "/media/upload")
WeMediaDto upload(@DataFile(value = "media") InputStream file, @Query("type") String type);
}
......@@ -94,8 +94,6 @@ public interface IWeMaterialService {
*/
public WeMediaDto uploadTemporaryMaterial(String url, String type,String name);
public WeMediaDto uploadTemporaryMaterial(String url, String type);
/**
* 上传素材图片
* @param file
......
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
......@@ -155,7 +156,8 @@ public class WeCustomerMessageServiceImpl extends ServiceImpl<WeCustomerMessageM
if (customerMessagePushDto.getMessageType().equals(GroupMessageType.IMAGE.getType())) {
ImageMessageDto imageMessage = customerMessagePushDto.getImageMessage();
try {
WeMediaDto weMediaDto = weMaterialService.uploadTemporaryMaterial(imageMessage.getPic_url(), GroupMessageType.IMAGE.getMessageType());
WeMediaDto weMediaDto = weMaterialService.uploadTemporaryMaterial(imageMessage.getPic_url(),
FileUtil.getName(imageMessage.getPic_url()),GroupMessageType.IMAGE.getMessageType());
imageMessage.setMedia_id(weMediaDto.getMedia_id());
} catch (Exception e) {
}
......
......@@ -153,27 +153,6 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
}
@Override
public WeMediaDto uploadTemporaryMaterial(String url, String type) {
HttpURLConnection conn = null;
try{
URL materialUrl = new URL(url);
conn = (HttpURLConnection) materialUrl.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(20 * 1000);
InputStream inputStream = conn.getInputStream();
return weMediaClient.upload(inputStream, type);
}catch (Exception e){
e.printStackTrace();
log.error("上传临时文件失败......url:{},type:{},ex:{},st:{}",url,type,e.getMessage(),e.getStackTrace());
}finally {
if (conn !=null){
conn = null;
}
}
return null;
}
@Override
public WeMediaDto uploadImg(MultipartFile file) {
return weMediaClient.uploadimg(file);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!