hitagi-entrada/classes/ArquivoRemoto.php

110 lines
3.5 KiB
PHP

<?php
namespace Hit\Ami;
class ArquivoRemoto
{
public $ip;
public $port;
public function __construct()
{
$this->ip = 'localhost';
$this->port = '8083';
}
public function runCURL($args = array())
{
$arr['url'] = isset($args['url']) ? $args['url'] : '';
$arr['port'] = isset($args['port']) ? $args['port'] : '';
$arr['postfields'] = isset($args['postfields']) ? $args['postfields'] : '';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => $arr['port'],
CURLOPT_URL => $arr['url'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $arr['postfields'],
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"User-Agent: insomnia/2023.5.8"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return array('error' => "cURL Error #:" . $err);
}
$arr = json_decode($response, true);
if (json_last_error() != JSON_ERROR_NONE) {
return array('error' => 'cURL response not JSON');
} else {
return $arr;
}
}
public function pegar($args = array())
{
$url = 'http://' . $this->ip . ':' . $this->port . '/pegar';
$arr = array();
$arr['auth'] = isset($args['auth']) ? $args['auth'] : '80889736666668f4e2b9008ec15f5ca5';
$arr['filedir'] = isset($args['filedir']) ? $args['filedir'] : '';
$arr['filename'] = isset($args['filename']) ? $args['filename'] : '';
$postfields = json_encode($arr);
unset($arr);
$argssend = array();
$argssend['url'] = $url;
$argssend['port'] = $this->port;
$argssend['postfields'] = $postfields;
return $this->runCURL($argssend);
}
public function salvar($args = array())
{
$url = 'http://' . $this->ip . ':' . $this->port . '/salvar';
$arr = array();
$arr['auth'] = isset($args['auth']) ? $args['auth'] : '80889736666668f4e2b9008ec15f5ca5';
$arr['filedir'] = isset($args['filedir']) ? $args['filedir'] : '';
$arr['filename'] = isset($args['filename']) ? $args['filename'] : '';
$arr['filebase64'] = isset($args['filebase64']) ? $args['filebase64'] : '';
$postfields = json_encode($arr);
unset($arr);
$argssend = array();
$argssend['url'] = $url;
$argssend['port'] = $this->port;
$argssend['postfields'] = $postfields;
return $this->runCURL($argssend);
}
public function excluir($args = array())
{
$url = 'http://' . $this->ip . ':' . $this->port . '/excluir';
$arr = array();
$arr['auth'] = isset($args['auth']) ? $args['auth'] : '80889736666668f4e2b9008ec15f5ca5';
$arr['filedir'] = isset($args['filedir']) ? $args['filedir'] : '';
$arr['filename'] = isset($args['filename']) ? $args['filename'] : '';
$postfields = json_encode($arr);
unset($arr);
$argssend = array();
$argssend['url'] = $url;
$argssend['port'] = $this->port;
$argssend['postfields'] = $postfields;
return $this->runCURL($argssend);
}
}