Browse Source

捕获异常

dev
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.password>123456</spring.redis.password>
<!-- 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.discovery.namespace>fcd6fc8f-ca3a-4b01-8026-2b05cdc5976b</nacos.discovery.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.impl.WxMaServiceImpl;
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.RedisUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerAppDTO;
import com.epmet.dto.form.CustomerAppSecretFormDTO;
import com.epmet.feign.OperCrmOpenFeignClient;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
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.util.CollectionUtils;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
@ -50,6 +52,8 @@ public class CustomerAppWxServiceUtil implements ApplicationRunner {
@Autowired
private RedisUtils redisUtils;
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Autowired
private OperCrmOpenFeignClient operCrmOpenFeignClient;
private static Map<String, WxMaService> maServices = Maps.newHashMap();
@ -64,7 +68,7 @@ public class CustomerAppWxServiceUtil implements ApplicationRunner {
}
return wxMaService;
}
public String get(String appId) {
/*public String get(String appId) {
String key = RedisKeys.getAppSecretKey(appId);
String secret = (String) redisUtils.get(key);
if (StringUtils.isBlank(secret)) {
@ -79,24 +83,45 @@ public class CustomerAppWxServiceUtil implements ApplicationRunner {
}
}
return secret;
}
}*/
@Override
public void run(ApplicationArguments args) throws Exception {
Result<List<CustomerAppDTO>> configAllAppResult = operCrmOpenFeignClient.getConfigAllApp();
if (configAllAppResult != null && configAllAppResult.success() && !CollectionUtils.isEmpty(configAllAppResult.getData())) {
maServices = configAllAppResult.getData().stream()
.map(a -> {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(a.getAppId());
config.setSecret(a.getSecret());
config.setMsgDataFormat(JSON_STR);
public void run(ApplicationArguments args) {
try {
Result<List<CustomerAppDTO>> configAllAppResult = operCrmOpenFeignClient.getConfigAllApp();
logger.info("initWxMa operCrmOpenFeignClient.getConfigAllApp result:{}", JSON.toJSONString(configAllAppResult));
if (configAllAppResult == null || configAllAppResult.success()){
logger.info("initWxMa operCrmOpenFeignClient.getConfigAllApp fail");
return;
}
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();
service.setWxMaConfig(config);
return service;
}).collect(Collectors.toMap(s -> s.getWxMaConfig().getAppid(), a -> a));
WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config);
redisTemplate.opsForSet().add(appKey,a.getSecret());
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
* @param appId
* @return
*/
public static String getAppSecretKey(String appId) {
return rootPrefix.concat("oper:crm:appid:secret").concat(appId);
public static String getCustomerAppKey() {
return rootPrefix.concat("oper:crm:app");
}
}

Loading…
Cancel
Save