🎨 #2598 【企业微信】修复windows系统会话存档的加载顺序

This commit is contained in:
0katekate0 2022-04-26 11:30:44 +08:00 committed by GitHub
parent f9cf8ca1de
commit 010c184caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 7 deletions

View File

@ -2,6 +2,8 @@ package com.tencent.wework;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
* 注意
* 此类必须配置在com.tencent.wework路径底下否则会报错
@ -147,7 +149,7 @@ public class Finance {
* @param libFiles 类库配置文件
* @param prefixPath 类库文件的前缀路径
*/
public Finance(String[] libFiles, String prefixPath) {
public Finance(List<String> libFiles, String prefixPath) {
boolean isWindows = Finance.isWindows();
for (String file : libFiles) {
String suffix = file.substring(file.lastIndexOf(".") + 1);
@ -173,7 +175,7 @@ public class Finance {
* @param prefixPath
* @return
*/
public synchronized static Finance loadingLibraries(String[] libFiles, String prefixPath) {
public synchronized static Finance loadingLibraries(List<String> libFiles, String prefixPath) {
if (finance != null) {
return finance;
}

View File

@ -17,6 +17,9 @@ import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.MsgAudit.*;
@ -39,12 +42,19 @@ public class WxCpMsgAuditServiceImpl implements WxCpMsgAuditService {
throw new WxErrorException("请配置会话存档sdk文件的路径不要配错了");
}
/**
* 完整的文件库路径
*
* /www/osfile/libcrypto-1_1-x64.dll,libssl-1_1-x64.dll,libcurl-x64.dll,WeWorkFinanceSdk.dll,libWeWorkFinanceSdk_Java.so
*/
// 替换斜杠
String replacePath = configPath.replace("\\", "/");
// 所有的后缀文件
String suffixFiles = replacePath.substring(replacePath.lastIndexOf("/") + 1);
// 获取的前缀路径
String prefixPath = replacePath.substring(0, replacePath.lastIndexOf("/") + 1);
// 获取最后一个斜杠的下标用作分割路径
int lastIndex = replacePath.lastIndexOf("/") + 1;
// 获取完整路径的前缀路径
String prefixPath = replacePath.substring(0, lastIndex);
// 获取后缀的所有文件目的遍历所有文件
String suffixFiles = replacePath.substring(lastIndex);
// 包含so文件
String[] libFiles = suffixFiles.split(",");
@ -52,7 +62,20 @@ public class WxCpMsgAuditServiceImpl implements WxCpMsgAuditService {
throw new WxErrorException("请仔细配置会话存档文件路径!!");
}
Finance.loadingLibraries(libFiles, prefixPath);
List<String> libList = Arrays.asList(libFiles);
// 判断windows系统会话存档sdk中dll的加载因为会互相依赖所以是有顺序的否则会导致无法加载sdk #2598
List<String> osLib = new LinkedList();
List<String> fileLib = new ArrayList();
libList.stream().forEach(s -> {
if (s.contains("lib")) {
osLib.add(s);
} else {
fileLib.add(s);
}
});
osLib.addAll(fileLib);
Finance.loadingLibraries(osLib, prefixPath);
long sdk = Finance.SingletonSDK();
long ret = Finance.Init(sdk, cpService.getWxCpConfigStorage().getCorpId(), cpService.getWxCpConfigStorage().getCorpSecret());