production/Controleur/ControleurTesterreconnaissancefaciale.php
2025-12-02 11:29:44 +00:00

129 lines
4.0 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once 'Framework/Controleur.php';
require_once 'Modele/Societeusercentral.php';
require_once 'Modele/Menuvueutilisateur.php';
class ControleurTesterreconnaissancefaciale extends Controleur {
private $menuvue;
private $societeusercentral;
public function __construct()
{
$this->menuvue = new Menuvueutilisateur();
$this->menuvue->getMenuVue('Testerreconnaissancefaciale');
$this->societeusercentral = new societeusercentral();
}
public function index()
{
$codeSociete = $_SESSION['codeSociete'];
// $paramreconnaissancefaciale = $this->societeusercentral->getSocieteusersReconnaissanceFaciale($codeSociete);
// $this->genererVue(array('paramreconnaissancefaciale' => $paramreconnaissancefaciale));
$this->genererVue();
}
public function callback()
{
echo "Call back didit";
exit();
}
public function tester()
{
$apiKey = "lL18NHzgOta3_uKXYKcIG2s5a_Rys9Vq49JrDPVtESc";
$userImagePath = "/var/www/html/production/Temp/mbadan.jpg"; // photo prise en temps réel
$referenceImagePath = "/var/www/html/production/Temp/mbadan.jpg"; // photo d'identité ou d'enregistrement
// Vérification que les fichiers existent
if (!file_exists($userImagePath) || !file_exists($referenceImagePath))
{
die("Erreur : l'un des fichiers images n'existe pas.\n");
}
/*
$API_KEY = getenv('DIDIT_API_KEY'); // récupérée dans le Business Console
$WORKFLOW = getenv('DIDIT_BIO_WORKFLOW_ID'); // workflow "Biometric Authentication"
$CALLBACK = getenv('DIDIT_WEBHOOK_URL'); // votre endpoint webhook
*/
$API_KEY = "lL18NHzgOta3_uKXYKcIG2s5a_Rys9Vq49JrDPVtESc";
$WORKFLOW = "7ad9e67c-5859-45f3-ba3a-f36945400574"; // workflow "Biometric Authentication"
// $CALLBACK = "https://gestionnaire.ebene.ovh/Testerreconnaissancefaciale/callback/"; // votre endpoint webhook
$CALLBACK = "https://gestionnaire.ebene.ovh/faceebene/diditcallback.php"; // votre endpoint webhook
// 1) Charger et encoder en Base64 le portrait de référence (JPG/PNG)
/*
$portraitPath = __DIR__ . '/portrait_reference.jpg';
*/
$portraitPath = "/var/www/html/production/Temp/mbadan.jpg";
$portraitB64 = base64_encode(file_get_contents($portraitPath));
// 2) Construire la charge utile pour créer la session
$payload = [
"workflow_id" => $WORKFLOW,
"vendor_data" => "lkane@ebene.info", // votre identifiant utilisateur
"callback" => $CALLBACK,
"metadata" => ["reason" => "login"], // champ libre optionnel
"portrait_image"=> $portraitB64 // <- clé pour activer Face Match 1:1
];
$ch = curl_init('https://verification.didit.me/v2/session/');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'accept: application/json',
'content-type: application/json',
'x-api-key: ' . $API_KEY
],
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
/*
var_dump
(
array
(
"response" => $response,
)
);
exit();
*/
if ($response === false) {
throw new RuntimeException('Erreur cURL: ' . curl_error($ch));
}
$code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($code < 200 || $code >= 300) {
throw new RuntimeException("Echec création session (HTTP $code): $response");
}
$session = json_decode($response, true);
// Conservez ces champs pour la suite
$urlVerification = $session['url'];
$sessionId = $session['session_id'];
$sessionToken = $session['session_token'];
/*
var_dump
(
array
(
"urlVerification" => $urlVerification,
"sessionId" => $sessionId,
"sessionToken" => $sessionToken,
)
);
exit();
*/
// 🔗 URL à présenter/rediriger à lutilisateur pour prendre le selfie + liveness
echo "Open verification URL: " . $session['url'] . PHP_EOL;
}
}