|
@@ -1,11 +1,12 @@
|
|
|
package com.hcloud.microserver.h5.config.wx;
|
|
|
|
|
|
|
|
|
-
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
+import me.chanjar.weixin.mp.api.WxOAuth2Service;
|
|
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
|
|
+import me.chanjar.weixin.mp.api.impl.WxOAuth2ServiceImpl;
|
|
|
+import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
@@ -16,7 +17,7 @@ import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
@Slf4j
|
|
|
@Configuration
|
|
|
-@ConditionalOnClass(WxMpService.class)
|
|
|
+@ConditionalOnClass({WxMpService.class,WxOAuth2Service.class})
|
|
|
@EnableConfigurationProperties(WxMpProperties.class)
|
|
|
public class WxMpConfiguration {
|
|
|
|
|
@@ -27,10 +28,11 @@ public class WxMpConfiguration {
|
|
|
this.properties = properties;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Bean
|
|
|
@ConditionalOnMissingBean
|
|
|
public WxMpService wxMpService() {
|
|
|
- WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
|
|
|
+ WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
|
|
|
configStorage.setAppId(StringUtils.trimToNull(this.properties.getAppId()));
|
|
|
configStorage.setSecret(StringUtils.trimToNull(this.properties.getSecret()));
|
|
|
configStorage.setToken(StringUtils.trimToNull(this.properties.getToken()));
|
|
@@ -39,4 +41,18 @@ public class WxMpConfiguration {
|
|
|
wxMpService.setWxMpConfigStorage(configStorage);
|
|
|
return wxMpService;
|
|
|
}
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnMissingBean
|
|
|
+ public WxOAuth2Service wxOAuth2Service() {
|
|
|
+ WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
|
|
|
+ configStorage.setAppId(StringUtils.trimToNull(this.properties.getAppId()));
|
|
|
+ configStorage.setSecret(StringUtils.trimToNull(this.properties.getSecret()));
|
|
|
+ configStorage.setToken(StringUtils.trimToNull(this.properties.getToken()));
|
|
|
+ configStorage.setAesKey(StringUtils.trimToNull(this.properties.getAesKey()));
|
|
|
+ WxMpService wxMpService = new WxMpServiceImpl();
|
|
|
+ wxMpService.setWxMpConfigStorage(configStorage);
|
|
|
+ WxOAuth2Service wxOAuth2Service = new WxOAuth2ServiceImpl(wxMpService);
|
|
|
+ return wxOAuth2Service;
|
|
|
+ }
|
|
|
}
|