secure upload

master
yixian 8 years ago
parent e43b4b0f42
commit bb5d6dbd25

@ -4,18 +4,20 @@ import au.com.royalpay.payment.core.exceptions.ChannelNetworkException;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.system.core.TradeSecureService; import au.com.royalpay.payment.manage.system.core.TradeSecureService;
import au.com.royalpay.payment.manage.system.core.beans.TradeSecureFile; import au.com.royalpay.payment.manage.system.core.beans.TradeSecureFile;
import au.com.royalpay.payment.tools.env.SysConfigManager;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jcraft.jsch.*; import com.jcraft.jsch.*;
import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.provider.sftp.SftpClientFactory; import org.apache.commons.vfs2.provider.sftp.SftpClientFactory;
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -25,6 +27,7 @@ import java.util.List;
*/ */
@Service @Service
public class TradeSecureServiceHanyinImpl implements TradeSecureService { public class TradeSecureServiceHanyinImpl implements TradeSecureService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Value("${app.hanyin-secure.pid:ROYALPAY}") @Value("${app.hanyin-secure.pid:ROYALPAY}")
private String pid; private String pid;
@Value("${app.hanyin-secure.sftp-host}") @Value("${app.hanyin-secure.sftp-host}")
@ -37,9 +40,15 @@ public class TradeSecureServiceHanyinImpl implements TradeSecureService {
private String sftpPwd; private String sftpPwd;
@Resource @Resource
private TransactionMapper transactionMapper; private TransactionMapper transactionMapper;
@Resource
private SysConfigManager sysConfigManager;
@Override @Override
public void uploadSecureReportYesterday() { public void uploadSecureReportYesterday() {
if (!sysConfigManager.getSysConfig().getBooleanValue("production_flag")) {
return;
}
logger.debug("start uploading secure report");
uploadSecureReport(DateTime.now().plusDays(-1).withMillisOfDay(0).toDate()); uploadSecureReport(DateTime.now().plusDays(-1).withMillisOfDay(0).toDate());
} }
@ -59,9 +68,13 @@ public class TradeSecureServiceHanyinImpl implements TradeSecureService {
command = (ChannelSftp) channel; command = (ChannelSftp) channel;
command.ls("/royalpay"); command.ls("/royalpay");
String dir = "/royalpay/" + file.getTransDate().toString("yyyyMMdd"); String dir = "/royalpay/" + file.getTransDate().toString("yyyyMMdd");
logger.debug("removing dir:{}", dir);
command.rmdir(dir); command.rmdir(dir);
logger.debug("rmdir success");
logger.debug("mk dir:{}", dir);
command.mkdir(dir); command.mkdir(dir);
String dest = dir + file.filename(); String dest = dir + file.filename();
logger.debug("rmdir success, start uploading file:{}", dest);
command.put(new ByteArrayInputStream(file.content()), dest); command.put(new ByteArrayInputStream(file.content()), dest);
} catch (IOException | JSchException | SftpException e) { } catch (IOException | JSchException | SftpException e) {
throw new ChannelNetworkException("Upload Secure file failed", e); throw new ChannelNetworkException("Upload Secure file failed", e);

Loading…
Cancel
Save