|
|
|
|
@@ -58,6 +58,7 @@ class ApiController extends Controller {
|
|
|
|
|
|
|
|
|
|
public function actionGetLogs() {
|
|
|
|
|
if (Yii::$app->request->post()) {
|
|
|
|
|
Yii::$app->response->format = "json";
|
|
|
|
|
$post = Yii::$app->request->bodyParams;
|
|
|
|
|
$time = date_format(date_create_from_format('Y-m-d H:i:s', $post['time']), 'U');
|
|
|
|
|
$key = common::generateRandomString();
|
|
|
|
|
@@ -73,6 +74,11 @@ class ApiController extends Controller {
|
|
|
|
|
@unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $lastLogs->image);
|
|
|
|
|
$lastLogs->delete();
|
|
|
|
|
}
|
|
|
|
|
$lastLogs = CaptureLogs::find()->andWhere(["staff_id" => $post['id']])->orderBy(["time" => SORT_DESC])->limit(1)->one();
|
|
|
|
|
if ($lastLogs && ($time - $lastLogs->time) < 1) {
|
|
|
|
|
file_put_contents("log_connect_server.txt", "\n[" . date("H:i:s d/m/Y") . "] duplicate face " . $post["id"], FILE_APPEND);
|
|
|
|
|
return ["status" => "success"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$model = new CaptureLogs();
|
|
|
|
|
$logs = $model->create([
|
|
|
|
|
@@ -85,7 +91,10 @@ class ApiController extends Controller {
|
|
|
|
|
$ip = "https://dev-dc.beetai.com";
|
|
|
|
|
if ($server_ip)
|
|
|
|
|
$ip = $server_ip->data;
|
|
|
|
|
if ($this->is_connected() && $logs) {
|
|
|
|
|
$parseUrl = parse_url($ip);
|
|
|
|
|
$host = $parseUrl['host'];
|
|
|
|
|
$port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
|
|
|
|
|
if ($this->is_connected($host, $port) && $logs) {
|
|
|
|
|
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
|
|
|
|
$id_camera = 0;
|
|
|
|
|
if ($device_id)
|
|
|
|
|
@@ -104,8 +113,9 @@ class ApiController extends Controller {
|
|
|
|
|
$data[] = "123"; //person_id
|
|
|
|
|
$data[] = "+7"; //timezone
|
|
|
|
|
$text = implode("|", $data);
|
|
|
|
|
$res = json_decode(file_get_contents($ip . "/api/box/face_recognition_auth_v2?token=" . $tk, false, stream_context_create([
|
|
|
|
|
$res = json_decode(@file_get_contents($ip . "/api/box/face_recognition_auth_v2?token=" . $tk, false, stream_context_create([
|
|
|
|
|
'http' => [
|
|
|
|
|
'timeout' => Yii::$app->params['timeoutRequestServer'],
|
|
|
|
|
'header' => "Content-Type: application/json",
|
|
|
|
|
'method' => "POST",
|
|
|
|
|
'content' => json_encode([
|
|
|
|
|
@@ -115,12 +125,13 @@ class ApiController extends Controller {
|
|
|
|
|
])
|
|
|
|
|
]
|
|
|
|
|
])), true);
|
|
|
|
|
if ($res['status'] == 10000) {
|
|
|
|
|
if ($res && $res['status'] == 10000) {
|
|
|
|
|
$logsInfo->sync_status = 1;
|
|
|
|
|
$logsInfo->save();
|
|
|
|
|
} else {
|
|
|
|
|
file_put_contents("log_connect_server.txt", "\n[" . date("H:i:s d/m/Y") . "] /api/box/face_recognition_auth_v2 timeout " . $ip, FILE_APPEND);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Yii::$app->response->format = "json";
|
|
|
|
|
return ["status" => "success"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -337,17 +348,19 @@ class ApiController extends Controller {
|
|
|
|
|
|
|
|
|
|
public function actionSync() {
|
|
|
|
|
Yii::$app->response->format = "json";
|
|
|
|
|
if ($this->is_connected()) {
|
|
|
|
|
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
|
|
|
|
|
$ip = "https://dev-dc.beetai.com";
|
|
|
|
|
if ($server_ip)
|
|
|
|
|
$ip = $server_ip->data;
|
|
|
|
|
$parseUrl = parse_url($ip);
|
|
|
|
|
$host = $parseUrl['host'];
|
|
|
|
|
$port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
|
|
|
|
|
if ($this->is_connected($host, $port)) {
|
|
|
|
|
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
|
|
|
|
$id_camera = 0;
|
|
|
|
|
if ($device_id)
|
|
|
|
|
$id_camera = intval($device_id->data);
|
|
|
|
|
$ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all();
|
|
|
|
|
|
|
|
|
|
$tk = "";
|
|
|
|
|
$token = \app\models\SyncUrl::findOne(['key_config' => 'token']);
|
|
|
|
|
if ($token)
|
|
|
|
|
@@ -356,25 +369,31 @@ class ApiController extends Controller {
|
|
|
|
|
if (file_exists("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value->image)) {
|
|
|
|
|
$staffInfo = ListManagement::findOne($value->staff_id);
|
|
|
|
|
$confidence = json_decode($value->confidence, true);
|
|
|
|
|
$res = json_decode(file_get_contents($ip . "/api/oem/face_recognition?token=" . $tk, false, stream_context_create([
|
|
|
|
|
$data = [];
|
|
|
|
|
$data[] = strval($id_camera); //camera_id
|
|
|
|
|
$data[] = date("Y-m-d H:i:s", $value->time); //frametime
|
|
|
|
|
$data[] = $staffInfo ? strval($staffInfo->code) : "0"; //idCard
|
|
|
|
|
$data[] = $staffInfo ? $staffInfo->staff_id : ""; //idObject
|
|
|
|
|
$data[] = "123"; //person_id
|
|
|
|
|
$data[] = "+7"; //timezone
|
|
|
|
|
$text = implode("|", $data);
|
|
|
|
|
$res = json_decode(@file_get_contents($ip . "/api/box/face_recognition_auth_v2?token=" . $tk, false, stream_context_create([
|
|
|
|
|
'http' => [
|
|
|
|
|
'timeout' => Yii::$app->params['timeoutRequestServer'],
|
|
|
|
|
'header' => "Content-Type: application/json",
|
|
|
|
|
'method' => "POST",
|
|
|
|
|
'content' => json_encode([
|
|
|
|
|
'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value->image)),
|
|
|
|
|
'camera_id' => strval($id_camera),
|
|
|
|
|
'frametime' => date("Y-m-d H:i:s", $value->time),
|
|
|
|
|
'idCard' => $staffInfo ? strval($staffInfo->code) : "0",
|
|
|
|
|
'idObject' => $staffInfo ? $staffInfo->staff_id : "",
|
|
|
|
|
"person_id" => "123",
|
|
|
|
|
"timezone" => "+7",
|
|
|
|
|
'data' => common::rsaEncode($text),
|
|
|
|
|
'confidence' => isset($confidence['percent1']) ? floatval($confidence['percent1']) : 0
|
|
|
|
|
])
|
|
|
|
|
]
|
|
|
|
|
])), true);
|
|
|
|
|
if ($res['status'] == 10000) {
|
|
|
|
|
if ($res && $res['status'] == 10000) {
|
|
|
|
|
$value->sync_status = 1;
|
|
|
|
|
$value->save();
|
|
|
|
|
} else {
|
|
|
|
|
file_put_contents("log_connect_server.txt", "\n[" . date("H:i:s d/m/Y") . "][SYNC] face_recognition_auth_v2 timeout " . $ip, FILE_APPEND);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$value->delete();
|
|
|
|
|
@@ -384,14 +403,16 @@ class ApiController extends Controller {
|
|
|
|
|
return ["status" => true];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function is_connected($ip = "google.com") {
|
|
|
|
|
$connected = @fsockopen($ip, 80);
|
|
|
|
|
function is_connected($host, $port) {
|
|
|
|
|
$connected = @fsockopen($host, $port);
|
|
|
|
|
//website, port (try 80 or 443)
|
|
|
|
|
if ($connected) {
|
|
|
|
|
$is_conn = true; //action when connected
|
|
|
|
|
fclose($connected);
|
|
|
|
|
// file_put_contents("log_connect_server.txt", "\n" . date("H:i:s d/m/Y") . " connected " . $host . ":" . $port, FILE_APPEND);
|
|
|
|
|
} else {
|
|
|
|
|
$is_conn = false; //action in connection failure
|
|
|
|
|
file_put_contents("log_connect_server.txt", "\n[" . date("H:i:s d/m/Y") . "] disconnected " . $host . ":" . $port, FILE_APPEND);
|
|
|
|
|
}
|
|
|
|
|
return $is_conn;
|
|
|
|
|
}
|
|
|
|
|
@@ -486,12 +507,14 @@ class ApiController extends Controller {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function actionTest() {
|
|
|
|
|
// $updating = \app\models\SyncUrl::findOne(['key_config' => 'token']);
|
|
|
|
|
$updating = \app\models\SyncUrl::find()->all();
|
|
|
|
|
foreach ($updating as $key => $value) {
|
|
|
|
|
echo $value->key_config . " " . $value->data . "<br>";
|
|
|
|
|
}
|
|
|
|
|
exit();
|
|
|
|
|
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
|
|
|
|
|
$ip = "https://dev-dc.beetai.com";
|
|
|
|
|
if ($server_ip)
|
|
|
|
|
$ip = $server_ip->data;
|
|
|
|
|
$parseUrl = parse_url($ip);
|
|
|
|
|
$host = $parseUrl['host'];
|
|
|
|
|
$port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
|
|
|
|
|
$this->is_connected($host, $port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function actionReGenFeature() {
|
|
|
|
|
|