Skip to content

Commit

Permalink
🐛 #1600 修复无法切换到初始公众号配置的问题并完善了removeConfigStorage方法
Browse files Browse the repository at this point in the history
* 修复无法切换到初始公众号配置的问题

* 完善removeConfigStorage
  • Loading branch information
rain7fine11 authored Jun 3, 2020
1 parent 1c60839 commit b52e676
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ protected String extractAccessToken(String resultContent) throws WxErrorExceptio

@Override
public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) {
final String defaultMpId = WxMpConfigStorageHolder.get();
final String defaultMpId = wxConfigProvider.getAppId();
this.setMultiConfigStorages(ImmutableMap.of(defaultMpId, wxConfigProvider), defaultMpId);
}

Expand All @@ -440,6 +440,18 @@ public void addConfigStorage(String mpId, WxMpConfigStorage configStorages) {
@Override
public void removeConfigStorage(String mpId) {
synchronized (this) {
if (this.configStorageMap.size() == 1) {
this.configStorageMap.remove(mpId);
log.warn("已删除最后一个公众号配置:{},须立即使用setWxMpConfigStorage或setMultiConfigStorages添加配置", mpId);
return;
}
if (WxMpConfigStorageHolder.get().equals(mpId)) {
this.configStorageMap.remove(mpId);
final String defaultMpId = this.configStorageMap.keySet().iterator().next();
WxMpConfigStorageHolder.set(defaultMpId);
log.warn("已删除默认公众号配置,公众号【{}】被设为默认配置", defaultMpId);
return;
}
this.configStorageMap.remove(mpId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void testSwitchover() {
assertTrue(this.wxService.switchover("another"));
assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another");
assertFalse(this.wxService.switchover("whatever"));
assertFalse(this.wxService.switchover("default"));
}

@Test
Expand Down

0 comments on commit b52e676

Please sign in to comment.