|
|
@ -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"); |
|
|
|
} |
|
|
|
} |
|
|
|