|
@@ -8,7 +8,12 @@ import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
|
|
import cn.binarywang.wx.miniapp.message.WxMaMessageHandler;
|
|
|
import cn.binarywang.wx.miniapp.message.WxMaMessageRouter;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.course.config.CourseMaConfig;
|
|
|
+import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
|
+import com.fs.course.mapper.FsCoursePlaySourceConfigMapper;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.mapper.SysConfigMapper;
|
|
|
import com.google.common.collect.Lists;
|
|
@@ -18,6 +23,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import me.chanjar.weixin.common.error.WxRuntimeException;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
@@ -41,7 +47,7 @@ public class WxMaConfiguration {
|
|
|
private static Map<String, WxMaService> maServices;
|
|
|
|
|
|
@Autowired
|
|
|
- public WxMaConfiguration(SysConfigMapper sysConfigMapper) {
|
|
|
+ public WxMaConfiguration(SysConfigMapper sysConfigMapper, FsCoursePlaySourceConfigMapper configMapper) {
|
|
|
SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.config");
|
|
|
String configValue = sysConfig.getConfigValue();
|
|
|
//下单小程序加载
|
|
@@ -73,18 +79,69 @@ public class WxMaConfiguration {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 加载点播配置表配置
|
|
|
+ Wrapper<FsCoursePlaySourceConfig> queryWrapper = Wrappers.<FsCoursePlaySourceConfig>lambdaQuery().eq(FsCoursePlaySourceConfig::getIsDel, 0);
|
|
|
+ for (FsCoursePlaySourceConfig playConfig : configMapper.selectList(queryWrapper)) {
|
|
|
+ boolean isExist = c.stream().anyMatch(item -> item.getAppid().equals(playConfig.getAppid()));
|
|
|
+ if (!isExist){
|
|
|
+ WxMaConfig.Config wxMaConfig = new WxMaConfig.Config();
|
|
|
+ BeanUtils.copyProperties(playConfig, wxMaConfig);
|
|
|
+ c.add(wxMaConfig);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
wx.setConfigs(c);
|
|
|
this.properties = wx;
|
|
|
log.info("配置加载完毕! 配置文件: {}",JSON.toJSONString(this.properties));
|
|
|
}
|
|
|
|
|
|
public static WxMaService getMaService(String appid) {
|
|
|
+ // 从缓存获取
|
|
|
WxMaService wxService = maServices.get(appid);
|
|
|
- if (wxService == null) {
|
|
|
- throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
|
|
|
+ if (wxService != null) {
|
|
|
+ return wxService;
|
|
|
}
|
|
|
|
|
|
- return wxService;
|
|
|
+ // 缓存未命中,查询数据库
|
|
|
+ synchronized (WxMaConfiguration.class) {
|
|
|
+ // 双重检查
|
|
|
+ wxService = maServices.get(appid);
|
|
|
+ if (wxService != null) {
|
|
|
+ return wxService;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询数据库
|
|
|
+ FsCoursePlaySourceConfigMapper configMapper = SpringUtils.getBean(FsCoursePlaySourceConfigMapper.class);
|
|
|
+ Wrapper<FsCoursePlaySourceConfig> queryWrapper = Wrappers.<FsCoursePlaySourceConfig>lambdaQuery()
|
|
|
+ .eq(FsCoursePlaySourceConfig::getAppid, appid)
|
|
|
+ .eq(FsCoursePlaySourceConfig::getIsDel, 0);
|
|
|
+ FsCoursePlaySourceConfig config = configMapper.selectOne(queryWrapper);
|
|
|
+ if (config == null) {
|
|
|
+ throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
|
|
|
+ }
|
|
|
+
|
|
|
+ WxMaService service = getWxMaService(config.getAppid(), config.getSecret(), config.getToken(), config.getAesKey(), config.getMsgDataFormat());
|
|
|
+ maServices.put(appid, service);
|
|
|
+ log.info("Initialized WxMaService for appid: {}", appid);
|
|
|
+ return service;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化WxMaService
|
|
|
+ */
|
|
|
+ private static WxMaService getWxMaService(String appid, String secret, String token, String aesKey, String msgDataFormat) {
|
|
|
+ WxMaDefaultConfigImpl maConfig = new WxMaDefaultConfigImpl();
|
|
|
+ maConfig.setAppid(appid);
|
|
|
+ maConfig.setSecret(secret);
|
|
|
+ maConfig.setToken(token);
|
|
|
+ maConfig.setAesKey(aesKey);
|
|
|
+ maConfig.setMsgDataFormat(msgDataFormat);
|
|
|
+
|
|
|
+ WxMaService service = new WxMaServiceImpl();
|
|
|
+ service.setWxMaConfig(maConfig);
|
|
|
+ return service;
|
|
|
}
|
|
|
|
|
|
public static WxMaMessageRouter getRouter(String appid) {
|
|
@@ -100,17 +157,7 @@ public class WxMaConfiguration {
|
|
|
|
|
|
maServices = configs.stream()
|
|
|
.map(a -> {
|
|
|
- WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
|
|
-// WxMaDefaultConfigImpl config = new WxMaRedisConfigImpl(new JedisPool());
|
|
|
- // 使用上面的配置时,需要同时引入jedis-lock的依赖,否则会报类无法找到的异常
|
|
|
- config.setAppid(a.getAppid());
|
|
|
- config.setSecret(a.getSecret());
|
|
|
- config.setToken(a.getToken());
|
|
|
- config.setAesKey(a.getAesKey());
|
|
|
- config.setMsgDataFormat(a.getMsgDataFormat());
|
|
|
-
|
|
|
- WxMaService service = new WxMaServiceImpl();
|
|
|
- service.setWxMaConfig(config);
|
|
|
+ WxMaService service = getWxMaService(a.getAppid(), a.getSecret(), a.getToken(), a.getAesKey(), a.getMsgDataFormat());
|
|
|
routers.put(a.getAppid(), this.newRouter(service));
|
|
|
return service;
|
|
|
}).collect(Collectors.toMap(s -> s.getWxMaConfig().getAppid(), a -> a));
|