7 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
476f01098f update is_connected with dynamic server 2023-01-16 15:33:02 +07:00
3 changed files with 71 additions and 46 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([
@@ -85,7 +91,10 @@ class ApiController extends Controller {
$ip = "https://dev-dc.beetai.com"; $ip = "https://dev-dc.beetai.com";
if ($server_ip) if ($server_ip)
$ip = $server_ip->data; $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']); $device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 0; $id_camera = 0;
if ($device_id) if ($device_id)
@@ -104,23 +113,25 @@ 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' => [
'header' => "Content-Type: application/json", 'timeout' => Yii::$app->params['timeoutRequestServer'],
'method' => "POST", 'header' => "Content-Type: application/json",
'content' => json_encode([ 'method' => "POST",
'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName)), 'content' => json_encode([
'data' => common::rsaEncode($text), 'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName)),
'confidence' => isset($post["confidence"]["percent1"]) ? $post["confidence"]["percent1"] : 0 'data' => common::rsaEncode($text),
]) 'confidence' => isset($post["confidence"]["percent1"]) ? $post["confidence"]["percent1"] : 0
] ])
]
])), 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"];
} }
} }
@@ -337,17 +348,19 @@ class ApiController extends Controller {
public function actionSync() { public function actionSync() {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
if ($this->is_connected()) { $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']); $ip = "https://dev-dc.beetai.com";
$ip = "https://dev-dc.beetai.com"; if ($server_ip)
if ($server_ip) $ip = $server_ip->data;
$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']); $device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 0; $id_camera = 0;
if ($device_id) if ($device_id)
$id_camera = intval($device_id->data); $id_camera = intval($device_id->data);
$ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all(); $ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all();
$tk = ""; $tk = "";
$token = \app\models\SyncUrl::findOne(['key_config' => 'token']); $token = \app\models\SyncUrl::findOne(['key_config' => 'token']);
if ($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)) { 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 = [];
'http' => [ $data[] = strval($id_camera); //camera_id
'header' => "Content-Type: application/json", $data[] = date("Y-m-d H:i:s", $value->time); //frametime
'method' => "POST", $data[] = $staffInfo ? strval($staffInfo->code) : "0"; //idCard
'content' => json_encode([ $data[] = $staffInfo ? $staffInfo->staff_id : ""; //idObject
'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value->image)), $data[] = "123"; //person_id
'camera_id' => strval($id_camera), $data[] = "+7"; //timezone
'frametime' => date("Y-m-d H:i:s", $value->time), $text = implode("|", $data);
'idCard' => $staffInfo ? strval($staffInfo->code) : "0", $res = json_decode(@file_get_contents($ip . "/api/box/face_recognition_auth_v2?token=" . $tk, false, stream_context_create([
'idObject' => $staffInfo ? $staffInfo->staff_id : "", 'http' => [
"person_id" => "123", 'timeout' => Yii::$app->params['timeoutRequestServer'],
"timezone" => "+7", 'header' => "Content-Type: application/json",
'confidence' => isset($confidence['percent1']) ? floatval($confidence['percent1']) : 0 '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); ])), 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();
@@ -384,14 +403,16 @@ class ApiController extends Controller {
return ["status" => true]; return ["status" => true];
} }
function is_connected($ip = "google.com") { function is_connected($host, $port) {
$connected = @fsockopen($ip, 80); $connected = @fsockopen($host, $port);
//website, port (try 80 or 443) //website, port (try 80 or 443)
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;
} }
@@ -486,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() {