feat:新增配置类,实现动态配置管理,自动化注入配置功能
This commit is contained in:
@@ -403,6 +403,16 @@
|
|||||||
<artifactId>oauth2-oidc-sdk</artifactId>
|
<artifactId>oauth2-oidc-sdk</artifactId>
|
||||||
<version>${oauth2-oidc-sdk.version}</version>
|
<version>${oauth2-oidc-sdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zlt</groupId>
|
||||||
|
<artifactId>zlt-wechat-common-core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zlt</groupId>
|
||||||
|
<artifactId>zlt-wechat-spring-boot-starter</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
+13
-7
@@ -3,10 +3,10 @@ package com.central.user.controller;
|
|||||||
import com.central.common.context.TenantContextHolder;
|
import com.central.common.context.TenantContextHolder;
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
|
import com.central.user.service.PrivateKeyService;
|
||||||
|
import com.central.user.service.WechatConfigService;
|
||||||
|
import com.central.user.service.WechatPayService;
|
||||||
import com.zlt.wechat.entity.WechatConfig;
|
import com.zlt.wechat.entity.WechatConfig;
|
||||||
import com.zlt.wechat.service.PrivateKeyService;
|
|
||||||
import com.zlt.wechat.service.WechatConfigService;
|
|
||||||
import com.zlt.wechat.service.WechatPayService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.Parameters;
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
@@ -14,10 +14,10 @@ import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
|||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -27,13 +27,13 @@ import java.util.Map;
|
|||||||
@RequestMapping("/wechat/config")
|
@RequestMapping("/wechat/config")
|
||||||
public class SysWechatConfigController {
|
public class SysWechatConfigController {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private WechatConfigService wechatConfigService;
|
private WechatConfigService wechatConfigService;
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private WechatPayService wechatPayService;
|
private WechatPayService wechatPayService;
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private PrivateKeyService privateKeyService;
|
private PrivateKeyService privateKeyService;
|
||||||
|
|
||||||
@Operation(summary = "查询列表")
|
@Operation(summary = "查询列表")
|
||||||
@@ -109,4 +109,10 @@ public class SysWechatConfigController {
|
|||||||
public Result<WechatConfig> getCurrentConfig(@PathVariable String type) {
|
public Result<WechatConfig> getCurrentConfig(@PathVariable String type) {
|
||||||
return Result.succeed(wechatConfigService.getConfig(type, TenantContextHolder.getTenant()));
|
return Result.succeed(wechatConfigService.getConfig(type, TenantContextHolder.getTenant()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取租户密钥")
|
||||||
|
@GetMapping("/tenant/private-key")
|
||||||
|
public String getPrivateKey(@RequestParam("tenantId")String tenantId,@RequestParam String type) {
|
||||||
|
return privateKeyService.getPrivateKey(tenantId, type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.zlt.wechat.mapper;
|
package com.central.user.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
+5
-5
@@ -1,4 +1,4 @@
|
|||||||
package com.zlt.wechat.service;
|
package com.central.user.service;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ import java.io.InputStream;
|
|||||||
* 私钥文件管理服务
|
* 私钥文件管理服务
|
||||||
*/
|
*/
|
||||||
public interface PrivateKeyService {
|
public interface PrivateKeyService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传私钥文件
|
* 上传私钥文件
|
||||||
*
|
*
|
||||||
@@ -16,7 +16,7 @@ public interface PrivateKeyService {
|
|||||||
* @return 文件访问路径
|
* @return 文件访问路径
|
||||||
*/
|
*/
|
||||||
String uploadPrivateKey(String tenantId, String type, InputStream inputStream);
|
String uploadPrivateKey(String tenantId, String type, InputStream inputStream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取私钥文件
|
* 获取私钥文件
|
||||||
*
|
*
|
||||||
@@ -25,7 +25,7 @@ public interface PrivateKeyService {
|
|||||||
* @return 私钥文件内容
|
* @return 私钥文件内容
|
||||||
*/
|
*/
|
||||||
String getPrivateKey(String tenantId, String type);
|
String getPrivateKey(String tenantId, String type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除私钥文件
|
* 删除私钥文件
|
||||||
*
|
*
|
||||||
@@ -34,4 +34,4 @@ public interface PrivateKeyService {
|
|||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
boolean deletePrivateKey(String tenantId, String type);
|
boolean deletePrivateKey(String tenantId, String type);
|
||||||
}
|
}
|
||||||
-55
@@ -1,55 +0,0 @@
|
|||||||
package com.central.user.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.central.user.model.SysWechatConfig;
|
|
||||||
|
|
||||||
public interface SysWechatConfigService extends IService<SysWechatConfig> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取微信配置
|
|
||||||
*
|
|
||||||
* @param type 配置类型
|
|
||||||
* @return 微信配置
|
|
||||||
*/
|
|
||||||
SysWechatConfig getConfig(String type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存微信配置
|
|
||||||
*
|
|
||||||
* @param config 微信配置
|
|
||||||
* @return 是否成功
|
|
||||||
*/
|
|
||||||
boolean saveConfig(SysWechatConfig config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新微信配置
|
|
||||||
*
|
|
||||||
* @param config 微信配置
|
|
||||||
* @return 是否成功
|
|
||||||
*/
|
|
||||||
boolean updateConfig(SysWechatConfig config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除微信配置
|
|
||||||
*
|
|
||||||
* @param id 配置ID
|
|
||||||
* @return 是否成功
|
|
||||||
*/
|
|
||||||
boolean deleteConfig(Long id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 切换当前使用的微信配置
|
|
||||||
*
|
|
||||||
* @param type 配置类型
|
|
||||||
* @return 是否成功
|
|
||||||
*/
|
|
||||||
boolean switchConfig(String type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前使用的微信配置
|
|
||||||
*
|
|
||||||
* @param type 配置类型
|
|
||||||
* @return 微信配置
|
|
||||||
*/
|
|
||||||
SysWechatConfig getCurrentConfig(String type);
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.zlt.wechat.service;
|
package com.central.user.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.zlt.wechat.service;
|
package com.central.user.service;
|
||||||
|
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||||
+7
-7
@@ -1,6 +1,6 @@
|
|||||||
package com.zlt.wechat.service.impl;
|
package com.central.user.service.impl;
|
||||||
|
|
||||||
import com.zlt.wechat.service.PrivateKeyService;
|
import com.central.user.service.PrivateKeyService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -30,11 +30,11 @@ public class PrivateKeyServiceImpl implements PrivateKeyService {
|
|||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
content.append(line).append("\n");
|
content.append(line).append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 缓存私钥内容
|
// 缓存私钥内容
|
||||||
String cacheKey = String.format(CACHE_KEY_PATTERN, tenantId, type);
|
String cacheKey = String.format(CACHE_KEY_PATTERN, tenantId, type);
|
||||||
redisTemplate.opsForValue().set(cacheKey, content.toString(), CACHE_EXPIRE_DAYS, TimeUnit.DAYS);
|
redisTemplate.opsForValue().set(cacheKey, content.toString(), CACHE_EXPIRE_DAYS, TimeUnit.DAYS);
|
||||||
|
|
||||||
return cacheKey;
|
return cacheKey;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("上传私钥文件失败", e);
|
throw new RuntimeException("上传私钥文件失败", e);
|
||||||
@@ -45,11 +45,11 @@ public class PrivateKeyServiceImpl implements PrivateKeyService {
|
|||||||
public String getPrivateKey(String tenantId, String type) {
|
public String getPrivateKey(String tenantId, String type) {
|
||||||
String cacheKey = String.format(CACHE_KEY_PATTERN, tenantId, type);
|
String cacheKey = String.format(CACHE_KEY_PATTERN, tenantId, type);
|
||||||
String privateKey = redisTemplate.opsForValue().get(cacheKey);
|
String privateKey = redisTemplate.opsForValue().get(cacheKey);
|
||||||
|
|
||||||
if (!StringUtils.hasText(privateKey)) {
|
if (!StringUtils.hasText(privateKey)) {
|
||||||
throw new RuntimeException("私钥文件不存在");
|
throw new RuntimeException("私钥文件不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
return privateKey;
|
return privateKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,4 +58,4 @@ public class PrivateKeyServiceImpl implements PrivateKeyService {
|
|||||||
String cacheKey = String.format(CACHE_KEY_PATTERN, tenantId, type);
|
String cacheKey = String.format(CACHE_KEY_PATTERN, tenantId, type);
|
||||||
return redisTemplate.delete(cacheKey);
|
return redisTemplate.delete(cacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-61
@@ -1,61 +0,0 @@
|
|||||||
package com.central.user.service.impl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.central.common.context.TenantContextHolder;
|
|
||||||
import com.central.user.mapper.SysWechatConfigMapper;
|
|
||||||
import com.central.user.model.SysWechatConfig;
|
|
||||||
import com.central.user.service.SysWechatConfigService;
|
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class SysWechatConfigServiceImpl extends ServiceImpl<SysWechatConfigMapper, SysWechatConfig>
|
|
||||||
implements SysWechatConfigService {
|
|
||||||
|
|
||||||
private static final String CACHE_NAME = "wechat:config";
|
|
||||||
private static final String CACHE_KEY_PATTERN = "#type";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Cacheable(value = CACHE_NAME, key = CACHE_KEY_PATTERN, unless = "#result == null")
|
|
||||||
public SysWechatConfig getConfig(String type) {
|
|
||||||
return getOne(new LambdaQueryWrapper<SysWechatConfig>()
|
|
||||||
.eq(SysWechatConfig::getType, type)
|
|
||||||
.eq(SysWechatConfig::getTenantId, TenantContextHolder.getTenant())
|
|
||||||
.eq(SysWechatConfig::getStatus, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@CacheEvict(value = CACHE_NAME, key = CACHE_KEY_PATTERN)
|
|
||||||
public boolean saveConfig(SysWechatConfig config) {
|
|
||||||
config.setTenantId(TenantContextHolder.getTenant());
|
|
||||||
return save(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@CacheEvict(value = CACHE_NAME, key = CACHE_KEY_PATTERN)
|
|
||||||
public boolean updateConfig(SysWechatConfig config) {
|
|
||||||
config.setTenantId(TenantContextHolder.getTenant());
|
|
||||||
return updateById(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@CacheEvict(value = CACHE_NAME, allEntries = true)
|
|
||||||
public boolean deleteConfig(Long id) {
|
|
||||||
return removeById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@CacheEvict(value = CACHE_NAME, key = CACHE_KEY_PATTERN)
|
|
||||||
public boolean switchConfig(String type) {
|
|
||||||
// 这里可以添加切换配置的具体逻辑
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Cacheable(value = CACHE_NAME, key = "'current:' + #type", unless = "#result == null")
|
|
||||||
public SysWechatConfig getCurrentConfig(String type) {
|
|
||||||
return getConfig(type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+5
-3
@@ -1,12 +1,13 @@
|
|||||||
package com.zlt.wechat.service.impl;
|
package com.central.user.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.user.mapper.WechatConfigMapper;
|
||||||
|
import com.central.user.service.WechatConfigService;
|
||||||
import com.zlt.wechat.entity.WechatConfig;
|
import com.zlt.wechat.entity.WechatConfig;
|
||||||
import com.zlt.wechat.mapper.WechatConfigMapper;
|
import lombok.RequiredArgsConstructor;
|
||||||
import com.zlt.wechat.service.WechatConfigService;
|
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
@@ -15,6 +16,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
@Service
|
@Service
|
||||||
public class WechatConfigServiceImpl extends ServiceImpl<WechatConfigMapper, WechatConfig> implements WechatConfigService {
|
public class WechatConfigServiceImpl extends ServiceImpl<WechatConfigMapper, WechatConfig> implements WechatConfigService {
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
//package com.zlt.wechat.service.impl;
|
package com.central.user.service.impl;//package com.zlt.wechat.service.impl;
|
||||||
//
|
//
|
||||||
//import com.wechat.pay.java.core.Config;
|
//import com.wechat.pay.java.core.Config;
|
||||||
//import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
//import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||||
+2
-1
@@ -22,6 +22,7 @@
|
|||||||
<module>zlt-elasticsearch-spring-boot-starter</module>
|
<module>zlt-elasticsearch-spring-boot-starter</module>
|
||||||
<module>zlt-oss-spring-boot-starter</module>
|
<module>zlt-oss-spring-boot-starter</module>
|
||||||
<module>zlt-zookeeper-spring-boot-starter</module>
|
<module>zlt-zookeeper-spring-boot-starter</module>
|
||||||
<!--<module>zlt-iot-spring-boot-starter</module>-->
|
<module>zlt-wechat-common-core</module>
|
||||||
|
<module>zlt-wechat-spring-boot-starter</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package com.zlt.wechat.feign;
|
||||||
|
|
||||||
|
import com.central.common.constant.ServiceNameConstants;
|
||||||
|
import com.zlt.wechat.feign.fallback.PrivateKeyServiceFallbackFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zlt
|
||||||
|
*/
|
||||||
|
@FeignClient(name = ServiceNameConstants.USER_SERVICE, fallbackFactory = PrivateKeyServiceFallbackFactory.class, dismiss404 = true)
|
||||||
|
public interface PrivateKeyService {
|
||||||
|
/**
|
||||||
|
* feign rpc访问远程/wechat/config/{type}接口
|
||||||
|
* 查询微信配置对象WechatConfig
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/wechat/config/{type}")
|
||||||
|
String getPrivateKey(@PathVariable("type") String type, @RequestParam("tenantId") String tenantId);
|
||||||
|
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package com.zlt.wechat.feign;
|
||||||
|
|
||||||
|
import com.central.common.constant.ServiceNameConstants;
|
||||||
|
import com.zlt.wechat.entity.WechatConfig;
|
||||||
|
import com.zlt.wechat.feign.fallback.WechatConfigServiceFallbackFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zlt
|
||||||
|
*/
|
||||||
|
@FeignClient(name = ServiceNameConstants.USER_SERVICE, fallbackFactory = WechatConfigServiceFallbackFactory.class, dismiss404 = true)
|
||||||
|
public interface WechatConfigService {
|
||||||
|
/**
|
||||||
|
* feign rpc访问远程/wechat/config/{type}接口
|
||||||
|
* 查询微信配置对象WechatConfig
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/wechat/config/{type}")
|
||||||
|
WechatConfig getConfig(@PathVariable("type") String type,String tenantId);
|
||||||
|
|
||||||
|
@GetMapping(value = "/app/{id}")
|
||||||
|
WechatConfig getConfig(String appId);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package com.zlt.wechat.feign.fallback;
|
||||||
|
|
||||||
|
import com.zlt.wechat.feign.PrivateKeyService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* userService降级工场
|
||||||
|
*
|
||||||
|
* @author zlt
|
||||||
|
* @date 2019/1/18
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class PrivateKeyServiceFallbackFactory implements FallbackFactory<PrivateKeyService> {
|
||||||
|
@Override
|
||||||
|
public PrivateKeyService create(Throwable throwable) {
|
||||||
|
return new PrivateKeyService() {
|
||||||
|
@Override
|
||||||
|
public String getPrivateKey(String tenantId,String type) {
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package com.zlt.wechat.feign.fallback;
|
||||||
|
|
||||||
|
import com.zlt.wechat.entity.WechatConfig;
|
||||||
|
import com.zlt.wechat.feign.WechatConfigService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* userService降级工场
|
||||||
|
*
|
||||||
|
* @author zlt
|
||||||
|
* @date 2019/1/18
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class WechatConfigServiceFallbackFactory implements FallbackFactory<WechatConfigService> {
|
||||||
|
@Override
|
||||||
|
public WechatConfigService create(Throwable throwable) {
|
||||||
|
return new WechatConfigService() {
|
||||||
|
@Override
|
||||||
|
public WechatConfig getConfig(String type,String tenantId) {
|
||||||
|
|
||||||
|
return new WechatConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WechatConfig getConfig(String appId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
com.zlt.wechat.feign.fallback.PrivateKeyServiceFallbackFactory
|
||||||
|
com.zlt.wechat.feign.fallback.WechatConfigServiceFallbackFactory
|
||||||
|
|
||||||
|
|
||||||
+2
-3
@@ -13,8 +13,8 @@ import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo;
|
|||||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||||
import com.wechat.pay.java.service.refund.RefundService;
|
import com.wechat.pay.java.service.refund.RefundService;
|
||||||
import com.zlt.wechat.entity.WechatConfig;
|
import com.zlt.wechat.entity.WechatConfig;
|
||||||
import com.zlt.wechat.service.WechatConfigService;
|
import com.zlt.wechat.feign.PrivateKeyService;
|
||||||
import com.zlt.wechat.service.PrivateKeyService;
|
import com.zlt.wechat.feign.WechatConfigService;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||||
@@ -161,7 +161,6 @@ public class WechatAutoConfiguration {
|
|||||||
executor.initialize();
|
executor.initialize();
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前商户ID
|
* 获取当前商户ID
|
||||||
* 这里需要根据实际业务场景实现,可以从ThreadLocal、请求上下文等获取
|
* 这里需要根据实际业务场景实现,可以从ThreadLocal、请求上下文等获取
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
com.zlt.wechat.config.WechatAutoConfiguration
|
com.zlt.wechat.config.WechatAutoConfiguration
|
||||||
|
|||||||
+6
-3
@@ -46,6 +46,11 @@
|
|||||||
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zlt</groupId>
|
||||||
|
<artifactId>zlt-wechat-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
@@ -94,9 +99,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zlt</groupId>
|
<groupId>com.zlt</groupId>
|
||||||
<artifactId>zlt-wechat-common-core</artifactId>
|
<artifactId>zlt-wechat-spring-boot-starter</artifactId>
|
||||||
<version>6.0.0</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||||||
/**
|
/**
|
||||||
* @author zlt
|
* @author zlt
|
||||||
*/
|
*/
|
||||||
@EnableFeignClients
|
@EnableFeignClients(basePackages = {"com.central", "com.zlt.wechat.feign"})
|
||||||
@MapperScan(basePackages = "com.central.oauth.mapper")
|
@MapperScan(basePackages = "com.central.oauth.mapper")
|
||||||
@EnableFeignInterceptor
|
@EnableFeignInterceptor
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ public class AuthorizationServerConfig {
|
|||||||
private final RegisteredClientService registeredClientService;
|
private final RegisteredClientService registeredClientService;
|
||||||
private final RedisSecurityContextRepository securityContextRepository;
|
private final RedisSecurityContextRepository securityContextRepository;
|
||||||
private final AuthenticationSuccessHandler authenticationSuccessHandler;
|
private final AuthenticationSuccessHandler authenticationSuccessHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* spring security 默认的安全策略
|
* spring security 默认的安全策略
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import com.central.common.model.SysUser;
|
|||||||
import com.central.common.utils.LoginUserUtils;
|
import com.central.common.utils.LoginUserUtils;
|
||||||
import com.central.oauth.service.ZltUserDetailsService;
|
import com.central.oauth.service.ZltUserDetailsService;
|
||||||
import com.zlt.wechat.entity.WechatConfig;
|
import com.zlt.wechat.entity.WechatConfig;
|
||||||
import com.zlt.wechat.service.WechatConfigService;
|
import com.zlt.wechat.feign.WechatConfigService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.authentication.DisabledException;
|
import org.springframework.security.authentication.DisabledException;
|
||||||
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
||||||
@@ -64,7 +64,8 @@ public class UserDetailServiceImpl implements ZltUserDetailsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WechatConfig loadMiniAppConfig(String appId) {
|
public WechatConfig loadMiniAppConfig(String appId) {
|
||||||
return wechatConfigService.getConfig(appId);
|
// return wechatConfigService.getConfig(appId);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,43 +9,43 @@
|
|||||||
export default {
|
export default {
|
||||||
dev: {
|
dev: {
|
||||||
'/api-uaa/': {
|
'/api-uaa/': {
|
||||||
// target: 'http://119.45.169.13:9900',
|
target: 'http://119.45.169.13:9900',
|
||||||
target: 'http://127.0.0.1:9900',
|
// target: 'http://127.0.0.1:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-user/': {
|
'/api-user/': {
|
||||||
// target: 'http://119.45.169.13:9900',
|
target: 'http://119.45.169.13:9900',
|
||||||
target: 'http://127.0.0.1:9900',
|
// target: 'http://127.0.0.1:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-log/': {
|
'/api-log/': {
|
||||||
// target: 'http://119.45.169.13:9900',
|
target: 'http://119.45.169.13:9900',
|
||||||
target: 'http://127.0.0.1:9900',
|
// target: 'http://127.0.0.1:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-search/': {
|
'/api-search/': {
|
||||||
// target: 'http://119.45.169.13:9900',
|
target: 'http://119.45.169.13:9900',
|
||||||
target: 'http://127.0.0.1:9900',
|
// target: 'http://127.0.0.1:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-generator/': {
|
'/api-generator/': {
|
||||||
// target: 'http://119.45.169.13:9900',
|
target: 'http://119.45.169.13:9900',
|
||||||
target: 'http://127.0.0.1:9900',
|
// target: 'http://127.0.0.1:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-file/': {
|
'/api-file/': {
|
||||||
// target: 'http://119.45.169.13:9900',
|
target: 'http://119.45.169.13:9900',
|
||||||
target: 'http://127.0.0.1:9900',
|
// target: 'http://127.0.0.1:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-order/': {
|
'/api-order/': {
|
||||||
// target: 'http://119.45.169.13:9900',
|
target: 'http://119.45.169.13:9900',
|
||||||
target: 'http://127.0.0.1:9900',
|
// target: 'http://127.0.0.1:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/api-device/': {
|
'/api-device/': {
|
||||||
// target: 'http://119.45.169.13:9900',
|
target: 'http://119.45.169.13:9900',
|
||||||
target: 'http://127.0.0.1:9900',
|
// target: 'http://127.0.0.1:9900',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user