Commit 76d4e27e by danmo

欢迎语图片修改

1 parent 107db5ce
...@@ -2,12 +2,14 @@ package com.linkwechat.wecom.factory.impl; ...@@ -2,12 +2,14 @@ package com.linkwechat.wecom.factory.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.enums.MediaType;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.Threads; import com.linkwechat.common.utils.Threads;
import com.linkwechat.wecom.domain.WeEmpleCodeTag; import com.linkwechat.wecom.domain.WeEmpleCodeTag;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel; import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel; import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel;
import com.linkwechat.wecom.domain.dto.WeEmpleCodeDto; import com.linkwechat.wecom.domain.dto.WeEmpleCodeDto;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
import com.linkwechat.wecom.domain.dto.WeWelcomeMsg; import com.linkwechat.wecom.domain.dto.WeWelcomeMsg;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO; import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeCallBackEventFactory; import com.linkwechat.wecom.factory.WeCallBackEventFactory;
...@@ -44,6 +46,8 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory ...@@ -44,6 +46,8 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
private IWeFlowerCustomerRelService weFlowerCustomerRelService; private IWeFlowerCustomerRelService weFlowerCustomerRelService;
@Autowired @Autowired
private IWeFlowerCustomerTagRelService weFlowerCustomerTagRelService; private IWeFlowerCustomerTagRelService weFlowerCustomerTagRelService;
@Autowired
private IWeMaterialService weMaterialService;
@Override @Override
public void eventHandle(WxCpXmlMessageVO message) { public void eventHandle(WxCpXmlMessageVO message) {
...@@ -151,8 +155,13 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory ...@@ -151,8 +155,13 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
.content(messageMap.getWelcomeMsg()).build()); .content(messageMap.getWelcomeMsg()).build());
} }
if(StringUtils.isNotEmpty(messageMap.getCategoryId())){ if(StringUtils.isNotEmpty(messageMap.getCategoryId())){
weWelcomeMsgBuilder.image(WeWelcomeMsg.Image.builder().media_id(messageMap.getCategoryId()) WeMediaDto weMediaDto = weMaterialService
.pic_url(messageMap.getMaterialUrl()).build()); .uploadTemporaryMaterial(messageMap.getMaterialUrl(), MediaType.IMAGE.getMediaType());
Optional.ofNullable(weMediaDto).ifPresent(media ->{
weWelcomeMsgBuilder.image(WeWelcomeMsg.Image.builder().media_id(media.getMedia_id())
.pic_url(media.getUrl()).build());
});
} }
weCustomerService.sendWelcomeMsg(weWelcomeMsgBuilder.build()); weCustomerService.sendWelcomeMsg(weWelcomeMsgBuilder.build());
} }
......
...@@ -26,6 +26,7 @@ import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag; ...@@ -26,6 +26,7 @@ import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import com.linkwechat.wecom.mapper.WeCustomerMapper; import com.linkwechat.wecom.mapper.WeCustomerMapper;
import com.linkwechat.wecom.service.*; import com.linkwechat.wecom.service.*;
import com.tencent.wework.Finance;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
...@@ -111,6 +112,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto ...@@ -111,6 +112,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
*/ */
@Override @Override
public List<WeCustomer> selectWeCustomerList(WeCustomer weCustomer) { public List<WeCustomer> selectWeCustomerList(WeCustomer weCustomer) {
long sdk = Finance.NewSdk();
return weCustomerMapper.selectWeCustomerList(weCustomer); return weCustomerMapper.selectWeCustomerList(weCustomer);
} }
......
...@@ -10,15 +10,25 @@ import com.linkwechat.common.exception.wecom.WeComException; ...@@ -10,15 +10,25 @@ import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SnowFlakeUtil; import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUploadUtils; import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.wecom.client.WeMediaClient;
import com.linkwechat.wecom.domain.WeMaterial; import com.linkwechat.wecom.domain.WeMaterial;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
import com.linkwechat.wecom.domain.vo.WeMaterialFileVO; import com.linkwechat.wecom.domain.vo.WeMaterialFileVO;
import com.linkwechat.wecom.mapper.WeMaterialMapper; import com.linkwechat.wecom.mapper.WeMaterialMapper;
import com.linkwechat.wecom.service.IWeMaterialService; import com.linkwechat.wecom.service.IWeMaterialService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.http.entity.ContentType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -37,6 +47,8 @@ public class WeMaterialServiceImpl implements IWeMaterialService { ...@@ -37,6 +47,8 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
private WeMaterialMapper weMaterialMapper; private WeMaterialMapper weMaterialMapper;
@Autowired @Autowired
private ServerConfig serverConfig; private ServerConfig serverConfig;
@Autowired
private WeMediaClient weMediaClient;
@Override @Override
public WeMaterialFileVO uploadWeMaterialFile(MultipartFile file, String type) { public WeMaterialFileVO uploadWeMaterialFile(MultipartFile file, String type) {
...@@ -115,5 +127,21 @@ public class WeMaterialServiceImpl implements IWeMaterialService { ...@@ -115,5 +127,21 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
} }
} }
@Override
public WeMediaDto uploadTemporaryMaterial(String url, String type) {
try {
File file = new File(url);
FileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem item=factory.createItem(file.getName(),"text/plain",true,file.getName());
MultipartFile multipartFile = new CommonsMultipartFile(item);
return weMediaClient.upload(multipartFile, type);
} catch (Exception e) {
e.printStackTrace();
log.error("上传临时文件失败......url:{},type:{},ex:{},st:{}",url,type,e.getMessage(),e.getStackTrace());
}
return null;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!