6 Commits

Author SHA1 Message Date
fb9dd6fc89 update gitignore 2023-06-28 11:38:50 +07:00
e4e080266a fix bug empty logs 2023-06-19 11:30:46 +07:00
82a5b0d0ad update not insert duplicate logs 2023-06-14 13:49:01 +07:00
21cc5f2050 add logs api synclogs 2023-06-12 14:36:07 +07:00
ea202ccc3f update file_get_content timeout 2023-06-09 11:59:55 +07:00
58a5522642 fix bug exception get logs 2023-06-09 11:48:30 +07:00
3 changed files with 56 additions and 36 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@
/web/data /web/data
/vendor/ /vendor/
/nbproject/private/ /nbproject/private/
/db

View File

@@ -6,5 +6,6 @@ return [
"maxLogs" => 50000, "maxLogs" => 50000,
"maxPicture" => 9999, "maxPicture" => 9999,
"version" => "1.0.7", "version" => "1.0.7",
"autoSyncLog" => false "autoSyncLog" => false,
"timeoutRequestServer" => 4
]; ];

View File

@@ -58,6 +58,7 @@ class ApiController extends Controller {
public function actionGetLogs() { public function actionGetLogs() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$post = Yii::$app->request->bodyParams; $post = Yii::$app->request->bodyParams;
$time = date_format(date_create_from_format('Y-m-d H:i:s', $post['time']), 'U'); $time = date_format(date_create_from_format('Y-m-d H:i:s', $post['time']), 'U');
$key = common::generateRandomString(); $key = common::generateRandomString();
@@ -73,6 +74,11 @@ class ApiController extends Controller {
@unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $lastLogs->image); @unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $lastLogs->image);
$lastLogs->delete(); $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(); $model = new CaptureLogs();
$logs = $model->create([ $logs = $model->create([
@@ -107,8 +113,9 @@ class ApiController extends Controller {
$data[] = "123"; //person_id $data[] = "123"; //person_id
$data[] = "+7"; //timezone $data[] = "+7"; //timezone
$text = implode("|", $data); $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' => [ 'http' => [
'timeout' => Yii::$app->params['timeoutRequestServer'],
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
'method' => "POST", 'method' => "POST",
'content' => json_encode([ 'content' => json_encode([
@@ -118,12 +125,13 @@ class ApiController extends Controller {
]) ])
] ]
])), true); ])), true);
if ($res['status'] == 10000) { if ($res && $res['status'] == 10000) {
$logsInfo->sync_status = 1; $logsInfo->sync_status = 1;
$logsInfo->save(); $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"]; 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)) { if (file_exists("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value->image)) {
$staffInfo = ListManagement::findOne($value->staff_id); $staffInfo = ListManagement::findOne($value->staff_id);
$confidence = json_decode($value->confidence, true); $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' => [ 'http' => [
'timeout' => Yii::$app->params['timeoutRequestServer'],
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
'method' => "POST", 'method' => "POST",
'content' => json_encode([ 'content' => json_encode([
'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value->image)), 'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value->image)),
'camera_id' => strval($id_camera), 'data' => common::rsaEncode($text),
'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 'confidence' => isset($confidence['percent1']) ? floatval($confidence['percent1']) : 0
]) ])
] ]
])), true); ])), true);
if ($res['status'] == 10000) { if ($res && $res['status'] == 10000) {
$value->sync_status = 1; $value->sync_status = 1;
$value->save(); $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 { } else {
$value->delete(); $value->delete();
@@ -395,8 +409,10 @@ class ApiController extends Controller {
if ($connected) { if ($connected) {
$is_conn = true; //action when connected $is_conn = true; //action when connected
fclose($connected); fclose($connected);
// file_put_contents("log_connect_server.txt", "\n" . date("H:i:s d/m/Y") . " connected " . $host . ":" . $port, FILE_APPEND);
} else { } else {
$is_conn = false; //action in connection failure $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; return $is_conn;
} }
@@ -491,12 +507,14 @@ class ApiController extends Controller {
} }
public function actionTest() { public function actionTest() {
// $updating = \app\models\SyncUrl::findOne(['key_config' => 'token']); $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$updating = \app\models\SyncUrl::find()->all(); $ip = "https://dev-dc.beetai.com";
foreach ($updating as $key => $value) { if ($server_ip)
echo $value->key_config . " " . $value->data . "<br>"; $ip = $server_ip->data;
} $parseUrl = parse_url($ip);
exit(); $host = $parseUrl['host'];
$port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
$this->is_connected($host, $port);
} }
public function actionReGenFeature() { public function actionReGenFeature() {