PHP code example of yungangunite / websocket-server-sdk

1. Go to this page and download the library: Download yungangunite/websocket-server-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/ */

    

yungangunite / websocket-server-sdk example snippets


use YG\WSServer\YGWSClient;

$client = new YGWSClient(
    'your_app_id',
    'your_app_secret',
    'http://your-server'  // 可选,默认为 http://your-server
);

try {
    $userData = $client->registerUser(
        'username',
        'password',
        '[email protected]',  // 可选
        [                     // 可选
            'phone' => '13800138000',
            'other_info' => '其他信息'
        ]
    );
    
    print_r($userData);
} catch (Exception $e) {
    echo "错误:" . $e->getMessage();
}

try {
    $wsToken = $client->getWsToken($userData['user_id']);
    print_r($wsToken);
} catch (Exception $e) {
    echo "错误:" . $e->getMessage();
}