Commit 957c9c64 by danmo

会话存档媒体文件修改

1 parent 679faeff
......@@ -9,7 +9,7 @@ ruoyi:
# 实例演示开关
demoEnabled: true
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
profile: D:/ruoyi/uploadPath
profile: /home/ruoyi/uploadPath
# 获取ip地址开关
addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证
......
......@@ -114,7 +114,7 @@ public class RuoYiConfig
*/
public static String getDownloadWeWorkPath()
{
return getProfile() + "/download/media_data/{type}/{date}/{fileName}";
return getProfile() + "/download/media_data/{}/{}";
}
/**
......
package com.tencent.wework;
/* sdk��������
typedef struct Slice_t {
char* buf;
int len;
} Slice_t;
typedef struct MediaData {
char* outindexbuf;
int out_len;
char* data;
int data_len;
int is_finish;
} MediaData_t;
*/
public class Finance {
public native static long NewSdk();
/**
* ��ʼ������
* Returnֵ=0��ʾ��API���óɹ�
*
* @param [in] sdk NewSdk���ص�sdkָ��
* @param [in] corpid ������ҵ����ҵid�����磺wwd08c8exxxx5ab44d����������ҵ΢�Ź����--�ҵ���ҵ--��ҵ��Ϣ�鿴
* @param [in] secret �������ݴ浵��Secret����������ҵ΢�Ź����--������--�������ݴ浵�鿴
*
*
* @return �����Ƿ��ʼ���ɹ�
* 0 - �ɹ�
* !=0 - ʧ��
*/
/**
* 初始化函数
* Return值=0表示该API调用成功
*
* @param /[in] sdk NewSdk返回的sdk指针
* @param /[in] corpid 调用企业的企业id,例如:wwd08c8exxxx5ab44d,可以在企业微信管理端--我的企业--企业信息查看
* @param /[in] secret 聊天内容存档的Secret,可以在企业微信管理端--管理工具--聊天内容存档查看
* @return 返回是否初始化成功
* 0 - 成功
* !=0 - 失败
*/
public native static int Init(long sdk, String corpid, String secret);
/**
* ��ȡ�����¼����
* Returnֵ=0��ʾ��API���óɹ�
*
*
* @param [in] sdk NewSdk���ص�sdkָ��
* @param [in] seq ��ָ����seq��ʼ��ȡ��Ϣ��ע����Ƿ��ص���Ϣ��seq+1��ʼ���أ�seqΪ֮ǰ�ӿڷ��ص����seqֵ���״�ʹ����ʹ��seq:0
* @param [in] limit һ����ȡ����Ϣ���������ֵ1000��������1000���᷵�ش���
* @param [in] proxy ʹ�ô����������Ҫ�����������ӡ��磺socks5://10.0.0.1:8081 ���� http://10.0.0.1:8081
* @param [in] passwd �����˺����룬��Ҫ���������˺����롣�� user_name:passwd_123
* @param [out] chatDatas ���ر�����ȡ��Ϣ�����ݣ�slice�ṹ��.���ݰ���errcode/errmsg���Լ�ÿ����Ϣ���ݡ�
*
* @return �����Ƿ���óɹ�
* 0 - �ɹ�
* !=0 - ʧ��
*/
/**
* 拉取聊天记录函数
* Return值=0表示该API调用成功
*
* @param /[in] sdk NewSdk返回的sdk指针
* @param /[in] seq 从指定的seq开始拉取消息,注意的是返回的消息从seq+1开始返回,seq为之前接口返回的最大seq值。首次使用请使用seq:0
* @param /[in] limit 一次拉取的消息条数,最大值1000条,超过1000条会返回错误
* @param /[in] proxy 使用代理的请求,需要传入代理的链接。如:socks5://10.0.0.1:8081 或者 http://10.0.0.1:8081
* @param /[in] passwd 代理账号密码,需要传入代理的账号密码。如 user_name:passwd_123
* @param /[in] timeout 超时时间,单位秒
* @param /[out] chatDatas 返回本次拉取消息的数据,slice结构体.内容包括errcode/errmsg,以及每条消息内容。
* @return 返回是否调用成功
* 0 - 成功
* !=0 - 失败
*/
public native static int GetChatData(long sdk, long seq, long limit, String proxy, String passwd, long timeout, long chatData);
/**
* ��ȡý����Ϣ����
* Returnֵ=0��ʾ��API���óɹ�
*
*
* @param [in] sdk NewSdk���ص�sdkָ��
* @param [in] sdkFileid ��GetChatData���ص�������Ϣ�У�ý����Ϣ������sdkfileid
* @param [in] proxy ʹ�ô����������Ҫ�����������ӡ��磺socks5://10.0.0.1:8081 ���� http://10.0.0.1:8081
* @param [in] passwd �����˺����룬��Ҫ���������˺����롣�� user_name:passwd_123
* @param [in] indexbuf ý����Ϣ��Ƭ��ȡ����Ҫ����ÿ����ȡ��������Ϣ���״β���Ҫ��д��Ĭ����ȡ512k������ÿ�ε���ֻ��Ҫ���ϴε��÷��ص�outindexbuf���뼴�ɡ�
* @param [out] media_data ���ر�����ȡ��ý������.MediaData�ṹ��.���ݰ���data(��������)/outindexbuf(�´�����)/is_finish(��ȡ��ɱ��)
*
* @return �����Ƿ���óɹ�
* 0 - �ɹ�
* !=0 - ʧ��
*/
/**
* 拉取媒体消息函数
* Return值=0表示该API调用成功
*
* @param /[in] sdk NewSdk返回的sdk指针
* @param /[in] sdkFileid 从GetChatData返回的聊天消息中,媒体消息包括的sdkfileid
* @param /[in] proxy 使用代理的请求,需要传入代理的链接。如:socks5://10.0.0.1:8081 或者 http://10.0.0.1:8081
* @param /[in] passwd 代理账号密码,需要传入代理的账号密码。如 user_name:passwd_123
* @param /[in] timeout 超时时间,单位秒
* @param /[in] indexbuf 媒体消息分片拉取,需要填入每次拉取的索引信息。首次不需要填写,默认拉取512k,后续每次调用只需要将上次调用返回的outindexbuf填入即可。
* @param /[out] media_data 返回本次拉取的媒体数据.MediaData结构体.内容包括data(数据内容)/outindexbuf(下次索引)/is_finish(拉取完成标记)
* @return 返回是否调用成功
* 0 - 成功
* !=0 - 失败
*/
public native static int GetMediaData(long sdk, String indexbuf, String sdkField, String proxy, String passwd, long timeout, long mediaData);
/**
* @brief ��������
* @param [in] encrypt_key, getchatdata���ص�encrypt_key
* @param [in] encrypt_msg, getchatdata���ص�content
* @param [out] msg, ���ܵ���Ϣ����
* @return �����Ƿ���óɹ�
* 0 - �ɹ�
* !=0 - ʧ��
* @param /[in] encrypt_key, getchatdata返回的encrypt_key
* @param /[in] encrypt_msg, getchatdata返回的content
* @param /[out] msg, 解密的消息明文
* @return 返回是否调用成功
* 0 - 成功
* !=0 - 失败
* @brief 解析密文
*/
public native static int DecryptData(long sdk, String encrypt_key, String encrypt_msg, long msg);
public native static void DestroySdk(long sdk);
public native static long NewSlice();
/**
* @brief �ͷ�slice����NewSlice�ɶ�ʹ��
* @return
* @return
* @brief 释放slice,和NewSlice成对使用
*/
public native static void FreeSlice(long slice);
/**
* @brief ��ȡslice����
* @return ����
* @return 内容
* @brief 获取slice内容
*/
public native static String GetContentFromSlice(long slice);
/**
* @brief ��ȡslice���ݳ���
* @return ����
* @return 内容
* @brief 获取slice内容长度
*/
public native static int GetSliceLen(long slice);
public native static long NewMediaData();
public native static void FreeMediaData(long mediaData);
/**
* @brief ��ȡmediadata outindex
* @return outindex
* @brief 获取mediadata outindex
*/
public native static String GetOutIndexBuf(long mediaData);
/**
* @brief ��ȡmediadata data����
* @return data
* @brief 获取mediadata data数据
*/
public native static byte[] GetData(long mediaData);
public native static int GetIndexLen(long mediaData);
public native static int GetDataLen(long mediaData);
/**
* @brief �ж�mediadata�Ƿ����
* @return 1��ɡ�0δ���
* @return 1完成、0未完成
* @brief 判断mediadata是否结束
*/
public native static int IsMediaDataFinish(long mediaData);
static {
if (isWindows()) {
System.loadLibrary("libeay32");
System.loadLibrary("libprotobuf");
System.loadLibrary("ssleay32");
System.loadLibrary("libcurl");
System.loadLibrary("WeWorkFinanceSdk");
}else {
System.loadLibrary("libWeWorkFinanceSdk_Java");
}
if (isWindows()) {
System.loadLibrary("libeay32");
System.loadLibrary("libprotobuf");
System.loadLibrary("ssleay32");
System.loadLibrary("libcurl");
System.loadLibrary("WeWorkFinanceSdk");
} else {
System.load("/app/project/libWeWorkFinanceSdk_Java.so");
}
}
public static boolean isWindows() {
String osName = System.getProperties().getProperty("os.name");
System.out.println("current system is " + osName);
return osName.toUpperCase().indexOf("WINDOWS") != -1;
}
public static boolean isWindows() {
String osName = System.getProperties().getProperty("os.name");
System.out.println("current system is " + osName);
return osName.toUpperCase().indexOf("WINDOWS") != -1;
}
}
\ No newline at end of file
......@@ -125,8 +125,8 @@ public class FinanceUtils {
String secret = "_Ruv_TD_GzE4wJLvhMv4MeYkjM81_IJFDPcsUiss9fw";
initSDK("ww24262ce93851488f", secret);
//getChatData(0,"","");
getMediaData("CiBkZDk3ZmJjMTlhYjU1YWJiNDQ4MjI3NWRlMzk1NmMzYxI4TkRkZk56ZzRNVE13TURVNU5Ua3lOVFEyTlY4NU5ERTBOekUwTWpaZk1UWXdOemt4TkRrMU1BPT0aIDBiMzY3YjkyNzE5ZDE3ZWU4NjkyNTVlYzJkNTlmNjI3",
"", "", "");
// getMediaData("CiBkZDk3ZmJjMTlhYjU1YWJiNDQ4MjI3NWRlMzk1NmMzYxI4TkRkZk56ZzRNVE13TURVNU5Ua3lOVFEyTlY4NU5ERTBOekUwTWpaZk1UWXdOemt4TkRrMU1BPT0aIDBiMzY3YjkyNzE5ZDE3ZWU4NjkyNTVlYzJkNTlmNjI3",
// "", "", "");
}
......@@ -214,9 +214,9 @@ public class FinanceUtils {
JSONObject emotionData = Optional.ofNullable(realJsonData.getJSONObject(msgType))
.orElse(realJsonData.getJSONObject("content"));
String filename = emotionData.getString("filename");
String fileext = emotionData.getString("fileext");
String fileName = filename+"."+fileext;
getPath(realJsonData, msgType, fileName);
//String fileext = emotionData.getString("fileext");
//String fileName = filename+"."+fileext;
getPath(realJsonData, msgType, filename);
}
......@@ -252,23 +252,29 @@ public class FinanceUtils {
}
private static void getPath(JSONObject realJsonData, String msgType, String fileName) {
String filePath = getFilePath(msgType, fileName);
String filePath = getFilePath(msgType);
JSONObject data = Optional.ofNullable(realJsonData.getJSONObject(msgType))
.orElse(realJsonData.getJSONObject("content"));
String sdkfileid = data.getString("sdkfileid");
try {
getMediaData(sdkfileid,"","",filePath);
getMediaData(sdkfileid,"","",filePath,fileName);
} catch (Exception e) {
e.printStackTrace();
}
realJsonData.put("attachment",filePath);
data.put("attachment",filePath+"/"+fileName);
if(realJsonData.containsKey("content")){
realJsonData.put("content",data);
}else {
realJsonData.put("msgType",data);
}
}
private static String getFilePath(String msgType, String fileName) {
return StringUtils.format(downloadWeWorkPath, msgType, DateUtils.getDate(), fileName);
private static String getFilePath(String msgType) {
return StringUtils.format(downloadWeWorkPath, msgType, DateUtils.getDate());
}
private static void getMediaData(String sdkFileid, String proxy, String passwd, String filePath) {
private static void getMediaData(String sdkFileid, String proxy, String passwd, String filePath, String fileName) {
String indexbuf = "";
while (true) {
long media_data = Finance.NewMediaData();
......@@ -281,7 +287,15 @@ public class FinanceUtils {
int dataLen = Finance.GetDataLen(media_data);
int isMediaDataFinish = Finance.IsMediaDataFinish(media_data);*/
try {
FileOutputStream outputStream = new FileOutputStream(new File(filePath), true);
File f = new File(filePath);
if(!f.exists()){
f.mkdirs();
}
File file = new File(filePath,fileName);
if (!file.isDirectory()){
file.createNewFile();
}
FileOutputStream outputStream = new FileOutputStream(file, true);
//File file = new File("D:\\浏览器下载\\media_data\\"+ IdUtils.simpleUUID()+".jpg");
//FileOutputStream outputStream = new FileOutputStream(file, true);
outputStream.write(Finance.GetData(media_data));
......
......@@ -44,6 +44,9 @@ public class RyTask {
public void FinanceTask(String corpId, String secret) throws IOException {
log.info("执行有参方法: params:{},{}", corpId, secret);
//创建索引
elasticSearch.createIndex2(WeConstans.WECOM_FINANCE_INDEX,elasticSearch.getFinanceMapping());
AtomicLong index = new AtomicLong(0);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
SortBuilder<?> sortBuilderPrice = SortBuilders.fieldSort("seq").order( SortOrder.DESC);
......@@ -52,11 +55,7 @@ public class RyTask {
searchResultList.stream().findFirst().ifPresent(result ->{
index.set(result.getLong("seq")+1);
});
if (index.get() == 0) {
elasticSearch.createIndex2(WeConstans.WECOM_FINANCE_INDEX,elasticSearch.getFinanceMapping());
}
log.info("执行有参方法: params:{},{}", corpId, secret);
log.info(">>>>>>>seq:{}",index.get());
FinanceUtils.initSDK(corpId, secret);
List<ElasticSearchEntity> chatDataList = FinanceUtils.getChatData(index.get(), "", "");
......
......@@ -104,4 +104,4 @@
"> 1%",
"last 2 versions"
]
}
\ No newline at end of file
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!