PHP code example of sunuid / php-sdk

1. Go to this page and download the library: Download sunuid/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sunuid / php-sdk example snippets




unuID\SunuID;

// Configuration du SDK
$config = [
    'client_id' => 'votre_client_id',
    'secret_id' => 'votre_secret_id',
    'partner_name' => 'Votre Entreprise',
    'theme' => 'light',
    'language' => 'fr'
];

// Initialisation
$sunuid = new SunuID($config);

// Initialiser avec l'API
if ($sunuid->init()) {
    echo "SDK initialisé avec succès\n";
    
    // Générer un QR code d'authentification
    $result = $sunuid->generateQR('https://votre-site.com/auth');
    
    if ($result['success']) {
        echo "QR Code généré: " . $result['data']['qr_code'] . "\n";
        echo "Session ID: " . $result['data']['session_id'] . "\n";
    }
}

// QR code avec API (authentification)
$result = $sunuid->generateQR('https://votre-site.com/auth');

// QR code local (sans API)
$result = $sunuid->generateQRLocal('https://votre-site.com', [
    'size' => 300,
    'margin' => 10
]);

// QR code avec WebSocket automatique
$result = $sunuid->generateQRWithWebSocket('https://votre-site.com/auth');

// Configuration avec Socket.IO
$config = [
    'client_id' => 'votre_client_id',
    'secret_id' => 'votre_secret_id',
    'partner_name' => 'Votre Entreprise',
    'enable_websocket' => true,
    'websocket_auto_connect' => true,
    'websocket_url' => 'https://samasocket.fayma.sn:9443',
    'websocket_socketio_version' => '2',
    'websocket_transports' => ['websocket', 'polling']
];

$sunuid = new SunuID($config);

// Initialiser et connecter le Socket.IO
$sunuid->initWebSocket();
if (!$sunuid->connectWebSocket()) {
    // Diagnostic rapide en cas d'échec
    echo "Erreur Socket.IO: " . ($sunuid->getWebSocketLastError() ?? 'inconnue') . "\n";
}

// Configurer les callbacks pour les événements
$sunuid->onWebSocketEvent('auth_success', function ($data) {
    echo "✅ Authentification réussie pour la session: " . $data['session_id'];
});

$sunuid->onWebSocketEvent('kyc_complete', function ($data) {
    echo "✅ KYC complété pour la session: " . $data['session_id'];
});

// S'abonner à une session spécifique
$sunuid->subscribeToSession('session_id_123');

// Envoyer un message personnalisé
$sunuid->sendWebSocketMessage([
    'event' => 'custom_event',
    'data' => ['message' => 'Hello!']
]);

$status = $sunuid->checkQRStatus('session_id_123');

if ($status['success']) {
    echo "Statut: " . $status['data']['status'] . "\n";
    if (isset($status['data']['user_data'])) {
        echo "Utilisateur: " . json_encode($status['data']['user_data']) . "\n";
    }
}

// KYC (Know Your Customer)
$sunuid = new SunuID(['type' => 1, ...]);

// Authentification
$sunuid = new SunuID(['type' => 2, ...]);

// Signature électronique
$sunuid = new SunuID(['type' => 3, ...]);

error_reporting(E_ALL ^ E_DEPRECATED);
bash
composer 
bash
git clone https://github.com/sunuid/php-sdk.git
cd sunuid-php-sdk
composer install
bash
php test_socketio_integration.php