Skip to content

Commit 5599d47

Browse files
Copilotbinarywang
andcommitted
代码审查修复:改进参数验证和代码质量
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
1 parent 9486f9a commit 5599d47

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

spring-boot-starters/wx-java-open-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/configuration/services/AbstractWxOpenConfiguration.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ protected WxOpenMultiServices wxOpenMultiServices(WxOpenMultiProperties wxOpenMu
4040
Collection<WxOpenSingleProperties> apps = appsMap.values();
4141
if (apps.size() > 1) {
4242
// 校验 appId 是否唯一
43+
String nullAppIdPlaceholder = "__NULL_APP_ID__";
4344
boolean multi = apps.stream()
4445
// 没有 appId,如果不判断是否为空,这里会报 NPE 异常
45-
.collect(Collectors.groupingBy(c -> c.getAppId() == null ? 0 : c.getAppId(), Collectors.counting()))
46+
.collect(Collectors.groupingBy(c -> c.getAppId() == null ? nullAppIdPlaceholder : c.getAppId(), Collectors.counting()))
4647
.entrySet().stream().anyMatch(e -> e.getValue() > 1);
4748
if (multi) {
4849
throw new RuntimeException("请确保微信开放平台配置 appId 的唯一性");
@@ -85,6 +86,14 @@ private void configApp(WxOpenInMemoryConfigStorage config, WxOpenSinglePropertie
8586
String apiHostUrl = appProperties.getApiHostUrl();
8687
String accessTokenUrl = appProperties.getAccessTokenUrl();
8788

89+
// appId 和 secret 是必需的
90+
if (StringUtils.isBlank(appId)) {
91+
throw new IllegalArgumentException("微信开放平台 appId 不能为空");
92+
}
93+
if (StringUtils.isBlank(secret)) {
94+
throw new IllegalArgumentException("微信开放平台 secret 不能为空");
95+
}
96+
8897
config.setComponentAppId(appId);
8998
config.setComponentAppSecret(secret);
9099
if (StringUtils.isNotBlank(token)) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2-
com.binarywang.spring.starter.wxjava.open.autoconfigure.WxOpenMultiAutoConfiguration
2+
com.binarywang.spring.starter.wxjava.open.autoconfigure.WxOpenMultiAutoConfiguration
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
com.binarywang.spring.starter.wxjava.open.autoconfigure.WxOpenMultiAutoConfiguration
1+
com.binarywang.spring.starter.wxjava.open.autoconfigure.WxOpenMultiAutoConfiguration

0 commit comments

Comments
 (0)