v.2.18
This commit is contained in:
81
commands/GETImportMenu.php
Normal file
81
commands/GETImportMenu.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETImportMenu extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getimportmenu';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$HRCPortalURL = 'https://portal.hrc.by/';
|
||||
$folder = 'menu';
|
||||
$terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->first();
|
||||
$url = $HRCPortalURL . 'api/cloud/list?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&folder=' . $folder;
|
||||
$search = curl_init();
|
||||
|
||||
curl_setopt_array($search, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
));
|
||||
$search_response = curl_exec($search);
|
||||
curl_close($search);
|
||||
$responses = json_decode($search_response, TRUE)['files'];
|
||||
|
||||
/*{"status":"success","message":[{"size":"61671","mimetype":"application\/xml","timestamp":1655321649,"type":"file","path":"menu\/Menu_1_1.xml","dirname":"menu","basename":"Menu_1_1.xml","extension":"xml","filename":"Menu_1_1"}]}*/
|
||||
|
||||
foreach ($responses as $key => $response) {
|
||||
$filename = $response['basename'];
|
||||
//$path = '/backup/' . $filename . '.xml';
|
||||
$path = '/menu/' . $filename;
|
||||
$download_url = $HRCPortalURL . 'api/cloud/download?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&path=' . $path;
|
||||
$download = curl_init();
|
||||
|
||||
curl_setopt_array($download, array(
|
||||
CURLOPT_URL => $download_url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
));
|
||||
$download_response = curl_exec($download);
|
||||
curl_close($download);
|
||||
$file = json_decode($download_response, TRUE)['content'];
|
||||
}
|
||||
$dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\menu\\";
|
||||
if (!is_dir($dirname)) {
|
||||
mkdir($dirname, 0755, 'w+');
|
||||
}
|
||||
if (file_exists($dirname . $filename)) {
|
||||
unlink($dirname . $filename);
|
||||
}
|
||||
$handle = fopen($dirname . $filename, 'w+');
|
||||
fputs($handle, chr(0xEF) . chr(0xBB) . chr(0xBF)); // BOM
|
||||
file_put_contents($dirname . $filename, base64_decode($file));
|
||||
fclose($handle);
|
||||
$menu_file = $dirname . $filename;
|
||||
$objXmlDocument = simplexml_load_file($menu_file);
|
||||
$objJsonDocument = json_encode($objXmlDocument);
|
||||
$xmlmenu = json_decode($objJsonDocument, TRUE);
|
||||
$test = $xmlmenu['GeneralSettings']['@attributes'];
|
||||
/* $check_setting = Settings::where('code', 12)->first();
|
||||
$check_setting = $check_setting['value'] + 0;
|
||||
if ($check_setting == 0) {
|
||||
|
||||
}*/
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => $test,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user