test connection

This commit is contained in:
dongpd 2020-10-09 17:40:46 +07:00
parent 70db83d3ab
commit fc71a6c7b8
2 changed files with 59 additions and 8 deletions

View File

@ -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);
}
}

View File

@ -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()
]
]
])}