Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 9.1k
企业微信会话存档获取媒体数据,添加传入lambda函数的方法来遍历媒体数据分片。#2858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMsgAuditService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 23 additions & 5 deletions
28 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMsgAuditServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 117 additions & 10 deletions
127 weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMsgAuditTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,8 +12,11 @@ | ||
| import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage; | ||
| import me.chanjar.weixin.cp.util.xml.XStreamTransformer; | ||
| import org.eclipse.jetty.util.ajax.JSON; | ||
| import org.testng.annotations.BeforeTest; | ||
| import org.testng.annotations.Test; | ||
| import java.io.File; | ||
| import java.io.FileOutputStream; | ||
| import java.io.InputStream; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| @@ -39,17 +42,21 @@ public class WxCpMsgAuditTest { | ||
| */ | ||
| // com.binarywang.spring.starter.wxjava.cp.config.WxCpServiceAutoConfiguration | ||
| // WxCpServiceImpl.getAccessToken() | ||
| @Test | ||
| public void test() throws Exception { | ||
| InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml"); | ||
| WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(inputStream); | ||
| wxCpConfigStorage = config; | ||
| cpService = new WxCpServiceImpl(); | ||
| cpService.setWxCpConfigStorage(config); | ||
| @BeforeTest | ||
| private void initCpservice() { | ||
| if(cpService == null) { | ||
| InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml"); | ||
| WxCpDemoInMemoryConfigStorage config = 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"); | ||
binarywang marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| wxCpConfigStorage = config; | ||
| cpService = new WxCpServiceImpl(); | ||
| cpService.setWxCpConfigStorage(config); | ||
| } | ||
| } | ||
| @Test | ||
| public void test() throws Exception { | ||
| /** | ||
| * 客户同意进行聊天内容存档事件回调 | ||
| * 配置了客户联系功能的成员添加外部联系人同意进行聊天内容存档时,回调该事件。 | ||
| @@ -644,9 +651,109 @@ public void test() throws Exception { | ||
| * https://www.jianshu.com/p/dde171887d63 | ||
| */ | ||
| String getUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s"; | ||
| String data = cpService.get(String.format(getUrl, config.getCorpId(), config.getCorpSecret()), null); | ||
| String data = cpService.get(String.format(getUrl, wxCpConfigStorage.getCorpId(), wxCpConfigStorage.getCorpSecret()), null); | ||
| } | ||
| @Test | ||
| public void testGetMediaFile() throws Exception { | ||
| WxCpMsgAuditService msgAuditService = cpService.getMsgAuditService(); | ||
| WxCpChatDatas chatDatas = msgAuditService.getChatDatas(0L, 100L, null, null, 10); | ||
| for (WxCpChatDatas.WxCpChatData chatDatum : chatDatas.getChatData()) { | ||
| WxCpChatModel decryptData = msgAuditService.getDecryptData(chatDatas.getSdk(), chatDatum, 2); | ||
| // 文件后缀 | ||
| String suffix = ""; | ||
| // 文件名md5 | ||
| String md5Sum = ""; | ||
| // sdkFileId | ||
| String sdkFileId = ""; | ||
| String msgType = decryptData.getMsgType(); | ||
| if(msgType == null ) msgType = ""; | ||
| switch (msgType) { | ||
| case "image": | ||
| suffix = ".jpg"; | ||
| md5Sum = decryptData.getImage().getMd5Sum(); | ||
| sdkFileId = decryptData.getImage().getSdkFileId(); | ||
| break; | ||
| case "voice": | ||
| suffix = ".amr"; | ||
| md5Sum = decryptData.getVoice().getMd5Sum(); | ||
| sdkFileId = decryptData.getVoice().getSdkFileId(); | ||
| break; | ||
| case "video": | ||
| suffix = ".mp4"; | ||
| md5Sum = decryptData.getVideo().getMd5Sum(); | ||
| sdkFileId = decryptData.getVideo().getSdkFileId(); | ||
| break; | ||
| case "emotion": | ||
| md5Sum = decryptData.getEmotion().getMd5Sum(); | ||
| sdkFileId = decryptData.getEmotion().getSdkFileId(); | ||
| int type = decryptData.getEmotion().getType(); | ||
| switch (type) { | ||
| case 1: | ||
| suffix = ".gif"; | ||
| break; | ||
| case 2: | ||
| suffix = ".png"; | ||
| break; | ||
| default: | ||
| return; | ||
| } | ||
| break; | ||
| case "file": | ||
| md5Sum = decryptData.getFile().getMd5Sum(); | ||
| suffix = "." + decryptData.getFile().getFileExt(); | ||
| sdkFileId = decryptData.getFile().getSdkFileId(); | ||
| break; | ||
| // 音频存档消息 | ||
| case "meeting_voice_call": | ||
| md5Sum = decryptData.getVoiceId(); | ||
| sdkFileId = decryptData.getMeetingVoiceCall().getSdkFileId(); | ||
| for (WxCpChatModel.MeetingVoiceCall.DemoFileData demofiledata : | ||
| decryptData.getMeetingVoiceCall().getDemoFileData()) { | ||
| String demoFileDataFileName = demofiledata.getFileName(); | ||
| suffix = demoFileDataFileName.substring(demoFileDataFileName.lastIndexOf(".") + 1); | ||
| } | ||
| break; | ||
| // 音频共享文档消息 | ||
| case "voip_doc_share": | ||
| md5Sum = decryptData.getVoipId(); | ||
| WxCpFileItem docShare = decryptData.getVoipDocShare(); | ||
| String fileName = docShare.getFileName(); | ||
| suffix = fileName.substring(fileName.lastIndexOf(".") + 1); | ||
| break; | ||
| default: | ||
| continue; | ||
| } | ||
| /** | ||
| * 拉取媒体文件 | ||
| * | ||
| * 传入一个each函数,用于遍历每个分片的数据 | ||
| */ | ||
| String path = Thread.currentThread().getContextClassLoader().getResource("").getPath(); | ||
| String targetPath = path + "testfile/" + md5Sum + suffix; | ||
| File file = new File(targetPath); | ||
| if (!file.getParentFile().exists()) { | ||
| file.getParentFile().mkdirs(); | ||
| }else{ | ||
| file.delete(); | ||
| } | ||
| cpService.getMsgAuditService().getMediaFile(chatDatas.getSdk(), sdkFileId, null, null, 1000L, data -> { | ||
| try { | ||
| // 大于512k的文件会分片拉取,此处需要使用追加写,避免后面的分片覆盖之前的数据。 | ||
| FileOutputStream outputStream = new FileOutputStream(targetPath, true); | ||
| outputStream.write(data); | ||
| outputStream.close(); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
| }); | ||
| } | ||
| Finance.DestroySdk(chatDatas.getSdk()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RESOURCE_LEAK: resource of type
java.io.FileOutputStreamacquired tooutputStreamby call toFileOutputStream(...)at line 188 is not released after line 191.Note: potential exception at line 189
ℹ️ Learn about @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore@sonatype-lift ignoreall@sonatype-lift exclude <file|issue|path|tool>file|issue|path|toolfrom Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]