Commit 50386d7d by 水库浪子

Merge branch 'master' of https://gitee.com/LinkWeChat/link-wechat

2 parents f9817cab 77943d6d
...@@ -19,6 +19,7 @@ import java.util.List; ...@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
/** /**
* @author sxw * @author sxw
...@@ -82,6 +83,27 @@ public class FinanceUtils { ...@@ -82,6 +83,27 @@ public class FinanceUtils {
JSONObject jsonObject = decryptChatRecord(sdk, data.getString("encrypt_random_key"), JSONObject jsonObject = decryptChatRecord(sdk, data.getString("encrypt_random_key"),
data.getString("encrypt_chat_msg"), privateKey); data.getString("encrypt_chat_msg"), privateKey);
jsonObject.put("seq", LocalSEQ); jsonObject.put("seq", LocalSEQ);
jsonObject.put("totype","0");
if (StringUtils.isEmpty(jsonObject.getString("roomid"))){
JSONArray tolist = jsonObject.getJSONArray("tolist");
Optional.ofNullable(tolist).ifPresent(itemList ->{
List<String> isEType = itemList.stream().map(item -> (String) item).filter(item ->
StringUtils.isNotEmpty(item) &&
("wo".equals(item.substring(0, 2)) || "wm".equals(item.substring(0, 2))))
.collect(Collectors.toList());
List<String> isExtype = itemList.stream().map(item -> (String) item).filter(item ->
StringUtils.isNotEmpty(item) && "wb".equals(item.substring(0, 2)))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(isEType)){
jsonObject.put("totype","1");
return;
}
if (CollectionUtil.isNotEmpty(isExtype)){
jsonObject.put("totype","2");
return;
}
});
}
elasticSearchEntity.setData(jsonObject); elasticSearchEntity.setData(jsonObject);
elasticSearchEntity.setId(jsonObject.getString("msgid")); elasticSearchEntity.setId(jsonObject.getString("msgid"));
resList.add(elasticSearchEntity); resList.add(elasticSearchEntity);
...@@ -94,16 +116,6 @@ public class FinanceUtils { ...@@ -94,16 +116,6 @@ public class FinanceUtils {
return resList; return resList;
} }
public static void main(String[] args) {
String secret = "_Ruv_TD_GzE4wJLvhMv4MeYkjM81_IJFDPcsUiss9fw";
initSDK("ww24262ce93851488f", secret);
//getChatData(0,"","");
// getMediaData("CiBkZDk3ZmJjMTlhYjU1YWJiNDQ4MjI3NWRlMzk1NmMzYxI4TkRkZk56ZzRNVE13TURVNU5Ua3lOVFEyTlY4NU5ERTBOekUwTWpaZk1UWXdOemt4TkRrMU1BPT0aIDBiMzY3YjkyNzE5ZDE3ZWU4NjkyNTVlYzJkNTlmNjI3",
// "", "", "");
}
/** /**
* @param sdk 初始化时候获取到的值 * @param sdk 初始化时候获取到的值
* @param ncrypt_random_key 企业微信返回的随机密钥 * @param ncrypt_random_key 企业微信返回的随机密钥
......
...@@ -56,11 +56,13 @@ ...@@ -56,11 +56,13 @@
<dependency> <dependency>
<groupId>net.java.dev.jna</groupId> <groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId> <artifactId>jna</artifactId>
<version>5.6.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.java.dev.jna</groupId> <groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId> <artifactId>jna-platform</artifactId>
<version>5.6.0</version>
</dependency> </dependency>
<!-- 系统模块--> <!-- 系统模块-->
......
...@@ -41,7 +41,7 @@ export default { ...@@ -41,7 +41,7 @@ export default {
this.loading = true this.loading = true
getDetail(id).then(({ data }) => { getDetail(id).then(({ data }) => {
this.form = data this.form = data
this.materialSelected = data.weMaterial.materialUrl this.materialSelected = data.weMaterial ==null?"":data.weMaterial.materialUrl
this.loading = false this.loading = false
}) })
}, },
......
...@@ -6,6 +6,7 @@ import com.dtflys.forest.annotation.Query; ...@@ -6,6 +6,7 @@ import com.dtflys.forest.annotation.Query;
import com.linkwechat.wecom.domain.dto.WeMediaDto; import com.linkwechat.wecom.domain.dto.WeMediaDto;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
/** /**
...@@ -18,12 +19,12 @@ public interface WeMediaClient { ...@@ -18,12 +19,12 @@ public interface WeMediaClient {
/** /**
* 上传临时素材 * 上传临时素材
* @param multipartFile * @param file
* @param type * @param type
* @return * @return
*/ */
@Post(url="/media/upload") @Post(url="/media/upload")
WeMediaDto upload(@DataFile(value = "file") MultipartFile multipartFile, @Query("type") String type); WeMediaDto upload(@DataFile(value = "media") File file, @Query("type") String type);
/** /**
* 上传图片 * 上传图片
...@@ -40,6 +41,6 @@ public interface WeMediaClient { ...@@ -40,6 +41,6 @@ public interface WeMediaClient {
* 使用byte数组和Inputstream对象时一定要定义fileName属性 * 使用byte数组和Inputstream对象时一定要定义fileName属性
*/ */
@Post(url = "/media/upload") @Post(url = "/media/upload")
WeMediaDto upload(@DataFile(value = "file", fileName = "${1}") InputStream in, String filename,@Query("type") String type); WeMediaDto upload(@DataFile(value = "media", fileName = "${1}") InputStream file, String filename, @Query("type") String type);
} }
...@@ -181,7 +181,7 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory ...@@ -181,7 +181,7 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
} }
if(StringUtils.isNotEmpty(messageMap.getCategoryId())){ if(StringUtils.isNotEmpty(messageMap.getCategoryId())){
WeMediaDto weMediaDto = weMaterialService WeMediaDto weMediaDto = weMaterialService
.uploadTemporaryMaterial(messageMap.getMaterialUrl(), MediaType.IMAGE.getMediaType()); .uploadTemporaryMaterial(messageMap.getMaterialUrl(),messageMap.getMaterialName(), MediaType.IMAGE.getMediaType());
Optional.ofNullable(weMediaDto).ifPresent(media ->{ Optional.ofNullable(weMediaDto).ifPresent(media ->{
weWelcomeMsgBuilder.image(WeWelcomeMsg.Image.builder().media_id(media.getMedia_id()) weWelcomeMsgBuilder.image(WeWelcomeMsg.Image.builder().media_id(media.getMedia_id())
.pic_url(media.getUrl()).build()); .pic_url(media.getUrl()).build());
......
...@@ -5,6 +5,7 @@ import com.dtflys.forest.exceptions.ForestRuntimeException; ...@@ -5,6 +5,7 @@ import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.dtflys.forest.http.ForestRequest; import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.http.ForestResponse; import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor; import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.multipart.ForestMultipart;
import com.dtflys.forest.utils.ForestDataType; import com.dtflys.forest.utils.ForestDataType;
import com.linkwechat.common.config.WeComeConfig; import com.linkwechat.common.config.WeComeConfig;
import com.linkwechat.common.constant.WeConstans; import com.linkwechat.common.constant.WeConstans;
...@@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
/** /**
* @description: 微信token拦截器 * @description: 微信token拦截器
...@@ -38,16 +40,15 @@ public class WeAccessTokenInterceptor implements Interceptor{ ...@@ -38,16 +40,15 @@ public class WeAccessTokenInterceptor implements Interceptor{
*/ */
@Override @Override
public boolean beforeExecute(ForestRequest request) { public boolean beforeExecute(ForestRequest request) {
request.setDataType(ForestDataType.JSON);
String uri=request.getUrl().replace("http://",""); String uri=request.getUrl().replace("http://","");
//request.setContentType("application/json");
if(!Arrays.asList(weComeConfig.getFileUplodUrl()).contains(uri)){
request.setDataType(ForestDataType.JSON);
request.setContentType("application/json"); request.setContentType("application/json");
// if(Arrays.asList(weComeConfig.getFileUplodUrl()).contains(uri)){ }
// request.setContentType("application/json");
// }else{
// request.setContentType("multipart/form-data");
// }
......
...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl; ...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import com.linkwechat.common.config.RuoYiConfig; import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.config.ServerConfig; import com.linkwechat.common.config.ServerConfig;
import com.linkwechat.common.constant.WeConstans; import com.linkwechat.common.constant.WeConstans;
...@@ -17,9 +18,19 @@ import com.linkwechat.wecom.domain.vo.WeMaterialFileVO; ...@@ -17,9 +18,19 @@ 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 me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
...@@ -135,32 +146,30 @@ public class WeMaterialServiceImpl implements IWeMaterialService { ...@@ -135,32 +146,30 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
public WeMediaDto uploadTemporaryMaterial(String url, String type) { public WeMediaDto uploadTemporaryMaterial(String url, String type) {
try { try {
File file = new File(url); File file = new File(url);
FileItemFactory factory = new DiskFileItemFactory(16, null); return weMediaClient.upload(file, type);
FileItem item=factory.createItem(file.getName(),"text/plain",true,file.getName());
MultipartFile multipartFile = new CommonsMultipartFile(item);
return weMediaClient.upload(multipartFile, type);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("上传临时文件失败......url:{},type:{},ex:{},st:{}",url,type,e.getMessage(),e.getStackTrace()); log.error("上传临时文件失败......url:{},type:{},ex:{},st:{}",url,type,e.getMessage(),e.getStackTrace());
} }
return null; return null;
} }
@Override @Override
public WeMediaDto uploadTemporaryMaterial(String url, String type, String name) { public WeMediaDto uploadTemporaryMaterial(String url, String type, String name) {
HttpURLConnection conn = null; HttpURLConnection conn = null;
try{ try{
URL materialUrl = new URL(url); URL materialUrl = new URL(url);
conn = (HttpURLConnection) materialUrl.openConnection(); conn = (HttpURLConnection) materialUrl.openConnection();
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
// conn.setConnectTimeout(20 * 1000); conn.setConnectTimeout(20 * 1000);
InputStream inputStream = conn.getInputStream(); return weMediaClient.upload(conn.getInputStream(), name, type);
return weMediaClient.upload(inputStream, name,type);
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
log.error("上传临时文件失败......url:{},type:{},name:{},ex:{},st:{}",url,type,name,e.getMessage(),e.getStackTrace()); log.error("上传临时文件失败......url:{},type:{},name:{},ex:{},st:{}",url,type,name,e.getMessage(),e.getStackTrace());
}finally {
if (conn !=null){
conn = null;
}
} }
return null; return null;
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<description>若依管理系统</description> <description>若依管理系统</description>
<properties> <properties>
<springboot.vaerion>2.2.1.RELEASE</springboot.vaerion> <springboot.vaerion>2.3.7.RELEASE</springboot.vaerion>
<linkwe.version>3.1.0</linkwe.version> <linkwe.version>3.1.0</linkwe.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<poi.version>3.17</poi.version> <poi.version>3.17</poi.version>
<velocity.version>1.7</velocity.version> <velocity.version>1.7</velocity.version>
<jwt.version>0.9.0</jwt.version> <jwt.version>0.9.0</jwt.version>
<forest.version>1.4.0</forest.version> <forest.version>1.5.0-RC1</forest.version>
<lombok.version>1.18.16</lombok.version> <lombok.version>1.18.16</lombok.version>
<reflectasm.version>1.11.9</reflectasm.version> <reflectasm.version>1.11.9</reflectasm.version>
<hutool.version>5.4.1</hutool.version> <hutool.version>5.4.1</hutool.version>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!