Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复无法切换到初始公众号配置的问题并完善了removeConfigStorage #1600

Merged
merged 2 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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