From b2f02817b1035fdd24d4b0ce71f6e92c04343f3b Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 4 Dec 2023 16:34:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E9=99=90=E5=88=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Smartlock.php | 34 ++++++++++++++++---- application/common/YingShiSdk/YingShiSdk.php | 20 ++++++------ 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/application/api/controller/Smartlock.php b/application/api/controller/Smartlock.php index 94887ab..fed6c55 100644 --- a/application/api/controller/Smartlock.php +++ b/application/api/controller/Smartlock.php @@ -8,13 +8,24 @@ use think\Request; class Smartlock extends Base { - public function deviceStatus() + /** + * 获取设备状态信息 + * @param Request $request + * @return false|string + */ + public function deviceStatus(Request $request) { try { - $request = Request::instance(); if (!$request->isPost()) throw new \Exception("请求失败,仅允许POST请求方式"); - $curlData = YingShiSdk::DeviceStatus(); + $accessToken = $request->header('AccessToken'); + $json = $request->getContent(); + $param = json_decode($json, true); + + if (empty($accessToken)) throw new \Exception('AccessToken参数,不能为空'); + if (empty($param['deviceSerial'])) throw new \Exception('deviceSerial参数,不能为空'); + + $curlData = YingShiSdk::DeviceStatus($accessToken,$param['deviceSerial']); if (!is_array($curlData)) throw new \Exception("cURL Error #:" . $curlData); @@ -24,13 +35,24 @@ class Smartlock extends Base } } - public function deviceInfo() + /** + * 获取单个设备信息 + * @param Request $request + * @return false|string + */ + public function deviceInfo(Request $request) { try { - $request = Request::instance(); if (!$request->isPost()) throw new \Exception("请求失败,仅允许POST请求方式"); - $curlData = YingShiSdk::DeviceInfo(); + $accessToken = $request->header('AccessToken'); + $json = $request->getContent(); + $param = json_decode($json, true); + + if (empty($accessToken)) throw new \Exception('AccessToken参数,不能为空'); + if (empty($param['deviceSerial'])) throw new \Exception('deviceSerial参数,不能为空'); + + $curlData = YingShiSdk::DeviceInfo($accessToken,$param['deviceSerial']); if (!is_array($curlData)) throw new \Exception("cURL Error #:" . $curlData); diff --git a/application/common/YingShiSdk/YingShiSdk.php b/application/common/YingShiSdk/YingShiSdk.php index 23f60bf..5165fe9 100644 --- a/application/common/YingShiSdk/YingShiSdk.php +++ b/application/common/YingShiSdk/YingShiSdk.php @@ -56,18 +56,18 @@ class YingShiSdk /** * 获取设备状态信息 + * @param $accessToken + * @param $deviceSerial * @return mixed|string */ - public static function DeviceStatus() + public static function DeviceStatus($accessToken,$deviceSerial) { - self::getAccessToken(); - $url = 'https://open.ys7.com/api/lapp/device/status/get'; $curlData = self::curlYingshiApi($url,[ - 'accessToken' => self::$accessToken, - 'deviceSerial' => self::$deviceSerial + 'accessToken' => $accessToken, + 'deviceSerial' => $deviceSerial ]); $err = $curlData['err']; @@ -84,18 +84,18 @@ class YingShiSdk /** * 获取单个设备信息 + * @param $accessToken + * @param $deviceSerial * @return mixed|string */ - public static function DeviceInfo() + public static function DeviceInfo($accessToken,$deviceSerial) { - self::getAccessToken(); - $url = 'https://open.ys7.com/api/lapp/device/info'; $curlDataInfo = YingShiSdk::curlYingshiApi($url,[ - 'accessToken' => self::$accessToken, - 'deviceSerial' => self::$deviceSerial + 'accessToken' => $accessToken, + 'deviceSerial' => $deviceSerial ]); $err = $curlDataInfo['err'];