Skip to content

Commit

Permalink
🆕 binarywang#3360 增加 miniapp-multi-spring-boot-start
Browse files Browse the repository at this point in the history
  • Loading branch information
monchcc committed Sep 7, 2024
1 parent a6e3c86 commit 39ead8f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
1 change: 1 addition & 0 deletions spring-boot-starters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</properties>

<modules>
<module>wx-java-miniapp-multi-spring-boot-starter</module>
<module>wx-java-miniapp-spring-boot-starter</module>
<module>wx-java-mp-multi-spring-boot-starter</module>
<module>wx-java-mp-spring-boot-starter</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
4. 使用样例

```java
import com.binarywang.spring.starter.wxjava.mp.service.WxMpMultiServices;
import com.binarywang.spring.starter.wxjava.mp.service.WxMaMultiServices;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpUserService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
@Slf4j
public abstract class AbstractWxMpConfiguration {

protected WxMpMultiServices wxMpMultiServices(WxMpMultiProperties wxCpMultiProperties) {
Map<String, WxMpSingleProperties> appsMap = wxCpMultiProperties.getApps();
protected WxMpMultiServices wxMpMultiServices(WxMpMultiProperties wxMpMultiProperties) {
Map<String, WxMpSingleProperties> appsMap = wxMpMultiProperties.getApps();
if (appsMap == null || appsMap.isEmpty()) {
log.warn("微信公众号应用参数未配置,通过 WxMpMultiServices#getWxMpService(\"tenantId\")获取实例将返回空");
return new WxMpMultiServicesImpl();
Expand All @@ -59,12 +59,12 @@ protected WxMpMultiServices wxMpMultiServices(WxMpMultiProperties wxCpMultiPrope
for (Map.Entry<String, WxMpSingleProperties> entry : entries) {
String tenantId = entry.getKey();
WxMpSingleProperties wxMpSingleProperties = entry.getValue();
WxMpDefaultConfigImpl storage = this.wxMpConfigStorage(wxCpMultiProperties);
WxMpDefaultConfigImpl storage = this.wxMpConfigStorage(wxMpMultiProperties);
this.configApp(storage, wxMpSingleProperties);
this.configHttp(storage, wxCpMultiProperties.getConfigStorage());
this.configHost(storage, wxCpMultiProperties.getHosts());
WxMpService wxCpService = this.wxMpService(storage, wxCpMultiProperties);
services.addWxMpService(tenantId, wxCpService);
this.configHttp(storage, wxMpMultiProperties.getConfigStorage());
this.configHost(storage, wxMpMultiProperties.getHosts());
WxMpService wxMpService = this.wxMpService(storage, wxMpMultiProperties);
services.addWxMpService(tenantId, wxMpService);
}
return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,32 @@
)
@RequiredArgsConstructor
public class WxMpInJedisConfiguration extends AbstractWxMpConfiguration {
private final WxMpMultiProperties wxCpMultiProperties;
private final WxMpMultiProperties wxMpMultiProperties;
private final ApplicationContext applicationContext;

@Bean
public WxMpMultiServices wxMpMultiServices() {
return this.wxMpMultiServices(wxCpMultiProperties);
return this.wxMpMultiServices(wxMpMultiProperties);
}

@Override
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxCpMultiProperties) {
return this.configRedis(wxCpMultiProperties);
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
return this.configRedis(wxMpMultiProperties);
}

private WxMpDefaultConfigImpl configRedis(WxMpMultiProperties wxCpMultiProperties) {
WxMpMultiRedisProperties wxCpMultiRedisProperties = wxCpMultiProperties.getConfigStorage().getRedis();
private WxMpDefaultConfigImpl configRedis(WxMpMultiProperties wxMpMultiProperties) {
WxMpMultiRedisProperties wxMpMultiRedisProperties = wxMpMultiProperties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (wxCpMultiRedisProperties != null && StringUtils.isNotEmpty(wxCpMultiRedisProperties.getHost())) {
jedisPool = getJedisPool(wxCpMultiProperties);
if (wxMpMultiRedisProperties != null && StringUtils.isNotEmpty(wxMpMultiRedisProperties.getHost())) {
jedisPool = getJedisPool(wxMpMultiProperties);
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
return new WxMpRedisConfigImpl(new JedisWxRedisOps(jedisPool), wxCpMultiProperties.getConfigStorage().getKeyPrefix());
return new WxMpRedisConfigImpl(new JedisWxRedisOps(jedisPool), wxMpMultiProperties.getConfigStorage().getKeyPrefix());
}

private JedisPool getJedisPool(WxMpMultiProperties wxCpMultiProperties) {
WxMpMultiProperties.ConfigStorage storage = wxCpMultiProperties.getConfigStorage();
private JedisPool getJedisPool(WxMpMultiProperties wxMpMultiProperties) {
WxMpMultiProperties.ConfigStorage storage = wxMpMultiProperties.getConfigStorage();
WxMpMultiRedisProperties redis = storage.getRedis();

JedisPoolConfig config = new JedisPoolConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
)
@RequiredArgsConstructor
public class WxMpInMemoryConfiguration extends AbstractWxMpConfiguration {
private final WxMpMultiProperties wxCpMultiProperties;
private final WxMpMultiProperties wxMpMultiProperties;

@Bean
public WxMpMultiServices wxCpMultiServices() {
return this.wxMpMultiServices(wxCpMultiProperties);
public WxMpMultiServices wxMpMultiServices() {
return this.wxMpMultiServices(wxMpMultiProperties);
}

@Override
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxCpMultiProperties) {
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
return this.configInMemory();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@
)
@RequiredArgsConstructor
public class WxMpInRedissonConfiguration extends AbstractWxMpConfiguration {
private final WxMpMultiProperties wxCpMultiProperties;
private final WxMpMultiProperties wxMpMultiProperties;
private final ApplicationContext applicationContext;

@Bean
public WxMpMultiServices wxMpMultiServices() {
return this.wxMpMultiServices(wxCpMultiProperties);
return this.wxMpMultiServices(wxMpMultiProperties);
}

@Override
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxCpMultiProperties) {
return this.configRedisson(wxCpMultiProperties);
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
return this.configRedisson(wxMpMultiProperties);
}

private WxMpDefaultConfigImpl configRedisson(WxMpMultiProperties wxCpMultiProperties) {
WxMpMultiRedisProperties redisProperties = wxCpMultiProperties.getConfigStorage().getRedis();
private WxMpDefaultConfigImpl configRedisson(WxMpMultiProperties wxMpMultiProperties) {
WxMpMultiRedisProperties redisProperties = wxMpMultiProperties.getConfigStorage().getRedis();
RedissonClient redissonClient;
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
redissonClient = getRedissonClient(wxCpMultiProperties);
redissonClient = getRedissonClient(wxMpMultiProperties);
} else {
redissonClient = applicationContext.getBean(RedissonClient.class);
}
return new WxMpRedissonConfigImpl(redissonClient, wxCpMultiProperties.getConfigStorage().getKeyPrefix());
return new WxMpRedissonConfigImpl(redissonClient, wxMpMultiProperties.getConfigStorage().getKeyPrefix());
}

private RedissonClient getRedissonClient(WxMpMultiProperties wxCpMultiProperties) {
WxMpMultiProperties.ConfigStorage storage = wxCpMultiProperties.getConfigStorage();
private RedissonClient getRedissonClient(WxMpMultiProperties wxMpMultiProperties) {
WxMpMultiProperties.ConfigStorage storage = wxMpMultiProperties.getConfigStorage();
WxMpMultiRedisProperties redis = storage.getRedis();

Config config = new Config();
Expand Down

0 comments on commit 39ead8f

Please sign in to comment.