Skip to content

Commit 010c184

Browse files
authored
🎨 #2598 【企业微信】修复windows系统会话存档的加载顺序
1 parent f9cf8ca commit 010c184

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

Diff for: weixin-java-cp/src/main/java/com/tencent/wework/Finance.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import lombok.extern.slf4j.Slf4j;
44

5+
import java.util.List;
6+
57
/**
68
* 注意:
79
* 此类必须配置在com.tencent.wework路径底下,否则会报错:
@@ -147,7 +149,7 @@ public static boolean isWindows() {
147149
* @param libFiles 类库配置文件
148150
* @param prefixPath 类库文件的前缀路径
149151
*/
150-
public Finance(String[] libFiles, String prefixPath) {
152+
public Finance(List<String> libFiles, String prefixPath) {
151153
boolean isWindows = Finance.isWindows();
152154
for (String file : libFiles) {
153155
String suffix = file.substring(file.lastIndexOf(".") + 1);
@@ -173,7 +175,7 @@ public Finance(String[] libFiles, String prefixPath) {
173175
* @param prefixPath
174176
* @return
175177
*/
176-
public synchronized static Finance loadingLibraries(String[] libFiles, String prefixPath) {
178+
public synchronized static Finance loadingLibraries(List<String> libFiles, String prefixPath) {
177179
if (finance != null) {
178180
return finance;
179181
}

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMsgAuditServiceImpl.java

+28-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import java.io.File;
1919
import java.io.FileOutputStream;
20+
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.LinkedList;
2023
import java.util.List;
2124

2225
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.MsgAudit.*;
@@ -39,20 +42,40 @@ public WxCpChatDatas getChatDatas(long seq, @NonNull long limit, String proxy, S
3942
throw new WxErrorException("请配置会话存档sdk文件的路径,不要配错了!!");
4043
}
4144

45+
/**
46+
* 完整的文件库路径:
47+
*
48+
* /www/osfile/libcrypto-1_1-x64.dll,libssl-1_1-x64.dll,libcurl-x64.dll,WeWorkFinanceSdk.dll,libWeWorkFinanceSdk_Java.so
49+
*/
4250
// 替换斜杠
4351
String replacePath = configPath.replace("\\", "/");
44-
// 所有的后缀文件
45-
String suffixFiles = replacePath.substring(replacePath.lastIndexOf("/") + 1);
46-
// 获取的前缀路径
47-
String prefixPath = replacePath.substring(0, replacePath.lastIndexOf("/") + 1);
52+
// 获取最后一个斜杠的下标,用作分割路径
53+
int lastIndex = replacePath.lastIndexOf("/") + 1;
54+
// 获取完整路径的前缀路径
55+
String prefixPath = replacePath.substring(0, lastIndex);
56+
// 获取后缀的所有文件,目的遍历所有文件
57+
String suffixFiles = replacePath.substring(lastIndex);
4858

4959
// 包含so文件
5060
String[] libFiles = suffixFiles.split(",");
5161
if (libFiles.length <= 0) {
5262
throw new WxErrorException("请仔细配置会话存档文件路径!!");
5363
}
5464

55-
Finance.loadingLibraries(libFiles, prefixPath);
65+
List<String> libList = Arrays.asList(libFiles);
66+
// 判断windows系统会话存档sdk中dll的加载,因为会互相依赖所以是有顺序的,否则会导致无法加载sdk #2598
67+
List<String> osLib = new LinkedList();
68+
List<String> fileLib = new ArrayList();
69+
libList.stream().forEach(s -> {
70+
if (s.contains("lib")) {
71+
osLib.add(s);
72+
} else {
73+
fileLib.add(s);
74+
}
75+
});
76+
osLib.addAll(fileLib);
77+
78+
Finance.loadingLibraries(osLib, prefixPath);
5679
long sdk = Finance.SingletonSDK();
5780

5881
long ret = Finance.Init(sdk, cpService.getWxCpConfigStorage().getCorpId(), cpService.getWxCpConfigStorage().getCorpSecret());

0 commit comments

Comments
 (0)