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