From 1414cfae3de00176888a076cdcd1a59f8fb08953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 17 Jul 2023 12:53:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=95=B0=E6=8D=AE=E4=B8=8B?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/DeviceLogSyncCommand.php | 1 - app/Iot/Linkos/HttpClient.php | 37 +++++++++++++++---- app/Services/DeviceLogService.php | 2 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/DeviceLogSyncCommand.php b/app/Console/Commands/DeviceLogSyncCommand.php index 8a900ea..28020b0 100644 --- a/app/Console/Commands/DeviceLogSyncCommand.php +++ b/app/Console/Commands/DeviceLogSyncCommand.php @@ -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 diff --git a/app/Iot/Linkos/HttpClient.php b/app/Iot/Linkos/HttpClient.php index 1b01273..0d3a725 100644 --- a/app/Iot/Linkos/HttpClient.php +++ b/app/Iot/Linkos/HttpClient.php @@ -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(); } /** diff --git a/app/Services/DeviceLogService.php b/app/Services/DeviceLogService.php index a345dd9..f5dfe3a 100644 --- a/app/Services/DeviceLogService.php +++ b/app/Services/DeviceLogService.php @@ -41,7 +41,7 @@ class DeviceLogService $perPage = 50; do { - $data = $httpClient->getDeviceFlowList( + $data = $httpClient->deviceFlowList( $device->sn, $start, $end, $page, $perPage );