From fc71a6c7b87d870f1e1e83fc2f72afe655b30614 Mon Sep 17 00:00:00 2001 From: dongpd Date: Fri, 9 Oct 2020 17:40:46 +0700 Subject: [PATCH] test connection --- controllers/DepartmentController.php | 53 ++++++++++++++++++++++++++-- views/device/index.tpl | 14 +++++--- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/controllers/DepartmentController.php b/controllers/DepartmentController.php index 6041b9bd..d38eb6db 100644 --- a/controllers/DepartmentController.php +++ b/controllers/DepartmentController.php @@ -240,14 +240,61 @@ class DepartmentController extends Controller { } public function actionTest() { - $test = file_get_contents("http://192.168.2.119:2001/TestConnection", false, stream_context_create([ + $timezone = [ + "DeviceIP" => "192.168.1.200", + "TimezoneId" => 1, + "SunTime1" => 0, "SunTime2" => 0, "SunTime3" => 0, + "MonTime1" => 0, "MonTime2" => 0, "MonTime3" => 0, + "TueTime1" => 0, "TueTime2" => 0, "TueTime3" => 0, + "WedTime1" => 0, "WedTime2" => 0, "WedTime3" => 0, + "ThuTime1" => 0, "ThuTime2" => 0, "ThuTime3" => 0, + "FriTime1" => $this->convertTime("8:30", "12:30"), "FriTime2" => $this->convertTime("13:30", "18:30"), "FriTime3" => 0, + "SatTime1" => 0, "SatTime2" => 0, "SatTime3" => 0, + "Hol1Time1" => 0, "Hol1Time2" => 0, "Hol1Time3" => 0, + "Hol2Time1" => 0, "Hol2Time2" => 0, "Hol2Time3" => 0, + "Hol3Time1" => 0, "Hol3Time2" => 0, "Hol3Time3" => 0 + ]; + $timezoneRq = $this->requestToMCard("/SetDeviceData/timezone", $timezone); + + $user = [ + "DeviceIP" => "192.168.1.200", + "CardNo" => 16673827, + "Pin" => 69, + "Password" => "", + "Group" => "", + "StartTime" => "", + "EndTime" => "" + ]; + $userRq = $this->requestToMCard("/SetDeviceData/user", $user); + + $userAuthor = [ + "DeviceIP" => "192.168.1.200", + "Pin" => 69, + "AuthorizeTimezoneId" => 1, + "AuthorizeDoorId" => 2 + ]; + + $userAuthorRq = $this->requestToMCard("/SetDeviceData/userauthorize", $userAuthor); + + return var_dump($timezoneRq, $userRq, $userAuthorRq); + } + + public function requestToMCard($path, $data) { + return file_get_contents("http://192.168.2.119:2001" . $path, false, stream_context_create([ 'http' => [ 'header' => "Content-Type: application/json", 'method' => "POST", - 'content' => json_encode(["DeviceIP" => "192.168.1.200"]) + 'content' => json_encode($data) ] ])); - return var_dump($test); + } + + public function convertTime($from, $to) { + $fTemp = explode(":", $from); + $front = dechex(intval($fTemp[0]) * 100 + intval($fTemp[1])); + $tTemp = explode(":", $to); + $back = dechex(intval($tTemp[0]) * 100 + intval($tTemp[1])); + return hexdec("0" . $front . "0" . $back); } } diff --git a/views/device/index.tpl b/views/device/index.tpl index d5eee435..3ceb7308 100644 --- a/views/device/index.tpl +++ b/views/device/index.tpl @@ -37,12 +37,12 @@ {GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, - 'layout'=> \app\helpers\DepartmentGrid::getLayout(), + 'layout'=> \app\helpers\CommonGrid::getLayout(), 'tableOptions' => [ 'class' => 'table table-striped table-bordered table-hover', 'style' => 'background:#fff;min-width:700px;' ], - 'rowOptions' => \app\helpers\DepartmentGrid::rows("device"), + 'rowOptions' => \app\helpers\CommonGrid::rows("device"), 'columns' => [ [ 'class' => 'yii\grid\SerialColumn', @@ -54,17 +54,21 @@ 'format' => 'raw', 'contentOptions' => ['class' => 'text-center'], 'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%'], - 'value' => \app\helpers\DepartmentGrid::checkbox("device") + 'value' => \app\helpers\CommonGrid::checkbox("device") ], 'name', + 'serial', 'ip_address', + 'status', + 'type', + 'area_id', [ 'attribute' => 'created_at', - 'value' => \app\helpers\DepartmentGrid::createdAt() + 'value' => \app\helpers\CommonGrid::createdAt() ], [ 'attribute' => 'modified_at', - 'value' => \app\helpers\DepartmentGrid::modifiedAt() + 'value' => \app\helpers\CommonGrid::modifiedAt() ] ] ])}