PHP code example of sunnyphp / ttlock

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

    

sunnyphp / ttlock example snippets



declare(strict_types=1);

ion;
use SunnyPHP\TTLock\Entrypoint;
use SunnyPHP\TTLock\Request\Lock\GetList;
use SunnyPHP\TTLock\Request\Lock\Initialize;
use SunnyPHP\TTLock\Request\OAuth2\AccessToken;
use SunnyPHP\TTLock\Request\User\Register;
use SunnyPHP\TTLock\Transport;

// initial configuration
$entrypoint = new Entrypoint(
	new Configuration('client_id', 'client_secret', /* access token if needed */),
	new Transport(\Http\Adapter\Guzzle7\Client::createWithConfig([
		'verify' => false,	// disable certificates check
	])),
);

// register user; retrieve TTLock Cloud API username
$register = $entrypoint->getUserRegister(new Register('username', 'password'));
var_dump($register->getResponseArray());

// get access token; retrieve access token, refresh token, expiration, etc
$tokenResponse = $entrypoint->getOAuth2AccessToken(new AccessToken($register->getUsername(), 'password'));
var_dump($tokenResponse->getResponseArray());

// save token response to future requests or refreshing token
// ...

// inject access token to entrypoint configuration (most of the requests 
shell
composer