Commit 9d9fc69e by 孙喜旺

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

1 parent 7217e3c0
......@@ -36,4 +36,13 @@ 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,6 +94,8 @@ public interface IWeMaterialService {
*/
public WeMediaDto uploadTemporaryMaterial(String url, String type,String name);
public WeMediaDto uploadTemporaryMaterial(String url, String type);
/**
* 上传素材图片
* @param file
......
......@@ -13,11 +13,14 @@ import com.linkwechat.wecom.client.WeCustomerMessagePushClient;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerMessage;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import com.linkwechat.wecom.domain.dto.message.ImageMessageDto;
import com.linkwechat.wecom.domain.dto.message.SendMessageResultDto;
import com.linkwechat.wecom.domain.dto.message.WeCustomerMessagePushDto;
import com.linkwechat.wecom.mapper.WeCustomerMessageMapper;
import com.linkwechat.wecom.service.IWeCustomerMessageService;
import com.linkwechat.wecom.service.IWeMaterialService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -45,6 +48,9 @@ public class WeCustomerMessageServiceImpl extends ServiceImpl<WeCustomerMessageM
@Autowired
private WeCustomerMessagePushClient weCustomerMessagePushClient;
@Autowired
private IWeMaterialService weMaterialService;
@Override
public int updateWeCustomerMessageActualSend(Long messageId, Integer actualSend) {
......@@ -147,9 +153,15 @@ 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());
imageMessage.setMedia_id(weMediaDto.getMedia_id());
} catch (Exception e) {
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("msgtype","image");
jsonObject.put("image",customerMessagePushDto.getImageMessage());
jsonObject.put("image",imageMessage);
list.add(jsonObject);
}
if (customerMessagePushDto.getMessageType().equals(GroupMessageType.LINK.getType())) {
......
......@@ -153,6 +153,27 @@ 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!