1
0
mirror of synced 2025-12-24 02:57:55 +08:00

🆕 #2676 【企业微信】增加家校应用-复学码接口支持

This commit is contained in:
0katekate0
2022-06-05 22:38:00 +08:00
committed by GitHub
parent 6ce418a719
commit 0dfd7a091c
18 changed files with 592 additions and 38 deletions

View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.cp.api;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.msgaudit.*;
@@ -18,7 +17,7 @@ import java.util.List;
* 企业微信会话内容存档测试类.
* 官方文档https://developer.work.weixin.qq.com/document/path/91360
*
* @author Wang_Wong
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
* @date 2022-01-17
*/
@Slf4j
@@ -28,6 +27,7 @@ public class WxCpMsgAuditTest {
private static WxCpService cpService;
// com.binarywang.spring.starter.wxjava.cp.config.WxCpServiceAutoConfiguration
// WxCpServiceImpl.getAccessToken()
@Test
public void test() throws Exception {
@@ -39,20 +39,26 @@ public class WxCpMsgAuditTest {
cpService.setWxCpConfigStorage(config);
/**
* 配置:
* 仔细配置:
* <xml>
* <corpId>wwa3bexxXXXXXX</corpId>
* <agentId>自定义agentId</agentId>
* <corpSecret>xIpum7Yt4NMXXXXXXX</corpSecret>
* <token>2bSNqXXXXXXXX</token>
* <aesKey>MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDZuPVMyVyMvJkdSCZA893B2pggd1r95T8k2QZgz+VejtaDJCbD60mYoW1Uwwlwuqy8W78M6MmXsskn+5XunyR1WJlJGqgi0OMVGYvSfkNb9kD50fM21CGLcN1y4miL9fVNBIsvJmIUeJCNS8TioAVGFvh2EgzjqTR1gHfDwu8If7rfGmTHkPYL8hQxMg/EQ3451JOIBHSa7EQSx64SIoVWEgSDFQjGEpjUiJRfciyyz+nTSkEDgFa9hpyTS6E0c/3Q5lVDFgIwTArC19XBFKb00PbcFuLriOIsTBX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Lmg82Jr4xa8wECCgnZmwQKBgH7hirPs1/HqBrbxS726IZUf9QTmVkyOYIwzuwFYKb/+4caSah+iaXexVux0xS5tchj/6c1dQSKJmlegV8smIb6EEcko7llA1y1P5QFtXtaaRd07tTsv3BKEg496YLRjbxPzgJn6Fsoz3TTdGwESL8Q3I2h0WmVVhmr/rjr+RkWQ</aesKey>
* <corpId>ww45xxx88865xxx</corpId>
* <corpSecret>xIpum7Yt4NMXcyxdzcQ2l_46BG4QIQDR57MhA45ebIw</corpSecret> // secret
* <agentId>200000</agentId> // 会话存档的应用id
* <token></token> // 回调配置的token
* <aesKey></aesKey> // 回调配置的EncodingAESKey
*
* // 企业微信会话存档
* // 1、会话存档私钥一定要加上前缀
* // 2、仔细配置windows以及linux环境sdk路径
* <msgAuditPriKey>MIxxx893B2pggd1r95T8k2QxxxxbD6xxxxmXsskn+5XunyR1WJlJGqgi0OMVGYvSfkNb9kD50fM21CGLcN1y4miL9fVNBIsvJmIUeJCNS8TioAVGFvh2EgzjqTR1gH</msgAuditPriKey>
* <msgAuditLibPath>/www/osfile/libcrypto-1_1-x64.dll,libssl-1_1-x64.dll,libcurl-x64.dll,WeWorkFinanceSdk.dll,libWeWorkFinanceSdk_Java.so</msgAuditLibPath>
* </xml>
*
* 注意最好先配置lib开头的系统库再配置sdk类库配置绝对路径最好配置为linux路径
* windows:
* <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>
* </xml>
* Windows:
* <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>
*/
/**
@@ -84,12 +90,13 @@ public class WxCpMsgAuditTest {
// Integer publickeyVer = chatData.getPublickeyVer();
// 获取明文数据
final String chatPlainText = cpService.getMsgAuditService().getChatPlainText(chatData);
final String chatPlainText = cpService.getMsgAuditService().getChatPlainText(chatData, 2);
final WxCpChatModel wxCpChatModel = WxCpChatModel.fromJson(chatPlainText);
log.info("明文数据为:{}", wxCpChatModel.toJson());
// 获取消息数据
final WxCpChatModel decryptData = cpService.getMsgAuditService().getDecryptData(chatData);
// https://developer.work.weixin.qq.com/document/path/91774
final WxCpChatModel decryptData = cpService.getMsgAuditService().getDecryptData(chatData, 2);
log.info("获取消息数据为:{}", decryptData.toJson());
/**
@@ -435,6 +442,16 @@ public class WxCpMsgAuditTest {
WxCpGroupChat room = cpService.getMsgAuditService().getGroupChat("wrOQpTDwAAyPl84GBJ40W5eWxWtixSCA");
log.info(room.toJson());
/**
* 获取access_token
* https://developer.work.weixin.qq.com/document/path/91039
* 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);
}
}

View File

@@ -0,0 +1,72 @@
package me.chanjar.weixin.cp.api;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.school.WxCpCustomizeHealthInfo;
import me.chanjar.weixin.cp.bean.school.WxCpResultList;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
/**
* 企业微信家校应用 复学码相关接口.
* https://developer.work.weixin.qq.com/document/path/93744
*
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
* @date: 2022/5/31 9:10
*/
@Slf4j
public class WxCpSchoolTest {
private static WxCpConfigStorage wxCpConfigStorage;
private static WxCpService cpService;
@Test
public void test() throws WxErrorException {
/**
* 注意:
* 权限说明:仅复学码应用可以调用
*/
InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml");
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(inputStream);
wxCpConfigStorage = config;
cpService = new WxCpServiceImpl();
cpService.setWxCpConfigStorage(config);
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
/**
* 获取老师健康信息
* https://developer.work.weixin.qq.com/document/path/93744
*/
WxCpCustomizeHealthInfo teacherCustomizeHealthInfo = cpService.getSchoolService().getTeacherCustomizeHealthInfo(date, null, null);
log.info("teacherCustomizeHealthInfo为{}", teacherCustomizeHealthInfo.toJson());
/**
* 获取学生健康信息
* https://developer.work.weixin.qq.com/document/path/93745
*/
WxCpCustomizeHealthInfo studentCustomizeHealthInfo = cpService.getSchoolService().getStudentCustomizeHealthInfo(date, null, null);
log.info("studentCustomizeHealthInfo为{}", studentCustomizeHealthInfo.toJson());
/**
* 获取师生健康码
* https://developer.work.weixin.qq.com/document/path/93746
*/
ArrayList<String> userIds = Lists.newArrayList();
userIds.add("Wangkai");
WxCpResultList healthQrCode = cpService.getSchoolService().getHealthQrCode(userIds, 1);
log.info("healthQrCode为{}", healthQrCode.toJson());
}
}

View File

@@ -11,6 +11,18 @@
<tagId>企业号通讯录里的某个tagid</tagId>
<oauth2redirectUri>网页授权获取用户信息回调地址</oauth2redirectUri>
<webhookKey>webhook链接地址的key值</webhookKey>
<!-- 企业微信会话存档,windows以及linux环境sdk路径 -->
<!-- 企业微信会话存档,私钥,windows以及linux环境sdk路径 -->
<msgAuditPriKey>-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCTfm5cxqfglfOV7b/Z7OtTZZoZpk2EPTvVhn/ngsfKR899xRdR
25s4h8HkK0XhxqYdOGoAdG3Gms+DvCSY/vu3UtImf0eZSNXpKZJBUnvUVjX4ivnr
Ohu2Rjw6O4gPjPnZKw8voCu0Nae1YLeNvFYw48PK7QrqmpHQv1sCd/8zHwIDAQAB
AoGAResz7xgfQghjsgnEHk9BGUY7YHhlG9CZWjYJ0Ro+ksYq9vClBuGHeitk/0CC
Pq7YVVbGbVPELFd8EvNwF/UcJsMlvFis16FzNS60Hn7M/o82gI6AVhSQmocoGhNs
MIKxTnXRqqlKFbCdcSfG+hQP7syHah6Z8UhLYuEA8s/ppd0CQQD99HTSvB4P5FfL
rlKTz6w6uh4qBYl53u5cLQxCRFGgXD6HvPnEwdzQf+2LCVM1zIhyxw2Kak1U467Q
6JizEuHDTC2YljEbg/j+/AlpA/Ua5HQYnH5yD3DCK7rQyTvqE5gU+CfRbwTbLGre
fk/WJK4iqizgZobNRyUCQGB7jR5b8K7NsX7SoV7v/PFOsoj4G2W5q7LSz4GaoXGl
3F+dSlXPYHdTow3dzfgVDldEzgoThs5UWMTQvBUZch0=
-----END RSA PRIVATE KEY-----</msgAuditPriKey>
<msgAuditLibPath>/www/osfile/libcrypto-1_1-x64.dll,libssl-1_1-x64.dll,libcurl-x64.dll,WeWorkFinanceSdk.dll,libWeWorkFinanceSdk_Java.so</msgAuditLibPath>
</xml>