1
0
mirror of synced 2026-02-10 21:57:53 +08:00

修复代码审查反馈:完善SDK自动销毁逻辑和测试代码

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-14 04:03:29 +00:00
parent 6e3039cd88
commit 7d637399df
4 changed files with 28 additions and 4 deletions

View File

@@ -304,7 +304,7 @@ public interface WxCpConfigStorage {
/**
* 减少会话存档SDK的引用计数
* 当引用计数降为0时自动销毁SDK
* 当引用计数降为0时自动销毁SDK以释放资源
*
* @param sdk sdk id
* @return 减少后的引用计数如果返回0表示SDK已被销毁

View File

@@ -1,5 +1,6 @@
package me.chanjar.weixin.cp.config.impl;
import com.tencent.wework.Finance;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
@@ -497,7 +498,14 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
@Override
public synchronized int decrementMsgAuditSdkRefCount(long sdk) {
if (this.msgAuditSdk == sdk && this.msgAuditSdkRefCount > 0) {
return --this.msgAuditSdkRefCount;
int newCount = --this.msgAuditSdkRefCount;
// 当引用计数降为0时自动销毁SDK以释放资源
if (newCount == 0) {
Finance.DestroySdk(sdk);
this.msgAuditSdk = 0;
this.msgAuditSdkExpiresTime = 0;
}
return newCount;
}
return 0;
}

View File

@@ -1,5 +1,6 @@
package me.chanjar.weixin.cp.config.impl;
import com.tencent.wework.Finance;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
@@ -515,7 +516,14 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
@Override
public synchronized int decrementMsgAuditSdkRefCount(long sdk) {
if (this.msgAuditSdk == sdk && this.msgAuditSdkRefCount > 0) {
return --this.msgAuditSdkRefCount;
int newCount = --this.msgAuditSdkRefCount;
// 当引用计数降为0时自动销毁SDK以释放资源
if (newCount == 0) {
Finance.DestroySdk(sdk);
this.msgAuditSdk = 0;
this.msgAuditSdkExpiresTime = 0;
}
return newCount;
}
return 0;
}

View File

@@ -803,15 +803,23 @@ public class WxCpMsgAuditTest {
suffix = "." + decryptData.getFile().getFileExt();
sdkFileId = decryptData.getFile().getSdkFileId();
break;
default:
// 未知消息类型,跳过处理
continue;
}
// 测试新的downloadMediaFile方法 - 不需要传入SDK
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
String targetPath = path + "testfile-new/" + md5Sum + suffix;
File file = new File(targetPath);
// 确保父目录存在
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
} else {
}
// 删除已存在的文件
if (file.exists()) {
file.delete();
}