新增设备暂停/继续命令

This commit is contained in:
Yu Sun
2022-08-19 17:06:18 +08:00
parent 69173cb7a1
commit a01cf0b232

View File

@@ -11,44 +11,57 @@ class ECommand {
$command2API = [
'server_restart' => '/Admin/ServerCloseAndRestart',
'server_close' => '/Admin/ServerClose',
'device_stop' => '/Edge/DeviceStopRequest',
'device_continue' => 'Edge/DeviceContinueRequest'
];
if (str_starts_with($this -> post -> command, 'server')) {
$res = pg_query($this -> dbconn, sprintf(
"SELECT url, port
FROM hf_mes_scada_edgeserver_controller_server
WHERE id = '%s'",
$this -> post -> server_id
));
$server_info = pg_fetch_row($res);
$res = pg_query($this -> dbconn, sprintf(
"SELECT url, port
FROM hf_mes_scada_edgeserver_controller_server
WHERE id = '%s'",
$this -> post -> server_id
));
$server_info = pg_fetch_row($res);
if (str_starts_with($this -> post -> command, 'server'))
$ch = curl_init(
$server_info[0]
. ":"
. $server_info[1]
. $command2API[$this -> post -> command]
);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt(
$ch,
CURLOPT_USERPWD,
$this -> post -> username
else if (str_starts_with($this -> post -> command, 'device'))
$ch = curl_init(
$server_info[0]
. ":"
. $this -> post -> password
. $server_info[1]
. $command2API[$this -> post -> command]
. '?data='
. $this -> post -> device_id
);
else
return;
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt(
$ch,
CURLOPT_USERPWD,
$this -> post -> username
. ":"
. $this -> post -> password
);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$return = curl_exec($ch);
curl_close($ch);
if ($return) {
pg_update(
$this -> dbconn,
"hf_mes_scada_edgeserver_controller_server",
['updated' => false],
['id' => $this -> post -> server_id]
);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$return = curl_exec($ch);
curl_close($ch);
if ($return) {
pg_update(
$this -> dbconn,
"hf_mes_scada_edgeserver_controller_server",
['updated' => false],
['id' => $this -> post -> server_id]
);
}
}
pg_insert(
@@ -56,6 +69,7 @@ class ECommand {
'hf_mes_scada_edgeserver_controller_command',
[
'server_id' => $this -> post -> server_id,
'device_id' => $this -> post -> server_id ?? NULL,
'command' => $this -> post -> command,
'success' => $return
],