* @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' => null])->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("/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 + 60 * 60 * 7), 'idCard' => $staffInfo ? strval($staffInfo->code) : "0", "person_id" => "123", "timezone" => "+7" ]) ] ])), 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; } }