修改代码配置使用的自动注入方式,删除一个多余的代码
This commit is contained in:
parent
e28b6f25bb
commit
dc9d02f0dc
|
@ -8,12 +8,17 @@
|
|||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="wechat-j-open" />
|
||||
<module name="wechat-official-account-spring" />
|
||||
<module name="wechat-j-pay" />
|
||||
<module name="wechat-j-common" />
|
||||
<module name="wechat-j-work" />
|
||||
<module name="wechat-official-account-spring" />
|
||||
<module name="wechat-j-mp" />
|
||||
<module name="wechat-j-oa" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="wechat-j-wecom" target="11" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
|
|
|
@ -9,8 +9,14 @@
|
|||
<file url="file://$PROJECT_DIR$/../WeChat-J/oa/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/open/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/open/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/pay/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/pay/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/wecom/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/wecom/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/work/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/../WeChat-J/work/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -3,8 +3,10 @@ package com.ossez.wechat.demo.common.enums;
|
|||
/**
|
||||
* User different http client to make api call.
|
||||
* We should only keep OK_HTTP, this enough for package
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
public enum HttpClientType {
|
||||
HTTP_CLIENT, OK_HTTP
|
||||
public enum HttpClientCategory {
|
||||
OK_HTTP, HTTP_CLIENT
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.ossez.wechat.demo.common.enums;
|
||||
|
||||
/**
|
||||
* WeChat's Storage Category
|
||||
*
|
||||
* We provide implement for MEM(RAM) and REDIS
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
public enum StorageCategory {
|
||||
MEM, REDIS
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.ossez.wechat.demo.common.enums;
|
||||
|
||||
/**
|
||||
* storage类型.
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* created on 2020-08-30
|
||||
*/
|
||||
public enum StorageType {
|
||||
/**
|
||||
* 内存.
|
||||
*/
|
||||
Memory,
|
||||
/**
|
||||
* redis(JedisClient).
|
||||
*/
|
||||
Jedis,
|
||||
/**
|
||||
* redis(Redisson).
|
||||
*/
|
||||
Redisson,
|
||||
/**
|
||||
* redis(RedisTemplate).
|
||||
*/
|
||||
RedisTemplate
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.ossez.wechat.demo.config;
|
||||
|
||||
import com.ossez.wechat.demo.common.enums.HttpClientCategory;
|
||||
import com.ossez.wechat.demo.properties.WeChatOfficialAccountProperties;
|
||||
import com.ossez.wechat.oa.api.WeChatOfficialAccountService;
|
||||
import com.ossez.wechat.oa.api.impl.okhttp.WeChatOfficialAccountServiceOkHttp;
|
||||
import com.ossez.wechat.oa.config.ConfigStorage;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* .
|
||||
*
|
||||
* @author someone
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(WeChatOfficialAccountProperties.class)
|
||||
@Import({WeChatStorageAutoConfiguration.class})
|
||||
public class WeChatConfiguration {
|
||||
|
||||
|
||||
/**
|
||||
* weChat Service Inject
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WeChatOfficialAccountService weChatOfficialAccountService(ConfigStorage configStorage, WeChatOfficialAccountProperties weChatOfficialAccountProperties) {
|
||||
HttpClientCategory httpClientCategory = weChatOfficialAccountProperties.getConfigStorage().getHttpClientCategory();
|
||||
WeChatOfficialAccountService weChatOfficialAccountService = new WeChatOfficialAccountServiceOkHttp();
|
||||
|
||||
weChatOfficialAccountService.setWxMpConfigStorage(configStorage);
|
||||
return weChatOfficialAccountService;
|
||||
}
|
||||
}
|
|
@ -1,17 +1,15 @@
|
|||
package com.ossez.wechat.demo.config;
|
||||
|
||||
import com.ossez.wechat.demo.common.enums.StorageType;
|
||||
import com.ossez.wechat.demo.common.enums.StorageCategory;
|
||||
import com.ossez.wechat.demo.properties.RedisProperties;
|
||||
import com.ossez.wechat.demo.properties.WeChatOfficialAccountProperties;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.ossez.wechat.oa.config.ConfigStorage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ossez.wechat.common.redis.JedisWxRedisOps;
|
||||
import com.ossez.wechat.common.redis.RedisTemplateWxRedisOps;
|
||||
import com.ossez.wechat.common.redis.WxRedisOps;
|
||||
import com.ossez.wechat.oa.config.WxMpHostConfig;
|
||||
import com.ossez.wechat.oa.config.ConfigStorage;
|
||||
import com.ossez.wechat.oa.config.DefaultConfigStorage;
|
||||
import com.ossez.wechat.oa.config.impl.RedisConfigStorage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -35,7 +33,7 @@ import java.util.Set;
|
|||
@Slf4j
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class WxMpStorageAutoConfiguration {
|
||||
public class WeChatStorageAutoConfiguration {
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
private final WeChatOfficialAccountProperties wxMpProperties;
|
||||
|
@ -43,10 +41,10 @@ public class WxMpStorageAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean(ConfigStorage.class)
|
||||
public ConfigStorage wxMpConfigStorage() {
|
||||
StorageType type = wxMpProperties.getConfigStorage().getType();
|
||||
StorageCategory type = wxMpProperties.getConfigStorage().getType();
|
||||
ConfigStorage config;
|
||||
switch (type) {
|
||||
case RedisTemplate:
|
||||
case REDIS:
|
||||
config = redisTemplateConfigStorage();
|
||||
break;
|
||||
default:
|
|
@ -1,17 +0,0 @@
|
|||
package com.ossez.wechat.demo.config;
|
||||
|
||||
import com.ossez.wechat.demo.properties.WeChatOfficialAccountProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* .
|
||||
*
|
||||
* @author someone
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(WeChatOfficialAccountProperties.class)
|
||||
@Import({ WxMpStorageAutoConfiguration.class, WxMpServiceAutoConfiguration.class })
|
||||
public class WxMpAutoConfiguration {
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.ossez.wechat.demo.config;
|
||||
|
||||
import com.ossez.wechat.demo.common.enums.HttpClientType;
|
||||
import com.ossez.wechat.demo.properties.WeChatOfficialAccountProperties;
|
||||
import com.ossez.wechat.oa.api.WeChatOfficialAccountService;
|
||||
import com.ossez.wechat.oa.api.impl.okhttp.WeChatOfficialAccountServiceOkHttp;
|
||||
import com.ossez.wechat.oa.config.ConfigStorage;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 微信公众号相关服务自动注册.
|
||||
*
|
||||
* @author someone
|
||||
*/
|
||||
@Configuration
|
||||
public class WxMpServiceAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WeChatOfficialAccountService weChatOfficialAccountService(ConfigStorage configStorage, WeChatOfficialAccountProperties wxMpProperties) {
|
||||
HttpClientType httpClientType = wxMpProperties.getConfigStorage().getHttpClientType();
|
||||
WeChatOfficialAccountService weChatOfficialAccountService = new WeChatOfficialAccountServiceOkHttp();
|
||||
|
||||
weChatOfficialAccountService.setWxMpConfigStorage(configStorage);
|
||||
return weChatOfficialAccountService;
|
||||
}
|
||||
|
||||
}
|
|
@ -40,13 +40,7 @@ public class WeChatController {
|
|||
@GetMapping("/token")
|
||||
@ResponseBody
|
||||
public String getAccessToken() throws WxErrorException {
|
||||
|
||||
|
||||
weChatOfficialAccountService.getAccessToken(true);
|
||||
|
||||
|
||||
|
||||
return "ss" ;
|
||||
return weChatOfficialAccountService.getAccessToken(true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.ossez.wechat.demo.properties;
|
||||
|
||||
|
||||
import com.ossez.wechat.demo.common.enums.HttpClientType;
|
||||
import com.ossez.wechat.demo.common.enums.StorageType;
|
||||
import com.ossez.wechat.demo.common.enums.HttpClientCategory;
|
||||
import com.ossez.wechat.demo.common.enums.StorageCategory;
|
||||
import com.ossez.wechat.demo.model.entity.WeChatHost;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
@ -10,7 +10,7 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import static com.ossez.wechat.demo.common.enums.StorageType.Memory;
|
||||
import static com.ossez.wechat.demo.common.enums.StorageCategory.MEM;
|
||||
|
||||
/**
|
||||
* WeChat Official Account Config
|
||||
|
@ -37,7 +37,7 @@ public class WeChatOfficialAccountProperties {
|
|||
/**
|
||||
* 存储类型.
|
||||
*/
|
||||
private StorageType type = Memory;
|
||||
private StorageCategory type = MEM;
|
||||
|
||||
/**
|
||||
* 指定key前缀.
|
||||
|
@ -53,7 +53,7 @@ public class WeChatOfficialAccountProperties {
|
|||
/**
|
||||
* http客户端类型.
|
||||
*/
|
||||
private HttpClientType httpClientType = HttpClientType.OK_HTTP;
|
||||
private HttpClientCategory httpClientCategory = HttpClientCategory.OK_HTTP;
|
||||
|
||||
/**
|
||||
* http代理主机.
|
||||
|
|
|
@ -48,7 +48,7 @@ spring.redis.port=6379
|
|||
|
||||
# KEY
|
||||
wechat.official-account.app-id = wx637b82a7f94123ef
|
||||
wechat.official-account.secret = 343cecbc44d69e45367a65cc9b4d3925+
|
||||
wechat.official-account.secret = 343cecbc44d69e45367a65cc9b4d3925
|
||||
wechat.official-account.token = 0b01a700891d4a2f93a4323771c32455
|
||||
wechat.official-account.aes-key = aesKey
|
||||
|
||||
|
|
Loading…
Reference in New Issue