diff --git a/app/Exceptions/EmqxSupportException.php b/app/Exceptions/EmqxSupportException.php new file mode 100644 index 0000000..5e84011 --- /dev/null +++ b/app/Exceptions/EmqxSupportException.php @@ -0,0 +1,10 @@ +clients($request->all()); + $clients = $emqx->clients([ + 'clientid' => $request->client_id, + 'username' => $request->username, + 'page' => $request->page, + ]); + // dd($clients); return view('admin.device.index', compact('clients')); } diff --git a/app/Support/EmqxSupport.php b/app/Support/EmqxSupport.php index 4f40524..cda12c2 100644 --- a/app/Support/EmqxSupport.php +++ b/app/Support/EmqxSupport.php @@ -2,6 +2,7 @@ namespace App\Support; +use App\Exceptions\EmqxSupportException; use Illuminate\Http\Client\PendingRequest; use Illuminate\Support\Facades\Http; @@ -12,6 +13,9 @@ private function api(): PendingRequest return Http::baseUrl(config('emqx.api_url'))->withBasicAuth(config('emqx.api_key'), config('emqx.api_secret')); } + /** + * @throws EmqxSupportException + */ public function clients($params = []) { // merge params @@ -25,7 +29,7 @@ public function clients($params = []) if ($response->successful()) { return $response->json(); } else { - return false; + throw new EmqxSupportException('无法获取客户端列表。'); } } diff --git a/resources/views/admin/device/index.blade.php b/resources/views/admin/device/index.blade.php index b895d14..9aa3409 100644 --- a/resources/views/admin/device/index.blade.php +++ b/resources/views/admin/device/index.blade.php @@ -84,4 +84,22 @@ +
+
+ +
+
+ @endsection