|
@@ -12,28 +12,40 @@ namespace vendor;
|
|
|
|
|
|
use Log;
|
|
|
use refill;
|
|
|
-use refill\util;
|
|
|
|
|
|
class yifutongtax
|
|
|
{
|
|
|
const LocalPath = BASE_UPLOAD_PATH . "/YIFUTONG";
|
|
|
public function handle()
|
|
|
{
|
|
|
- $local_files = $this->down_files();
|
|
|
+// $local_files = $this->down_files();
|
|
|
// foreach ($local_files as $file) {
|
|
|
// Log::record("file=$file",Log::DEBUG);
|
|
|
// $this->parese_file($file);
|
|
|
// }
|
|
|
-
|
|
|
- foreach ($local_files as $file) {
|
|
|
- Log::record("file=$file",Log::DEBUG);
|
|
|
- $this->modify_time($file);
|
|
|
- }
|
|
|
+// foreach ($local_files as $file) {
|
|
|
+// Log::record("file=$file",Log::DEBUG);
|
|
|
+// $this->modify_time($file);
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
public function run()
|
|
|
{
|
|
|
+ //获取前一天数据
|
|
|
+ $cur_time = time();
|
|
|
+ $file = strftime("%Y%m%d_000110089970029",$cur_time - 86400);
|
|
|
+
|
|
|
+ $local_files = $this->down_file($file);
|
|
|
+ foreach ($local_files as $file) {
|
|
|
+ Log::record("file=$file",Log::DEBUG);
|
|
|
+ $this->parese_file($file);
|
|
|
+ }
|
|
|
|
|
|
+ sleep(60);
|
|
|
+ foreach ($local_files as $file) {
|
|
|
+ Log::record("file=$file",Log::DEBUG);
|
|
|
+ $this->modify_time($file);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -122,6 +134,62 @@ class yifutongtax
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private function down_file($file)
|
|
|
+ {
|
|
|
+ #北京业务的文件 sftp 221.122.92.145:10022 帐号 ylyw 密码 ylyw123
|
|
|
+ $conn = ssh2_connect('221.122.92.145', 10022);
|
|
|
+ if (!ssh2_auth_password($conn, 'ylyw', 'ylyw123')) {
|
|
|
+ Log::record("Cannot connect to ftp server.", Log::DEBUG);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $sftp = ssh2_sftp($conn);
|
|
|
+ if (!$sftp) {
|
|
|
+ Log::record('Cannot init SFTP');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $rpath_gen = function ($sftp) {
|
|
|
+ return "ssh2.sftp://" . intval($sftp) . "/";
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ $files_downloader = function ($sftp, $files, $local_path) use ($rpath_gen)
|
|
|
+ {
|
|
|
+ $local_files = [];
|
|
|
+ foreach ($files as $name)
|
|
|
+ {
|
|
|
+ $remote_file = $rpath_gen($sftp) . $name;
|
|
|
+
|
|
|
+ if (!file_exists($remote_file)) {
|
|
|
+ Log::record("$remote_file not exist.", Log::DEBUG);
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ Log::record("find file=$remote_file", Log::DEBUG);
|
|
|
+ }
|
|
|
+
|
|
|
+ $local_file = $local_path . "/$name";
|
|
|
+ Log::record("path=$local_file", Log::DEBUG);
|
|
|
+
|
|
|
+ if (!copy($remote_file, $local_file)) {
|
|
|
+ Log::record("copy $remote_file to $local_file error.", Log::DEBUG);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $local_files[] = $local_file;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $local_files;
|
|
|
+ };
|
|
|
+
|
|
|
+ $local_files = $files_downloader($sftp, [$file], static::LocalPath);
|
|
|
+
|
|
|
+ ssh2_disconnect($conn);
|
|
|
+
|
|
|
+ return $local_files;
|
|
|
+ }
|
|
|
+
|
|
|
private function down_files()
|
|
|
{
|
|
|
#北京业务的文件 sftp 221.122.92.145:10022 帐号 ylyw 密码 ylyw123
|