Skip to content

Commit

Permalink
🎨 #2598 【企业微信】修复windows系统会话存档的加载顺序
Browse files Browse the repository at this point in the history
  • Loading branch information
0katekate0 authored Apr 26, 2022
1 parent f9cf8ca commit 010c184
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
6 changes: 4 additions & 2 deletions weixin-java-cp/src/main/java/com/tencent/wework/Finance.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
* 注意:
* 此类必须配置在com.tencent.wework路径底下,否则会报错:
Expand Down Expand Up @@ -147,7 +149,7 @@ public static boolean isWindows() {
* @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);
Expand All @@ -173,7 +175,7 @@ public Finance(String[] libFiles, String prefixPath) {
* @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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

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.*;
Expand All @@ -39,20 +42,40 @@ public WxCpChatDatas getChatDatas(long seq, @NonNull long limit, String proxy, S
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(",");
if (libFiles.length <= 0) {
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());
Expand Down

0 comments on commit 010c184

Please sign in to comment.