BiFace_Server_Lite/commands/SyncController.php

79 lines
2.7 KiB
PHP

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace app\commands;
use yii\console\Controller;
use yii\console\ExitCode;
use app\models\CaptureLogs;
use app\models\ListManagement;
/**
* This command echoes the first argument that you have entered.
*
* This command is provided as an example for you to learn how to create console commands.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class SyncController extends Controller {
/**
* This command echoes what you have entered as the message.
* @param string $message the message to be echoed.
* @return int Exit code
*/
public function actionIndex() {
if ($this->is_connected()) {
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "dev-dc.beetai.com";
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
if ($device_id)
$id_camera = intval($device_id->data);
$ls = CaptureLogs::find()->andWhere(['<>', 'staff_id', 0])->andWhere(['sync_status' => 0])->all();
foreach ($ls as $key => $value) {
$staffInfo = ListManagement::findOne($value->staff_id);
$res = json_decode(file_get_contents("https://" . $ip . "/api/box/oem_face_recognition", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
'image' => base64_encode(file_get_contents(Yii::getAlias('@webroot') . "/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"
])
]
])), true);
if ($res['status'] == 10000) {
$value->sync_status = 1;
$value->save();
}
}
}
return ExitCode::OK;
}
function is_connected() {
$connected = @fsockopen("google.com", 80);
//website, port (try 80 or 443)
if ($connected) {
$is_conn = true; //action when connected
fclose($connected);
} else {
$is_conn = false; //action in connection failure
}
return $is_conn;
}
}