物联网后台管理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

92 lines
2.9 KiB

<?php
namespace app\api\controller;
use app\common\SzxfjkSdk\SmartLocks;
use app\common\YingShiSdk\YingShiSdk;
use think\Request;
class Smartlock extends Base
{
/**
* 获取设备状态信息
* @param Request $request
* @return false|string
*/
public function deviceStatus(Request $request)
{
try {
if (!$request->isPost()) throw new \Exception("请求失败,仅允许POST请求方式");
$accessToken = $request->header('AccessToken');
$json = $request->getContent();
$param = json_decode($json, true);
if (empty($accessToken)) throw new \Exception('Header参数:AccessToken,不能为空');
if (empty($param['deviceSerial'])) throw new \Exception('deviceSerial参数,不能为空');
$curlData = YingShiSdk::DeviceStatus($accessToken,$param['deviceSerial']);
if (!is_array($curlData)) throw new \Exception($curlData);
return $this->jsonSuccess('操作成功',$curlData);
} catch (\Exception $e) {
return $this->jsonError($e->getMessage());
}
}
/**
* 获取单个设备信息
* @param Request $request
* @return false|string
*/
public function deviceInfo(Request $request)
{
try {
if (!$request->isPost()) throw new \Exception("请求失败,仅允许POST请求方式");
$accessToken = $request->header('AccessToken');
$json = $request->getContent();
$param = json_decode($json, true);
if (empty($accessToken)) throw new \Exception('Header参数:AccessToken,不能为空');
if (empty($param['deviceSerial'])) throw new \Exception('deviceSerial参数,不能为空');
$curlData = YingShiSdk::DeviceInfo($accessToken,$param['deviceSerial']);
if (!is_array($curlData)) throw new \Exception($curlData);
return $this->jsonSuccess('操作成功',$curlData);
} catch (\Exception $e) {
return $this->jsonError($e->getMessage());
}
}
/**
* 智能门锁-设备实时上报数据
* @param Request $request
* @return false|string
*/
public function smartLocks(Request $request)
{
try {
$deviceInfo = YingShiSdk::DeviceInfo('','',true);
if (!is_array($deviceInfo)) throw new \Exception($deviceInfo);
$deviceStatus = YingShiSdk::DeviceStatus('','',true);
if (!is_array($deviceStatus)) throw new \Exception($deviceStatus);
$param = array_merge($deviceInfo,$deviceStatus);
$pushRes = SmartLocks::TimingDataPush($param);
if (!$pushRes['status']) throw new \Exception($pushRes['msg']);
return $this->jsonSuccess();
} catch (\Exception $exception) {
return $this->jsonError($exception->getMessage());
}
}
}