Commit b4f9a226 authored by terrfly's avatar terrfly
Browse files

完成 对象存储多种方式的支持

parent ee361e2b
......@@ -25,6 +25,13 @@
<version>${isys.version}</version>
</dependency>
<!-- 依赖[ oss ]包 -->
<dependency>
<groupId>com.jeequan</groupId>
<artifactId>jeepay-oss</artifactId>
<version>${isys.version}</version>
</dependency>
<!-- 依赖 sping-boot-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -17,7 +17,6 @@ package com.jeequan.jeepay.pay.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.stereotype.Component;
/**
......@@ -35,22 +34,4 @@ public class SystemYmlConfig {
/** 是否允许跨域请求 [生产环境建议关闭, 若api与前端项目没有在同一个域名下时,应开启此配置或在nginx统一配置允许跨域] **/
private Boolean allowCors;
@NestedConfigurationProperty //指定该属性为嵌套值, 否则默认为简单值导致对象为空(外部类不存在该问题, 内部static需明确指定)
private OssFile ossFile;
/** 系统oss配置信息 **/
@Data
public static class OssFile{
/** 存储根路径 **/
private String rootPath;
/** 公共读取块 **/
private String publicPath;
/** 私有读取块 **/
private String privatePath;
}
}
\ No newline at end of file
}
......@@ -42,6 +42,7 @@ import com.jeequan.jeepay.service.impl.IsvInfoService;
import com.jeequan.jeepay.service.impl.MchAppService;
import com.jeequan.jeepay.service.impl.MchInfoService;
import com.jeequan.jeepay.service.impl.PayInterfaceConfigService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
......@@ -59,6 +60,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @site https://www.jeepay.vip
* @date 2021/6/8 17:41
*/
@Slf4j
@Service
public class ConfigContextService {
......@@ -354,7 +356,8 @@ public class ConfigContextService {
try {
alipayClient = new DefaultAlipayClient(certAlipayRequest);
} catch (AlipayApiException e) {
e.printStackTrace();
log.error("error" ,e);
alipayClient = null;
}
}else{
alipayClient = new DefaultAlipayClient(sandbox == CS.YES ? AlipayConfig.SANDBOX_SERVER_URL : AlipayConfig.PROD_SERVER_URL
......
package com.jeequan.jeepay.pay.util;
import cn.hutool.core.io.FileUtil;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.oss.config.OssYmlConfig;
import com.jeequan.jeepay.oss.constant.OssSavePlaceEnum;
import com.jeequan.jeepay.oss.constant.OssServiceTypeEnum;
import com.jeequan.jeepay.oss.service.IOssService;
import com.jeequan.jeepay.pay.config.SystemYmlConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
/*
* 支付平台 获取系统文件工具类
......@@ -16,13 +23,59 @@ import java.io.File;
@Component
public class ChannelCertConfigKitBean {
@Autowired private SystemYmlConfig systemYmlConfig;
@Autowired private OssYmlConfig ossYmlConfig;
@Autowired private IOssService ossService;
public String getCertFilePath(String certFilePath){
return systemYmlConfig.getOssFile().getPrivatePath() + File.separator + certFilePath;
return getCertFile(certFilePath).getAbsolutePath();
}
public File getCertFile(String certFilePath){
return new File(getCertFilePath(certFilePath));
File certFile = new File(ossYmlConfig.getOss().getFilePrivatePath() + File.separator + certFilePath);
if(certFile.exists()){ // 本地存在直接返回
return certFile;
}
// 以下为 文件不存在的处理方式
// 是否本地存储
boolean isLocalSave = OssServiceTypeEnum.LOCAL.equals(ossYmlConfig.getOss().getServiceType());
// 本地存储 & 文件不存在
if(isLocalSave){
return certFile;
}
// 已经向oss请求并且返回了空文件时
if(new File(certFile.getAbsolutePath() + ".notexists").exists()){
return certFile;
}
// 请求下载并返回 新File
return downloadFile(certFilePath, certFile);
}
/** 下载文件 **/
private synchronized File downloadFile(String dbCertFilePath, File certFile){
//请求文件并写入
boolean isSuccess = ossService.downloadFile(OssSavePlaceEnum.PRIVATE, dbCertFilePath, certFile.getAbsolutePath());
// 下载成功 返回新的File对象
if(isSuccess) {
return new File(certFile.getAbsolutePath());
}
// 下载失败, 写入.notexists文件, 避免那下次再次下载影响效率。
try {
new File(certFile.getAbsolutePath() + ".notexists").createNewFile();
} catch (IOException e) {
}
return certFile;
}
}
......@@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeequan.jeepay.core.entity.SysConfig;
import com.jeequan.jeepay.core.model.DBApplicationConfig;
import com.jeequan.jeepay.core.service.ISysConfigService;
import com.jeequan.jeepay.service.mapper.SysConfigMapper;
import org.apache.commons.lang3.tuple.MutablePair;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -36,7 +37,7 @@ import java.util.Set;
* @since 2020-07-29
*/
@Service
public class SysConfigService extends ServiceImpl<SysConfigMapper, SysConfig> {
public class SysConfigService extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService {
@Autowired
private SysConfigService sysConfigService;
......
......@@ -25,9 +25,12 @@
<module>jeepay-core</module> <!-- 基础函数, 包含工具类等 -->
<module>jeepay-service</module> <!-- db service等 -->
<module>jeepay-oss</module> <!-- oss服务支撑 -->
<module>jeepay-manager</module> <!-- 运营平台管理端 -->
<module>jeepay-merchant</module> <!-- 商户平台管理端 -->
<module>jeepay-payment</module> <!-- 支付统一网关 -->
</modules>
<!-- 配置属性声明, 支持自定义参数 -->
......@@ -120,6 +123,13 @@
<version>4.13.50.ALL</version>
</dependency>
<!-- 阿里云oss组件 -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.13.0</version>
</dependency>
</dependencies>
</dependencyManagement>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment