1
0
mirror of synced 2026-02-22 22:08:00 +08:00

🎨 #2773【企业微信】优化会话存档,增加会话存档的多企业支持

This commit is contained in:
0katekate0
2022-08-12 11:42:43 +08:00
committed by GitHub
parent 53d332190c
commit fe49e5af11
7 changed files with 91 additions and 28 deletions

View File

@@ -3,10 +3,13 @@ package me.chanjar.weixin.cp.api;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.XmlUtils;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.living.*;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
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.Test;
@@ -18,7 +21,8 @@ import java.util.Date;
* 企业微信直播测试类.
* 官方文档https://open.work.weixin.qq.com/api/doc/90000/90135/93632
*
* @author Wang_Wong
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
* @date 2021-12-23
*/
@Slf4j
public class WxCpLivingTest {
@@ -36,6 +40,31 @@ public class WxCpLivingTest {
wxCpService = new WxCpServiceImpl();
wxCpService.setWxCpConfigStorage(config);
/**
* 直播回调事件
* 一场完整的直播,会经历 预约直播/开始直播/结束直播 等一系列状态变更。
* 为了让企业实时获取直播的动态当直播状态变更后企业微信会将该变更推送到开发者配置的回调URL。
* 只有通过接口创建的预约/立即直播才会回调。
*
* 请注意只有用企业微信api创建的直播才能收到回调且调用创建直播接口的应用要配置好回调url。
*/
String livingXml = "<xml>\n" +
" <ToUserName><![CDATA[toUser]]></ToUserName>\n" +
" <FromUserName><![CDATA[fromUser]]></FromUserName> \n" +
" <CreateTime>1348831860</CreateTime>\n" +
" <MsgType><![CDATA[event]]></MsgType>\n" +
" <Event><![CDATA[living_status_change]]></Event>\n" +
" <LivingId><![CDATA[LivingId]]></LivingId>\n" +
" <Status>1</Status>\n" +
" <AgentID>1</AgentID>\n" +
"</xml>";
final WxCpXmlMessage livingXmlMsg = XStreamTransformer.fromXml(WxCpXmlMessage.class, livingXml);
livingXmlMsg.setAllFieldsMap(XmlUtils.xml2Map(livingXml));
log.info("livingXmlMsg:{}", JSON.toString(livingXmlMsg));
/**
* 测试创建直播
*/

View File

@@ -1,6 +1,7 @@
package me.chanjar.weixin.cp.api;
import com.google.common.collect.Lists;
import com.tencent.wework.Finance;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.util.XmlUtils;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
@@ -114,7 +115,23 @@ public class WxCpMsgAuditTest {
* <msgAuditLibPath>D:/WorkSpace/libcrypto-1_1-x64.dll,libssl-1_1-x64.dll,libcurl-x64.dll,WeWorkFinanceSdk.dll,libWeWorkFinanceSdk_Java.so</msgAuditLibPath>
* Linux:
* <msgAuditLibPath>/www/osfile/work_msg_storage/libcrypto-1_1-x64.dll,libssl-1_1-x64.dll,libcurl-x64.dll,WeWorkFinanceSdk.dll,libWeWorkFinanceSdk_Java.so</msgAuditLibPath>
*/
*
*
* yml配置支持多个corpId
* wx:
* cp:
* appConfigs:
* - agentId: 10001 #客户联系
* corpId: xxxxxxxxxxx
* secret: T5fTj1n-sBAT4rKNW5c9IYNfPdXZxxxxxxxxxxx
* token: 2bSNqTcLtxxxxxxxxxxx
* aesKey: AXazu2Xyw44SNY1x8go2phn9p9B2xxxxxxxxxxx
* - agentId: 10002 #会话内容存档
* corpId: xxxxxxxxxxx
* secret: xIpum7Yt4NMXcyxdzcQ2l_46BG4Qxxxxxxxxxxx
* token:
* aesKey:
* /
/**
* 建议放到redis本次请求获取消息记录开始的seq值。首次访问填写0非首次使用上次企业微信返回的最大seq。允许从任意seq重入拉取。
@@ -145,13 +162,13 @@ public class WxCpMsgAuditTest {
// Integer publickeyVer = chatData.getPublickeyVer();
// 获取明文数据
final String chatPlainText = cpService.getMsgAuditService().getChatPlainText(chatData, 2);
final String chatPlainText = cpService.getMsgAuditService().getChatPlainText(chatDatas.getSdk(), chatData, 2);
final WxCpChatModel wxCpChatModel = WxCpChatModel.fromJson(chatPlainText);
log.info("明文数据为:{}", wxCpChatModel.toJson());
// 获取消息数据
// https://developer.work.weixin.qq.com/document/path/91774
final WxCpChatModel decryptData = cpService.getMsgAuditService().getDecryptData(chatData, 2);
final WxCpChatModel decryptData = cpService.getMsgAuditService().getDecryptData(chatDatas.getSdk(), chatData, 2);
log.info("获取消息数据为:{}", decryptData.toJson());
/**
@@ -239,13 +256,15 @@ public class WxCpMsgAuditTest {
* 3、比如可以上传到阿里云oss或者腾讯云cos
*/
String targetPath = path + md5Sum + suffix;
cpService.getMsgAuditService().getMediaFile(sdkFileId, null, null, 1000L, targetPath);
cpService.getMsgAuditService().getMediaFile(chatDatas.getSdk(), sdkFileId, null, null, 1000L, targetPath);
}
}
}
// 注意:
// 当此批次数据拉取完毕后可以释放此次sdk
log.info("释放sdk {}", chatDatas.getSdk());
Finance.DestroySdk(chatDatas.getSdk());
}