|
@@ -1,12 +1,30 @@
|
|
|
package com.ydtech.config;
|
|
package com.ydtech.config;
|
|
|
|
|
|
|
|
|
|
+import com.ydtech.config.properties.WechatCustomerProperties;
|
|
|
|
|
+import com.ydtech.config.properties.WechatOpenProperties;
|
|
|
|
|
+import me.chanjar.weixin.cp.api.WxCpKfService;
|
|
|
import me.chanjar.weixin.cp.api.WxCpService;
|
|
import me.chanjar.weixin.cp.api.WxCpService;
|
|
|
|
|
+import me.chanjar.weixin.cp.api.impl.WxCpKfServiceImpl;
|
|
|
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
|
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
|
|
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
|
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
|
|
|
|
+import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
|
|
+import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
|
|
|
|
+import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @version
|
|
|
|
|
+ * @description: 微信相关配置
|
|
|
|
|
+ * @author: wenks
|
|
|
|
|
+ * @date: 2024/11/27 15:01
|
|
|
|
|
+ **/
|
|
|
@Configuration
|
|
@Configuration
|
|
|
public class WechatWorkConfig {
|
|
public class WechatWorkConfig {
|
|
|
|
|
|
|
@@ -17,13 +35,55 @@ public class WechatWorkConfig {
|
|
|
@Value("${wechat.cp.agent-id}")
|
|
@Value("${wechat.cp.agent-id}")
|
|
|
private Integer agentId;
|
|
private Integer agentId;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private WechatOpenProperties wechatOpenProperties;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private WechatCustomerProperties wechatCustomerProperties;
|
|
|
|
|
+
|
|
|
@Bean
|
|
@Bean
|
|
|
public WxCpService wxCpService() {
|
|
public WxCpService wxCpService() {
|
|
|
WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
|
|
WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
|
|
|
config.setCorpId(corpId);
|
|
config.setCorpId(corpId);
|
|
|
config.setCorpSecret(secret);
|
|
config.setCorpSecret(secret);
|
|
|
config.setAgentId(agentId);
|
|
config.setAgentId(agentId);
|
|
|
-
|
|
|
|
|
|
|
+ WxCpServiceImpl wxCpService = new WxCpServiceImpl();
|
|
|
|
|
+ wxCpService.setWxCpConfigStorage(config);
|
|
|
return new WxCpServiceImpl();
|
|
return new WxCpServiceImpl();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public Map<String, WxMpService> wxMpService() {
|
|
|
|
|
+ Map<String, WxMpDefaultConfigImpl> collect = wechatOpenProperties.getProperties().keySet()
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .collect(Collectors.toMap(x->x, x -> {
|
|
|
|
|
+ WechatOpenProperties.PropertiesDto propertiesDto = wechatOpenProperties.getProperties().get(x);
|
|
|
|
|
+ WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
|
|
|
|
|
+ wxMpDefaultConfig.setAppId(propertiesDto.getComponentAppId());
|
|
|
|
|
+ wxMpDefaultConfig.setSecret(propertiesDto.getComponentSecret());
|
|
|
|
|
+ return wxMpDefaultConfig;
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ return collect.keySet().stream().collect(Collectors.toMap(x -> x, x -> {
|
|
|
|
|
+ WxMpServiceImpl wxMpService = new WxMpServiceImpl();
|
|
|
|
|
+ WxMpDefaultConfigImpl wxMpDefaultConfig = collect.get(x);
|
|
|
|
|
+ wxMpService.setWxMpConfigStorage(wxMpDefaultConfig);
|
|
|
|
|
+ return wxMpService;
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public WxCpKfService wxCpKfService(){
|
|
|
|
|
+ WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
|
|
|
|
|
+ config.setCorpId(corpId);
|
|
|
|
|
+ config.setCorpSecret(wechatCustomerProperties.getSecret());
|
|
|
|
|
+ config.setToken(wechatCustomerProperties.getToken());
|
|
|
|
|
+ config.setAesKey(wechatCustomerProperties.getEncodingAesKey());
|
|
|
|
|
+ WxCpServiceImpl wxCpService = new WxCpServiceImpl();
|
|
|
|
|
+ wxCpService.setWxCpConfigStorage(config);
|
|
|
|
|
+ return new WxCpKfServiceImpl(wxCpService());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|