Browse Source

捕获异常

dev_shibei_match
jianjun 5 years ago
parent
commit
8f3970dd23
  1. 2
      epmet-auth/pom.xml
  2. 61
      epmet-auth/src/main/java/com/epmet/redis/CustomerAppWxServiceUtil.java
  3. 5
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java

2
epmet-auth/pom.xml

@ -169,7 +169,7 @@
<spring.redis.port>6379</spring.redis.port> <spring.redis.port>6379</spring.redis.port>
<spring.redis.password>123456</spring.redis.password> <spring.redis.password>123456</spring.redis.password>
<!-- nacos --> <!-- nacos -->
<nacos.register-enabled>false</nacos.register-enabled> <nacos.register-enabled>true</nacos.register-enabled>
<nacos.server-addr>122.152.200.70:8848</nacos.server-addr> <nacos.server-addr>122.152.200.70:8848</nacos.server-addr>
<nacos.discovery.namespace>fcd6fc8f-ca3a-4b01-8026-2b05cdc5976b</nacos.discovery.namespace> <nacos.discovery.namespace>fcd6fc8f-ca3a-4b01-8026-2b05cdc5976b</nacos.discovery.namespace>
<nacos.config.namespace></nacos.config.namespace> <nacos.config.namespace></nacos.config.namespace>

61
epmet-auth/src/main/java/com/epmet/redis/CustomerAppWxServiceUtil.java

@ -11,24 +11,26 @@ package com.epmet.redis;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerAppDTO; import com.epmet.dto.CustomerAppDTO;
import com.epmet.dto.form.CustomerAppSecretFormDTO;
import com.epmet.feign.OperCrmOpenFeignClient; import com.epmet.feign.OperCrmOpenFeignClient;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -50,6 +52,8 @@ public class CustomerAppWxServiceUtil implements ApplicationRunner {
@Autowired @Autowired
private RedisUtils redisUtils; private RedisUtils redisUtils;
@Autowired @Autowired
private RedisTemplate<String,String> redisTemplate;
@Autowired
private OperCrmOpenFeignClient operCrmOpenFeignClient; private OperCrmOpenFeignClient operCrmOpenFeignClient;
private static Map<String, WxMaService> maServices = Maps.newHashMap(); private static Map<String, WxMaService> maServices = Maps.newHashMap();
@ -64,7 +68,7 @@ public class CustomerAppWxServiceUtil implements ApplicationRunner {
} }
return wxMaService; return wxMaService;
} }
public String get(String appId) { /*public String get(String appId) {
String key = RedisKeys.getAppSecretKey(appId); String key = RedisKeys.getAppSecretKey(appId);
String secret = (String) redisUtils.get(key); String secret = (String) redisUtils.get(key);
if (StringUtils.isBlank(secret)) { if (StringUtils.isBlank(secret)) {
@ -79,24 +83,45 @@ public class CustomerAppWxServiceUtil implements ApplicationRunner {
} }
} }
return secret; return secret;
} }*/
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) {
Result<List<CustomerAppDTO>> configAllAppResult = operCrmOpenFeignClient.getConfigAllApp(); try {
if (configAllAppResult != null && configAllAppResult.success() && !CollectionUtils.isEmpty(configAllAppResult.getData())) { Result<List<CustomerAppDTO>> configAllAppResult = operCrmOpenFeignClient.getConfigAllApp();
maServices = configAllAppResult.getData().stream() logger.info("initWxMa operCrmOpenFeignClient.getConfigAllApp result:{}", JSON.toJSONString(configAllAppResult));
.map(a -> { if (configAllAppResult == null || configAllAppResult.success()){
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); logger.info("initWxMa operCrmOpenFeignClient.getConfigAllApp fail");
config.setAppid(a.getAppId()); return;
config.setSecret(a.getSecret()); }
config.setMsgDataFormat(JSON_STR); String appKey = RedisKeys.getCustomerAppKey();
SetOperations<String, String> appSet = redisTemplate.opsForSet();
Set<String> members = appSet.members(appKey);
if ( !CollectionUtils.isEmpty(configAllAppResult.getData())) {
//if (!CollectionUtils.isEmpty(members) && CollectionUtils.isEmpty()){
//todo
//}
maServices = configAllAppResult.getData().stream()
.map(a -> {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(a.getAppId());
config.setSecret(a.getSecret());
config.setMsgDataFormat(JSON_STR);
WxMaService service = new WxMaServiceImpl(); WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config); service.setWxMaConfig(config);
return service; redisTemplate.opsForSet().add(appKey,a.getSecret());
}).collect(Collectors.toMap(s -> s.getWxMaConfig().getAppid(), a -> a)); return service;
}).collect(Collectors.toMap(s -> s.getWxMaConfig().getAppid(), a -> a));
}
} catch (Exception e) {
logger.error("init wxMaservice exception",e);
} finally {
logger.info("init wxMaservice end");
} }
logger.info("initWxMa success");
} }
} }

5
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java

@ -256,11 +256,10 @@ public class RedisKeys {
/** /**
* appId secret 缓存Key * appId secret 缓存Key
* @param appId
* @return * @return
*/ */
public static String getAppSecretKey(String appId) { public static String getCustomerAppKey() {
return rootPrefix.concat("oper:crm:appid:secret").concat(appId); return rootPrefix.concat("oper:crm:app");
} }
} }

Loading…
Cancel
Save