8000 【企业微信】增加家校应用-复学码接口支持 by 0katekate0 · Pull Request #2676 · binarywang/WxJava · GitHub
[go: up one dir, main page]

Skip to content

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

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
merged 3 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
【企业微信】新增会话存档私钥属性,修复#2678
  • Loading branch information
0katekate0 committed Jun 1, 2022
commit dd1a7a546838d624bce4555af235afea209c6674
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public class WxCpProperties {
* 微信企业号应用 EncodingAESKey
*/
private String aesKey;
/**
* 微信企业号应用 会话存档私钥
*/
private String msgAuditPriKey;
/**
* 微信企业号应用 会话存档类库路径
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ protected WxCpDefaultConfigImpl config(WxCpDefaultConfigImpl config, WxCpPropert
String token = properties.getToken();
Integer agentId = properties.getAgentId();
String aesKey = properties.getAesKey();
// 企业微信,会话存档路径
// 企业微信,私钥,会话存档路径
String msgAuditPriKey = properties.getMsgAuditPriKey();
String msgAuditLibPath = properties.getMsgAuditLibPath();

config.setCorpId(corpId);
Expand All @@ -32,6 +33,9 @@ protected WxCpDefaultConfigImpl config(WxCpDefaultConfigImpl config, WxCpPropert
if (StringUtils.isNotBlank(aesKey)) {
config.setAesKey(aesKey);
}
if (StringUtils.isNotBlank(msgAuditPriKey)) {
config.setMsgAuditPriKey(msgAuditPriKey);
}
if (StringUtils.isNotBlank(msgAuditLibPath)) {
config.setMsgAuditLibPath(msgAuditLibPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public WxCpChatDatas getChatDatas(long seq, @NonNull long limit, String proxy, S
Finance.FreeSlice(slice);
WxCpChatDatas chatDatas = WxCpChatDatas.fromJson(content);
if (chatDatas.getErrCode().intValue() != 0) {
Finance.DestroySingletonSDK(sdk);
throw new WxErrorException(chatDatas.toJson());
}

Expand All @@ -110,14 +111,19 @@ public WxCpChatModel getDecryptData(@NonNull WxCpChatDatas.WxCpChatData chatData
}

public String decryptChatData(WxCpChatDatas.WxCpChatData chatData) throws Exception {
// 企业获取的会话内容将用公钥加密,企业可用自行保存的私钥解开会话内容数据,aeskey不能为空
String priKey = cpService.getWxCpConfigStorage().getAesKey();
/**
* 企业获取的会话内容,使用企业自行配置的消息加密公钥进行加密,企业可用自行保存的私钥解开会话内容数据。
* msgAuditPriKey 会话存档私钥不能为空
*/
String priKey = cpService.getWxCpConfigStorage().getMsgAuditPriKey();
if (StringUtils.isEmpty(priKey)) {
throw new WxErrorException("请配置会话存档私钥【aesKey】");
throw new WxErrorException("请配置会话存档私钥【msgAuditPriKey】");
}

String decryptByPriKey = WxCpCryptUtil.decryptByPriKey(chatData.getEncryptRandomKey(), priKey);
// 每次使用DecryptData解密会话存档前需要调用NewSlice获取一个slice,在使用完slice中数据后,还需要调用FreeSlice释放。
/**
* 每次使用DecryptData解密会话存档前需要调用NewSlice获取一个slice,在使用完slice中数据后,还需要调用FreeSlice释放。
*/
long sdk = Finance.SingletonSDK();
long msg = Finance.NewSlice();

Expand All @@ -128,7 +134,9 @@ public String decryptChatData(WxCpChatDatas.WxCpChatData chatData) throws Except
throw new WxErrorException("msg err ret " + ret);
}

