File tree Expand file tree Collapse file tree 4 files changed +28
-4
lines changed
main/java/me/chanjar/weixin/cp/config
test/java/me/chanjar/weixin/cp/api Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -304,7 +304,7 @@ public interface WxCpConfigStorage {
304304
305305 /**
306306 * 减少会话存档SDK的引用计数
307- * 当引用计数降为0时,自动销毁SDK
307+ * 当引用计数降为0时,自动销毁SDK以释放资源
308308 *
309309 * @param sdk sdk id
310310 * @return 减少后的引用计数,如果返回0表示SDK已被销毁
Original file line number Diff line number Diff line change 11package me .chanjar .weixin .cp .config .impl ;
22
3+ import com .tencent .wework .Finance ;
34import me .chanjar .weixin .common .bean .WxAccessToken ;
45import me .chanjar .weixin .common .util .http .apache .ApacheHttpClientBuilder ;
56import me .chanjar .weixin .cp .config .WxCpConfigStorage ;
@@ -497,7 +498,14 @@ public synchronized int incrementMsgAuditSdkRefCount(long sdk) {
497498 @ Override
498499 public synchronized int decrementMsgAuditSdkRefCount (long sdk ) {
499500 if (this .msgAuditSdk == sdk && this .msgAuditSdkRefCount > 0 ) {
500- return --this .msgAuditSdkRefCount ;
501+ int newCount = --this .msgAuditSdkRefCount ;
502+ // 当引用计数降为0时,自动销毁SDK以释放资源
503+ if (newCount == 0 ) {
504+ Finance .DestroySdk (sdk );
505+ this .msgAuditSdk = 0 ;
506+ this .msgAuditSdkExpiresTime = 0 ;
507+ }
508+ return newCount ;
501509 }
502510 return 0 ;
503511 }
Original file line number Diff line number Diff line change 11package me .chanjar .weixin .cp .config .impl ;
22
3+ import com .tencent .wework .Finance ;
34import me .chanjar .weixin .common .bean .WxAccessToken ;
45import me .chanjar .weixin .common .util .http .apache .ApacheHttpClientBuilder ;
56import me .chanjar .weixin .cp .config .WxCpConfigStorage ;
@@ -515,7 +516,14 @@ public synchronized int incrementMsgAuditSdkRefCount(long sdk) {
515516 @ Override
516517 public synchronized int decrementMsgAuditSdkRefCount (long sdk ) {
517518 if (this .msgAuditSdk == sdk && this .msgAuditSdkRefCount > 0 ) {
518- return --this .msgAuditSdkRefCount ;
519+ int newCount = --this .msgAuditSdkRefCount ;
520+ // 当引用计数降为0时,自动销毁SDK以释放资源
521+ if (newCount == 0 ) {
522+ Finance .DestroySdk (sdk );
523+ this .msgAuditSdk = 0 ;
524+ this .msgAuditSdkExpiresTime = 0 ;
525+ }
526+ return newCount ;
519527 }
520528 return 0 ;
521529 }
Original file line number Diff line number Diff line change @@ -803,15 +803,23 @@ public void testNewSafeApi() throws Exception {
803803 suffix = "." + decryptData .getFile ().getFileExt ();
804804 sdkFileId = decryptData .getFile ().getSdkFileId ();
805805 break ;
806+ default :
807+ // 未知消息类型,跳过处理
808+ continue ;
806809 }
807810
808811 // 测试新的downloadMediaFile方法 - 不需要传入SDK
809812 String path = Thread .currentThread ().getContextClassLoader ().getResource ("" ).getPath ();
810813 String targetPath = path + "testfile-new/" + md5Sum + suffix ;
811814 File file = new File (targetPath );
815+
816+ // 确保父目录存在
812817 if (!file .getParentFile ().exists ()) {
813818 file .getParentFile ().mkdirs ();
814- } else {
819+ }
820+
821+ // 删除已存在的文件
822+ if (file .exists ()) {
815823 file .delete ();
816824 }
817825
You can’t perform that action at this time.
0 commit comments