mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🐛 #1600 修复无法切换到初始公众号配置的问题并完善了removeConfigStorage方法
* 修复无法切换到初始公众号配置的问题 * 完善removeConfigStorage
This commit is contained in:
parent
1c60839890
commit
b52e676040
@ -414,7 +414,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
|
||||
|
||||
@Override
|
||||
public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) {
|
||||
final String defaultMpId = WxMpConfigStorageHolder.get();
|
||||
final String defaultMpId = wxConfigProvider.getAppId();
|
||||
this.setMultiConfigStorages(ImmutableMap.of(defaultMpId, wxConfigProvider), defaultMpId);
|
||||
}
|
||||
|
||||
@ -440,6 +440,18 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ public class BaseWxMpServiceImplTest {
|
||||
assertTrue(this.wxService.switchover("another"));
|
||||
assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another");
|
||||
assertFalse(this.wxService.switchover("whatever"));
|
||||
assertFalse(this.wxService.switchover("default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user