设备数据下行
parent
ff775ec9d5
commit
1414cfae3d
|
|
@ -5,7 +5,6 @@ namespace App\Console\Commands;
|
|||
use App\Models\Device;
|
||||
use App\Services\DeviceLogService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Throwable;
|
||||
|
||||
class DeviceLogSyncCommand extends Command
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class HttpClient
|
|||
* @param int $perPage
|
||||
* @return array
|
||||
*/
|
||||
public function getDeviceFlowList(string $deviceId, Carbon $start, Carbon $end, int $page = 1, int $perPage = 50): array
|
||||
public function deviceFlowList(string $deviceId, Carbon $start, Carbon $end, int $page = 1, int $perPage = 50): array
|
||||
{
|
||||
$result = $this->post('/api/deviceFlow/v1/list', [
|
||||
'device_id' => $deviceId,
|
||||
|
|
@ -38,9 +38,36 @@ class HttpClient
|
|||
],
|
||||
]);
|
||||
|
||||
if (data_get($result, 'success') !== true) {
|
||||
throw new RuntimeException(data_get($result, 'msg', '出错啦!'));
|
||||
}
|
||||
|
||||
return $result['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备数据下行
|
||||
*
|
||||
* @param string $deviceId
|
||||
* @param string $service
|
||||
* @param array $data
|
||||
* @param boolean $confirm
|
||||
* @param boolean $clear
|
||||
* @param boolean $schedule
|
||||
* @return array
|
||||
*/
|
||||
public function deviceDataDownlink(string $deviceId, string $service, array $data = [], bool $confirm = true, bool $clear = true, bool $schedule = false): array
|
||||
{
|
||||
return $this->post('/api/down', [
|
||||
'device_id' => $deviceId,
|
||||
'service_id' => $service,
|
||||
'parameter' => $data,
|
||||
'clear' => (int) $clear,
|
||||
'schedule' => (int) $schedule,
|
||||
'confirm' => (int) $confirm,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param array $data
|
||||
|
|
@ -77,13 +104,7 @@ class HttpClient
|
|||
'Signature' => $this->sign(compact('nonce', 'timestamp')),
|
||||
])->baseUrl(self::ENDPOINT_URL)->send($method, $url, $options);
|
||||
|
||||
$result = $response->throw()->json();
|
||||
|
||||
if (data_get($result, 'success') !== true) {
|
||||
throw new RuntimeException(data_get($result, 'msg', '出错啦!'));
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $response->throw()->json();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class DeviceLogService
|
|||
$perPage = 50;
|
||||
|
||||
do {
|
||||
$data = $httpClient->getDeviceFlowList(
|
||||
$data = $httpClient->deviceFlowList(
|
||||
$device->sn, $start, $end, $page, $perPage
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue