|
|
|
|
@@ -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([
|
|
|
|
|
@@ -107,23 +113,25 @@ 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([
|
|
|
|
|
'http' => [
|
|
|
|
|
'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/" . $fileName)),
|
|
|
|
|
'data' => common::rsaEncode($text),
|
|
|
|
|
'confidence' => isset($post["confidence"]["percent1"]) ? $post["confidence"]["percent1"] : 0
|
|
|
|
|
])
|
|
|
|
|
]
|
|
|
|
|
$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/" . $fileName)),
|
|
|
|
|
'data' => common::rsaEncode($text),
|
|
|
|
|
'confidence' => isset($post["confidence"]["percent1"]) ? $post["confidence"]["percent1"] : 0
|
|
|
|
|
])
|
|
|
|
|
]
|
|
|
|
|
])), 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"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -361,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([
|
|
|
|
|
'http' => [
|
|
|
|
|
'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",
|
|
|
|
|
'confidence' => isset($confidence['percent1']) ? floatval($confidence['percent1']) : 0
|
|
|
|
|
])
|
|
|
|
|
]
|
|
|
|
|
$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)),
|
|
|
|
|
'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();
|
|
|
|
|
@@ -395,8 +409,10 @@ class ApiController extends Controller {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
@@ -491,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() {
|
|
|
|
|
|