🎨 格式化规范化部分测试代码

This commit is contained in:
Binary Wang
2022-10-30 14:31:34 +08:00
parent 30264bfaae
commit bf9c0571f8
2 changed files with 126 additions and 128 deletions

View File

@ -25,9 +25,10 @@ import java.util.List;
/** /**
* 企业微信会话内容存档测试类. * 企业微信会话内容存档测试类.
* 官方文档:https://developer.work.weixin.qq.com/document/path/91360 * <a href="https://developer.work.weixin.qq.com/document/path/91360">官方文档</a>
* *
* @author <a href="https://github.com/0katekate0">Wang_Wong</a> created on 2022-01-17 * @author <a href="https://github.com/0katekate0">Wang_Wong</a>
* created on 2022-01-17
*/ */
@Slf4j @Slf4j
public class WxCpMsgAuditTest { public class WxCpMsgAuditTest {
@ -37,27 +38,22 @@ public class WxCpMsgAuditTest {
/** /**
* Test. * Test.
*
* @throws Exception the exception
*/ */
// com.binarywang.spring.starter.wxjava.cp.config.WxCpServiceAutoConfiguration // com.binarywang.spring.starter.wxjava.cp.config.WxCpServiceAutoConfiguration
// WxCpServiceImpl.getAccessToken() // WxCpServiceImpl.getAccessToken()
@BeforeTest @BeforeTest
private void initCpservice() { private void initCpService() {
if(cpService == null) { if (cpService == null) {
InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml"); InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml");
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(inputStream); wxCpConfigStorage = WxCpDemoInMemoryConfigStorage.fromXml(inputStream);
config.setMsgAuditLibPath("/E:/IDEA_WORKSPACE/saisc/crs-member-java/target/classes/wework/libcrypto-1_1-x64.dll,libssl-1_1-x64.dll,libcurl-x64.dll,WeWorkFinanceSdk.dll");
wxCpConfigStorage = config;
cpService = new WxCpServiceImpl(); cpService = new WxCpServiceImpl();
cpService.setWxCpConfigStorage(config); cpService.setWxCpConfigStorage(this.wxCpConfigStorage);
} }
} }
@Test @Test
public void test() throws Exception { public void test() throws Exception {
/** /*
* 客户同意进行聊天内容存档事件回调 * 客户同意进行聊天内容存档事件回调
* 配置了客户联系功能的成员添加外部联系人同意进行聊天内容存档时,回调该事件。 * 配置了客户联系功能的成员添加外部联系人同意进行聊天内容存档时,回调该事件。
* *
@ -79,7 +75,7 @@ public class WxCpMsgAuditTest {
msgAuditApprovedXmlMsg.setAllFieldsMap(XmlUtils.xml2Map(msgAuditApprovedXml)); msgAuditApprovedXmlMsg.setAllFieldsMap(XmlUtils.xml2Map(msgAuditApprovedXml));
log.info("msgAuditApprovedXmlMsg:{}", JSON.toString(msgAuditApprovedXmlMsg)); log.info("msgAuditApprovedXmlMsg:{}", JSON.toString(msgAuditApprovedXmlMsg));
/** /*
* 产生会话回调事件 * 产生会话回调事件
* 为了提升企业会话存档的使用性能,降低无效的轮询次数。 * 为了提升企业会话存档的使用性能,降低无效的轮询次数。
* 当企业收到或发送新消息时企业微信可以以事件的形式推送到企业指定的url。回调间隔为15秒在15秒内若有消息则触发回调若无消息则不会触发回调。 * 当企业收到或发送新消息时企业微信可以以事件的形式推送到企业指定的url。回调间隔为15秒在15秒内若有消息则触发回调若无消息则不会触发回调。
@ -99,13 +95,13 @@ public class WxCpMsgAuditTest {
msgAuditNotifyXmlMsg.setAllFieldsMap(XmlUtils.xml2Map(msgAuditNotifyXml)); msgAuditNotifyXmlMsg.setAllFieldsMap(XmlUtils.xml2Map(msgAuditNotifyXml));
log.info("msgAuditNotifyXmlMsg:{}", JSON.toString(msgAuditNotifyXmlMsg)); log.info("msgAuditNotifyXmlMsg:{}", JSON.toString(msgAuditNotifyXmlMsg));
/** /*
* 增加变更事件类型:产生会话回调事件 * 增加变更事件类型:产生会话回调事件
*/ */
String msgauditNotify = WxCpConsts.EventType.MSGAUDIT_NOTIFY; String msgauditNotify = WxCpConsts.EventType.MSGAUDIT_NOTIFY;
/** /*
* 仔细配置: * 仔细配置:
* <xml> * <xml>
* <corpId>ww45xxx88865xxx</corpId> * <corpId>ww45xxx88865xxx</corpId>
@ -161,12 +157,12 @@ public class WxCpMsgAuditTest {
* openssl rsa -in private_key.pem -pubout -out public_key.pem * openssl rsa -in private_key.pem -pubout -out public_key.pem
* / * /
/** /*
* 建议放到redis本次请求获取消息记录开始的seq值。首次访问填写0非首次使用上次企业微信返回的最大seq。允许从任意seq重入拉取。 * 建议放到redis本次请求获取消息记录开始的seq值。首次访问填写0非首次使用上次企业微信返回的最大seq。允许从任意seq重入拉取。
*/ */
long seq = 0L; long seq = 0L;
/** /*
* 图片,语音,视频,表情,文件,音频存档消息,音频共享文档消息调用 获取媒体消息 * 图片,语音,视频,表情,文件,音频存档消息,音频共享文档消息调用 获取媒体消息
*/ */
List<String> mediaType = Arrays.asList("image", "voice", "video", "emotion", "file", List<String> mediaType = Arrays.asList("image", "voice", "video", "emotion", "file",
@ -201,7 +197,7 @@ public class WxCpMsgAuditTest {
chatData, 2); chatData, 2);
log.info("获取消息数据为:{}", decryptData.toJson()); log.info("获取消息数据为:{}", decryptData.toJson());
/** /*
* 注意: * 注意:
* 根据上面返回的文件类型来获取媒体文件, * 根据上面返回的文件类型来获取媒体文件,
* 不同的文件类型,拼接好存放文件的绝对路径,写入文件流,获取媒体文件。(拼接绝对文件路径的原因,以便上传到腾讯云或阿里云对象存储) * 不同的文件类型,拼接好存放文件的绝对路径,写入文件流,获取媒体文件。(拼接绝对文件路径的原因,以便上传到腾讯云或阿里云对象存储)
@ -278,7 +274,7 @@ public class WxCpMsgAuditTest {
return; return;
} }
/** /*
* 拉取媒体文件 * 拉取媒体文件
* *
* 注意: * 注意:
@ -300,7 +296,7 @@ public class WxCpMsgAuditTest {
} }
/** /*
* 文本 * 文本
*/ */
// String text = "{\"msgid\":\"CAQQluDa4QUY0On2rYSAgAMgzPrShAE=\",\"action\":\"send\",\"from\":\"XuJinSheng\", // String text = "{\"msgid\":\"CAQQluDa4QUY0On2rYSAgAMgzPrShAE=\",\"action\":\"send\",\"from\":\"XuJinSheng\",
@ -313,7 +309,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelText.toJson()); log.info("数据为:" + modelText.toJson());
/** /*
* 图片 * 图片
*/ */
String image = "{\"msgid\":\"CAQQvPnc4QUY0On2rYSAgAMgooLa0Q8=\",\"action\":\"send\",\"from\":\"XuJinSheng\"," + String image = "{\"msgid\":\"CAQQvPnc4QUY0On2rYSAgAMgooLa0Q8=\",\"action\":\"send\",\"from\":\"XuJinSheng\"," +
@ -325,7 +321,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelImage.toJson()); log.info("数据为:" + modelImage.toJson());
/** /*
* 撤回消息 * 撤回消息
*/ */
String revoke = "{\"msgid\":\"15775510700152506326_1603875615\",\"action\":\"recall\",\"from\":\"kenshin\"," + String revoke = "{\"msgid\":\"15775510700152506326_1603875615\",\"action\":\"recall\",\"from\":\"kenshin\"," +
@ -335,7 +331,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelRevoke.toJson()); log.info("数据为:" + modelRevoke.toJson());
/** /*
* 同意会话聊天内容 * 同意会话聊天内容
*/ */
String agree = "{\"msgid\":\"8891446340739254950_1603875826\",\"action\":\"send\"," + String agree = "{\"msgid\":\"8891446340739254950_1603875826\",\"action\":\"send\"," +
@ -352,7 +348,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelDisagree.toJson()); log.info("数据为:" + modelDisagree.toJson());
/** /*
* 语音 * 语音
*/ */
String voice = "{\"msgid\":\"10958372969718811103_1603875609\",\"action\":\"send\"," + String voice = "{\"msgid\":\"10958372969718811103_1603875609\",\"action\":\"send\"," +
@ -365,7 +361,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelVoice.toJson()); log.info("数据为:" + modelVoice.toJson());
/** /*
* 视频 * 视频
*/ */
String video = "{\"msgid\":\"17955920891003447432_1603875627\",\"action\":\"send\",\"from\":\"kenshin\"," + String video = "{\"msgid\":\"17955920891003447432_1603875627\",\"action\":\"send\",\"from\":\"kenshin\"," +
@ -378,7 +374,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelVideo.toJson()); log.info("数据为:" + modelVideo.toJson());
/** /*
* 名片 * 名片
*/ */
String card = "{\"msgid\":\"13714216591700685558_1603875680\",\"action\":\"send\",\"from\":\"kenshin\"," + String card = "{\"msgid\":\"13714216591700685558_1603875680\",\"action\":\"send\",\"from\":\"kenshin\"," +
@ -388,7 +384,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelCard.toJson()); log.info("数据为:" + modelCard.toJson());
/** /*
* 位置 * 位置
*/ */
String location = "{\"msgid\":\"2641513858500683770_1603876152\",\"action\":\"send\",\"from\":\"icefog\"," + String location = "{\"msgid\":\"2641513858500683770_1603876152\",\"action\":\"send\",\"from\":\"icefog\"," +
@ -399,7 +395,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelLocation.toJson()); log.info("数据为:" + modelLocation.toJson());
/** /*
* 表情 * 表情
*/ */
String emotion = "{\"msgid\":\"6623217619416669654_1603875612\",\"action\":\"send\",\"from\":\"icef\"," + String emotion = "{\"msgid\":\"6623217619416669654_1603875612\",\"action\":\"send\",\"from\":\"icef\"," +
@ -411,7 +407,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelEmotion.toJson()); log.info("数据为:" + modelEmotion.toJson());
/** /*
* 文件 * 文件
*/ */
String file = "{\"msgid\":\"18039699423706571225_1603875608\",\"action\":\"send\",\"from\":\"kens\"," + String file = "{\"msgid\":\"18039699423706571225_1603875608\",\"action\":\"send\",\"from\":\"kens\"," +
@ -424,7 +420,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelFile.toJson()); log.info("数据为:" + modelFile.toJson());
/** /*
* 链接 * 链接
*/ */
String link = "{\"msgid\":\"11788441727514772650_1603875624\",\"action\":\"send\",\"from\":\"kenshin\"," + String link = "{\"msgid\":\"11788441727514772650_1603875624\",\"action\":\"send\",\"from\":\"kenshin\"," +
@ -435,7 +431,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelLink.toJson()); log.info("数据为:" + modelLink.toJson());
/** /*
* 小程序消息 * 小程序消息
*/ */
String weapp = "{\"msgid\":\"11930598857592605935_1603875608\",\"action\":\"send\",\"from\":\"kens\"," + String weapp = "{\"msgid\":\"11930598857592605935_1603875608\",\"action\":\"send\",\"from\":\"kens\"," +
@ -446,7 +442,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelWeapp.toJson()); log.info("数据为:" + modelWeapp.toJson());
/** /*
* 会话记录消息 * 会话记录消息
*/ */
String chatrecord = "{\"msgid\":\"11354299838102555191_1603875658\",\"action\":\"send\",\"from\":\"ken\"," + String chatrecord = "{\"msgid\":\"11354299838102555191_1603875658\",\"action\":\"send\",\"from\":\"ken\"," +
@ -458,7 +454,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelChatRecord.toJson()); log.info("数据为:" + modelChatRecord.toJson());
/** /*
* 填表消息 * 填表消息
*/ */
String collect = "{\"msgid\":\"2500536226619379797_1576034482\",\"action\":\"send\",\"from\":\"nick\"," + String collect = "{\"msgid\":\"2500536226619379797_1576034482\",\"action\":\"send\",\"from\":\"nick\"," +
@ -471,7 +467,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelCollect.toJson()); log.info("数据为:" + modelCollect.toJson());
/** /*
* 红包消息 * 红包消息
*/ */
String redpacket = "{\"msgid\":\"333590477316965370_1603877439\",\"action\":\"send\",\"from\":\"kens\"," + String redpacket = "{\"msgid\":\"333590477316965370_1603877439\",\"action\":\"send\",\"from\":\"kens\"," +
@ -481,7 +477,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelRedpacket.toJson()); log.info("数据为:" + modelRedpacket.toJson());
/** /*
* 会议邀请信息 * 会议邀请信息
*/ */
String meeting = "{\"msgid\":\"5935786683775673543_1603877328\",\"action\":\"send\",\"from\":\"ken\"," + String meeting = "{\"msgid\":\"5935786683775673543_1603877328\",\"action\":\"send\",\"from\":\"ken\"," +
@ -492,7 +488,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelMeeting.toJson()); log.info("数据为:" + modelMeeting.toJson());
/** /*
* 切换企业日志 * 切换企业日志
*/ */
String switchlog = "{\"msgid\":\"125289002219525886280\",\"action\":\"switch\",\"time\":1554119421840," + String switchlog = "{\"msgid\":\"125289002219525886280\",\"action\":\"switch\",\"time\":1554119421840," +
@ -501,7 +497,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelSwitchLog.toJson()); log.info("数据为:" + modelSwitchLog.toJson());
/** /*
* 在线文档消息 * 在线文档消息
*/ */
String docMsg = "{\"msgid\":\"9732089160923053207_1603877765\",\"action\":\"send\",\"from\":\"ken\"," + String docMsg = "{\"msgid\":\"9732089160923053207_1603877765\",\"action\":\"send\",\"from\":\"ken\"," +
@ -512,7 +508,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelDocMsg.toJson()); log.info("数据为:" + modelDocMsg.toJson());
/** /*
* MarkDown格式消息 * MarkDown格式消息
*/ */
String markDown = "{\"msgid\":\"7546287934688259248_1603875715\",\"action\":\"send\",\"from\":\"ken\"," + String markDown = "{\"msgid\":\"7546287934688259248_1603875715\",\"action\":\"send\",\"from\":\"ken\"," +
@ -522,7 +518,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelMarkDown.toJson()); log.info("数据为:" + modelMarkDown.toJson());
/** /*
* 图文消息 * 图文消息
*/ */
String news = "{\"msgid\":\"118732825779547782215\",\"action\":\"send\",\"from\":\"kens\",\"tolist\":[\"icef\"," + String news = "{\"msgid\":\"118732825779547782215\",\"action\":\"send\",\"from\":\"kens\",\"tolist\":[\"icef\"," +
@ -533,7 +529,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelNews.toJson()); log.info("数据为:" + modelNews.toJson());
/** /*
* 日程消息 * 日程消息
*/ */
String calendar = "{\"msgid\":\"2345881211604379705_1603877680\",\"action\":\"send\",\"from\":\"ken\"," + String calendar = "{\"msgid\":\"2345881211604379705_1603877680\",\"action\":\"send\",\"from\":\"ken\"," +
@ -545,7 +541,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelCalendar.toJson()); log.info("数据为:" + modelCalendar.toJson());
/** /*
* 混合消息 * 混合消息
*/ */
String mixed = "{\"msgid\":\"DAQQluDa4QUY0On4kYSABAMgzPrShAE=\",\"action\":\"send\",\"from\":\"HeMiao\"," + String mixed = "{\"msgid\":\"DAQQluDa4QUY0On4kYSABAMgzPrShAE=\",\"action\":\"send\",\"from\":\"HeMiao\"," +
@ -564,7 +560,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelMixed.toJson()); log.info("数据为:" + modelMixed.toJson());
/** /*
* 音频存档消息 * 音频存档消息
*/ */
String meetingVoiceCall = "{\"msgid\":\"17952229780246929345_1594197637\",\"action\":\"send\"," + String meetingVoiceCall = "{\"msgid\":\"17952229780246929345_1594197637\",\"action\":\"send\"," +
@ -577,7 +573,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelMeetingVoiceCall.toJson()); log.info("数据为:" + modelMeetingVoiceCall.toJson());
/** /*
* 音频共享文档消息 * 音频共享文档消息
*/ */
String voipDocShare = "{\"msgid\":\"16527954622422422847_1594199256\",\"action\":\"send\"," + String voipDocShare = "{\"msgid\":\"16527954622422422847_1594199256\",\"action\":\"send\"," +
@ -591,7 +587,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelVoipDocShare.toJson()); log.info("数据为:" + modelVoipDocShare.toJson());
/** /*
* 互通红包消息 * 互通红包消息
*/ */
String externalRedpacket = "{\"msgid\":\"8632214264349267353_1603786184\",\"action\":\"send\"," + String externalRedpacket = "{\"msgid\":\"8632214264349267353_1603786184\",\"action\":\"send\"," +
@ -603,7 +599,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelExternalRedpacket.toJson()); log.info("数据为:" + modelExternalRedpacket.toJson());
/** /*
* 视频号消息 * 视频号消息
*/ */
String sphfeed = "{\"msgid\":\"5702551662099334532_1619511584_external\",\"action\":\"send\"," + String sphfeed = "{\"msgid\":\"5702551662099334532_1619511584_external\",\"action\":\"send\"," +
@ -614,7 +610,7 @@ public class WxCpMsgAuditTest {
log.info("数据为:" + modelSphFeed.toJson()); log.info("数据为:" + modelSphFeed.toJson());
/** /*
* 获取会话内容存档开启成员列表 * 获取会话内容存档开启成员列表
*/ */
List<String> permitUserList = cpService.getMsgAuditService().getPermitUserList(null); List<String> permitUserList = cpService.getMsgAuditService().getPermitUserList(null);
@ -623,7 +619,7 @@ public class WxCpMsgAuditTest {
ArrayList<WxCpCheckAgreeRequest.Info> userList = Lists.newArrayList(); ArrayList<WxCpCheckAgreeRequest.Info> userList = Lists.newArrayList();
WxCpCheckAgreeRequest checkAgreeRequest = new WxCpCheckAgreeRequest(); WxCpCheckAgreeRequest checkAgreeRequest = new WxCpCheckAgreeRequest();
/** /*
* 获取会话同意情况 * 获取会话同意情况
*/ */
WxCpCheckAgreeRequest.Info info = new WxCpCheckAgreeRequest.Info(); WxCpCheckAgreeRequest.Info info = new WxCpCheckAgreeRequest.Info();
@ -638,20 +634,21 @@ public class WxCpMsgAuditTest {
log.info(wxCpAgreeInfo.toJson()); log.info(wxCpAgreeInfo.toJson());
/** /*
* 获取会话内容存档内部群信息 * 获取会话内容存档内部群信息
*/ */
WxCpGroupChat room = cpService.getMsgAuditService().getGroupChat("wrOQpTDwAAyPl84GBJ40W5eWxWtixSCA"); WxCpGroupChat room = cpService.getMsgAuditService().getGroupChat("wrOQpTDwAAyPl84GBJ40W5eWxWtixSCA");
log.info(room.toJson()); log.info(room.toJson());
/** /*
* 获取access_token * 获取access_token
* https://developer.work.weixin.qq.com/document/path/91039 * https://developer.work.weixin.qq.com/document/path/91039
* https://www.jianshu.com/p/dde171887d63 * https://www.jianshu.com/p/dde171887d63
*/ */
String getUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s"; String getUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s";
String data = cpService.get(String.format(getUrl, wxCpConfigStorage.getCorpId(), wxCpConfigStorage.getCorpSecret()), null); String data = cpService.get(String.format(getUrl, wxCpConfigStorage.getCorpId(),
wxCpConfigStorage.getCorpSecret()), null);
} }
@ -662,97 +659,97 @@ public class WxCpMsgAuditTest {
WxCpChatDatas chatDatas = msgAuditService.getChatDatas(0L, 100L, null, null, 10); WxCpChatDatas chatDatas = msgAuditService.getChatDatas(0L, 100L, null, null, 10);
for (WxCpChatDatas.WxCpChatData chatDatum : chatDatas.getChatData()) { for (WxCpChatDatas.WxCpChatData chatDatum : chatDatas.getChatData()) {
WxCpChatModel decryptData = msgAuditService.getDecryptData(chatDatas.getSdk(), chatDatum, 2); WxCpChatModel decryptData = msgAuditService.getDecryptData(chatDatas.getSdk(), chatDatum, 2);
// 文件后缀 // 文件后缀
String suffix = ""; String suffix = "";
// 文件名md5 // 文件名md5
String md5Sum = ""; String md5Sum = "";
// sdkFileId // sdkFileId
String sdkFileId = ""; String sdkFileId = "";
String msgType = decryptData.getMsgType(); String msgType = decryptData.getMsgType();
if(msgType == null ) msgType = ""; if (msgType == null) msgType = "";
switch (msgType) { switch (msgType) {
case "image": case "image":
suffix = ".jpg"; suffix = ".jpg";
md5Sum = decryptData.getImage().getMd5Sum(); md5Sum = decryptData.getImage().getMd5Sum();
sdkFileId = decryptData.getImage().getSdkFileId(); sdkFileId = decryptData.getImage().getSdkFileId();
break; break;
case "voice": case "voice":
suffix = ".amr"; suffix = ".amr";
md5Sum = decryptData.getVoice().getMd5Sum(); md5Sum = decryptData.getVoice().getMd5Sum();
sdkFileId = decryptData.getVoice().getSdkFileId(); sdkFileId = decryptData.getVoice().getSdkFileId();
break; break;
case "video": case "video":
suffix = ".mp4"; suffix = ".mp4";
md5Sum = decryptData.getVideo().getMd5Sum(); md5Sum = decryptData.getVideo().getMd5Sum();
sdkFileId = decryptData.getVideo().getSdkFileId(); sdkFileId = decryptData.getVideo().getSdkFileId();
break; break;
case "emotion": case "emotion":
md5Sum = decryptData.getEmotion().getMd5Sum(); md5Sum = decryptData.getEmotion().getMd5Sum();
sdkFileId = decryptData.getEmotion().getSdkFileId(); sdkFileId = decryptData.getEmotion().getSdkFileId();
int type = decryptData.getEmotion().getType(); int type = decryptData.getEmotion().getType();
switch (type) { switch (type) {
case 1: case 1:
suffix = ".gif"; suffix = ".gif";
break; break;
case 2: case 2:
suffix = ".png"; suffix = ".png";
break; break;
default: default:
return; return;
} }
break; break;
case "file": case "file":
md5Sum = decryptData.getFile().getMd5Sum(); md5Sum = decryptData.getFile().getMd5Sum();
suffix = "." + decryptData.getFile().getFileExt(); suffix = "." + decryptData.getFile().getFileExt();
sdkFileId = decryptData.getFile().getSdkFileId(); sdkFileId = decryptData.getFile().getSdkFileId();
break; break;
// 音频存档消息 // 音频存档消息
case "meeting_voice_call": case "meeting_voice_call":
md5Sum = decryptData.getVoiceId(); md5Sum = decryptData.getVoiceId();
sdkFileId = decryptData.getMeetingVoiceCall().getSdkFileId(); sdkFileId = decryptData.getMeetingVoiceCall().getSdkFileId();
for (WxCpChatModel.MeetingVoiceCall.DemoFileData demofiledata : for (WxCpChatModel.MeetingVoiceCall.DemoFileData demofiledata :
decryptData.getMeetingVoiceCall().getDemoFileData()) { decryptData.getMeetingVoiceCall().getDemoFileData()) {
String demoFileDataFileName = demofiledata.getFileName(); String demoFileDataFileName = demofiledata.getFileName();
suffix = demoFileDataFileName.substring(demoFileDataFileName.lastIndexOf(".") + 1); suffix = demoFileDataFileName.substring(demoFileDataFileName.lastIndexOf(".") + 1);
} }
break; break;
// 音频共享文档消息 // 音频共享文档消息
case "voip_doc_share": case "voip_doc_share":
md5Sum = decryptData.getVoipId(); md5Sum = decryptData.getVoipId();
WxCpFileItem docShare = decryptData.getVoipDocShare(); WxCpFileItem docShare = decryptData.getVoipDocShare();
String fileName = docShare.getFileName(); String fileName = docShare.getFileName();
suffix = fileName.substring(fileName.lastIndexOf(".") + 1); suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
break; break;
default: default:
continue; continue;
} }
/** /*
* 拉取媒体文件 * 拉取媒体文件
* *
* 传入一个each函数用于遍历每个分片的数据 * 传入一个each函数用于遍历每个分片的数据
*/ */
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath(); String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
String targetPath = path + "testfile/" + md5Sum + suffix; String targetPath = path + "testfile/" + md5Sum + suffix;
File file = new File(targetPath); File file = new File(targetPath);
if (!file.getParentFile().exists()) { if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
}else{ } else {
file.delete(); file.delete();
} }
cpService.getMsgAuditService().getMediaFile(chatDatas.getSdk(), sdkFileId, null, null, 1000L, data -> { cpService.getMsgAuditService().getMediaFile(chatDatas.getSdk(), sdkFileId, null, null, 1000L, data -> {
try { try {
// 大于512k的文件会分片拉取此处需要使用追加写避免后面的分片覆盖之前的数据。 // 大于512k的文件会分片拉取此处需要使用追加写避免后面的分片覆盖之前的数据。
FileOutputStream outputStream = new FileOutputStream(targetPath, true); FileOutputStream outputStream = new FileOutputStream(targetPath, true);
outputStream.write(data); outputStream.write(data);
outputStream.close(); outputStream.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
}); });
} }
Finance.DestroySdk(chatDatas.getSdk()); Finance.DestroySdk(chatDatas.getSdk());
} }

View File

@ -13,6 +13,7 @@
<webhookKey>webhook链接地址的key值</webhookKey> <webhookKey>webhook链接地址的key值</webhookKey>
<!-- 企业微信会话存档私钥windows以及linux环境sdk路径 --> <!-- 企业微信会话存档私钥windows以及linux环境sdk路径 -->
<msgAuditSecret>会话存档的secret</msgAuditSecret> <msgAuditSecret>会话存档的secret</msgAuditSecret>
<msgAuditLibPath>会话存档的lib path</msgAuditLibPath>
<msgAuditPriKey>-----BEGIN RSA PRIVATE KEY----- <msgAuditPriKey>-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCTfm5cxqfglfOV7b/Z7OtTZZoZpk2EPTvVhn/ngsfKR899xRdR MIICXAIBAAKBgQCTfm5cxqfglfOV7b/Z7OtTZZoZpk2EPTvVhn/ngsfKR899xRdR
25s4h8HkK0XhxqYdOGoAdG3Gms+DvCSY/vu3UtImf0eZSNXpKZJBUnvUVjX4ivnr 25s4h8HkK0XhxqYdOGoAdG3Gms+DvCSY/vu3UtImf0eZSNXpKZJBUnvUVjX4ivnr