// 明文
/**
* 明文
*/
String plainText = Finance.GetContentFromSlice(msg);
Finance.FreeSlice(msg);
return plainText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ public interface WxCpConfigStorage {
*/
String getAesKey();

/**
* 企微会话存档私钥
*
* @return
*/
String getMsgAuditPriKey();

/**
* 获取企微会话存档系统库 绝对路径
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
private volatile String token;
private volatile String aesKey;
private volatile long expiresTime;
/**
* 会话存档私钥以及sdk路径
*/
private volatile String msgAuditPriKey;
private volatile String msgAuditLibPath;
private volatile String oauth2redirectUri;
private volatile String httpProxyHost;
Expand Down Expand Up @@ -257,6 +261,11 @@ public String getAesKey() {
return this.aesKey;
}

@Override
public String getMsgAuditPriKey() {
return this.msgAuditPriKey;
}

@Override
public String getMsgAuditLibPath() {
return this.msgAuditLibPath;
Expand Down Expand Up @@ -294,6 +303,15 @@ public void setMsgAuditLibPath(String msgAuditLibPath) {
this.msgAuditLibPath = msgAuditLibPath;
}

/**
* 设置会话存档私钥
*
* @param msgAuditPriKey 会话存档私钥
*/
public void setMsgAuditPriKey(String msgAuditPriKey) {
this.msgAuditPriKey = msgAuditPriKey;
}

@Override
public String getOauth2redirectUri() {
return this.oauth2redirectUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
private volatile String token;
private volatile String aesKey;
private volatile Integer agentId;
private volatile String msgAuditPriKey;
private volatile String msgAuditLibPath;
private volatile String oauth2redirectUri;
private volatile String httpProxyHost;
Expand Down Expand Up @@ -321,6 +322,11 @@ public String getAesKey() {
return this.aesKey;
}

@Override
public String getMsgAuditPriKey() {
return this.msgAuditPriKey;
}

@Override
public String getMsgAuditLibPath() {
return this.msgAuditLibPath;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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 {

Expand All @@ -39,20 +39,24 @@ public void test() throws Exception {
cpService.setWxCpConfigStorage(config);

/**
* 配置
* 仔细配置
* <xml>
* <corpId>wwa3bexxXXXXXX</corpId>
* <agentId>自定义agentId</agentId>
* <corpSecret>xIpum7Yt4NMXXXXXXX</corpSecret>
* <token>2bSNqXXXXXXXX</token>
* <aesKey>MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDZuPVMyVyMvJkdSCZA893B2pggd1r95T8k2QZgz+VejtaDJCbD60mYoW1Uwwlwuqy8W78M6MmXsskn+5XunyR1WJlJGqgi0OMVGYvSfkNb9kD50fM21CGLcN1y4miL9fVNBIsvJmIUeJCNS8TioAVGFvh2EgzjqTR1gHfDwu8If7rfGmTHkPYL8hQxMg/EQ3451JOIBHSa7EQSx64SIoVWEgSDFQjGEpjUiJRfciyyz+nTSkEDgFa9hpyTS6E0c/3Q5lVDFgIwTArC19XBFKb00PbcFuLriOIsTBX4K9XWBtefVXowAdqUVQDH6BNUIK7/iVPQ4L3p+F5DBOrx8I/7AgMBAAECggEBAK53C/nwEX2lU3ynaB/8SuMga274ta1mmmbIkdfaQA65nyOPQJEWZe8szBN0BoiSzgBR9JI/p+srlQ25CLgiRnDSAmMWPU1I3e72fZi7HPcAKakGmEKDUi4OzyVUUDp3aY3B6lZqB4Yn5o2S/b4sRI2ZspfKdxGncSYHP/Far3i6hzq2C1hbyYM6HkHPcrQ+z6ir6GxjLvHXssVJ+/C0HMsVIQAWPyEGbzWozS+EswmQ+itk+7cewiLWbaCSp6lsjHKGTxJwCxRes0nUt2SfkLnIUkDLxB7c6zDQJCn1K2UckCjNBlCWl+oDWLkLQ7UAJ+4IYYSslR4wXzRg8PplW8ECgYEA9VlEprEoG2oSn3HXIMFg0MANViQe89QJQdwd7D5h4FLxXQLItxqmZj77iktlzlICcK9WT9WHRY1AOilsuMaDmY0VH3Z8r/X9BU712KFJqMYH5CNxrqHOya3BG+CclEKToaOTmo9kiOpFAMNSuuWs6gvILJ0CKEmSUo5G9fJu4fkCgYEA4yypHoRZIP0mDdVDeVtdHHcq5JdWF6xbAFs4P57VHG1KDMWouk3IHSeO279gEIwcBAdaLcMMgFfzyQBwcisxjC76oyoZnbSntB7ZMFdPqALKfxIdleLilbASuRKesVAF+OgOx/yp/aQUeLG2pVBivgn2TyGMwjnxznTh9vh+vpMCgYEAmOva7krdRLkIgnjiLXhab8JEjbxVzoQKgRJBVE5NkxQffGmP0RC7Rl9bSQdVnRNgkfu3QGtGtQMlVRscuM6Cl+JnmASyErqvye89LJja4GcN5BRzdvVDflDeXBHThlU4zza1eVCGyQ+7ko4rsnIVJIvTaHs0LQguO2aStBk3I4ECgYAyBsO3VK3L9fNLWItjThtTCWsIq8rpq6reiTf5yqBjgi2sYlqlrDtFMFDlU190RWZl/Lh/G1TFbpjgypf4jEp89Ft9UugRMpc7sw9g9dk0xmiRUwvw1eXP0NZOqysHIPgvt+qJX7qPgHKBoaD3Bpy3/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
*
* 注意:最好先配置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>
* // 企业微信会话存档,私钥,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>
*/

/**
Expand Down Expand Up @@ -435,6 +439,15 @@ public void test() throws Exception {
WxCpGroupChat room = cpService.getMsgAuditService().getGroupChat("wrOQpTDwAAyPl84GBJ40W5eWxWtixSCA");
log.info(room.toJson());


/**
* 获取access_token
* https://developer.work.weixin.qq.com/document/path/91039
*/
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);


}

}
0