PHP code example of cruide / starline-openapi-php

1. Go to this page and download the library: Download cruide/starline-openapi-php 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/ */

    

cruide / starline-openapi-php example snippets


use Cruide\StarlineApi\StarlineApi;
use Cruide\StarlineApi\Auth\FileTokenStorage;
use Cruide\StarlineApi\Auth\GdOcr;

$api = new StarlineApi(
    appId: 123456,
    appSecret: 'your-secret',
    login: '[email protected]',
    password: 'password',
    tokenStorage: new FileTokenStorage('/var/tmp/starline-tokens.json'),
);

// Automatic captcha solving (pure PHP, ext-gd only)
$api->setOcr(new GdOcr());

$api->authenticate();

foreach ($api->user()->devices() as $device) {
    $state = $api->devices()->state($device->id());

    echo $device->alias(), ': ', $state->isArmed() ? 'armed' : 'disarmed', PHP_EOL;
}

$api = new StarlineApi(appId: 123, appSecret: '***');
$api->authenticateWithSlidToken('hash:user_id');

use Cruide\StarlineApi\Exceptions\StarlineAuthCaptchaException;

try {
    $api->authenticate();
} catch (StarlineAuthCaptchaException $e) {
    if ($e->isCaptchaRequired()) {
        // Show to user: $e->getCaptchaImg()
        $api->authenticateWithCaptcha($e->getCaptchaSid(), $userInput);
    } elseif ($e->isSmsRequired()) {
        // SMS sent to: $e->getPhone()
        $api->authenticateWithSms($smsCode);
    }
}

use Cruide\StarlineApi\Auth\TesseractOcr;

$api->setOcr(new TesseractOcr(lang: 'eng', psm: '8'));
$api->authenticate();  // captcha solved automatically

use Illuminate\Support\Facades\Cache;
use Cruide\StarlineApi\Auth\TokenStorageInterface;

final class CacheTokenStorage implements TokenStorageInterface
{
    public function get(string $key): ?string
    {
        return Cache::get($key);
    }

    public function set(string $key, string $value, ?int $ttl = null): void
    {
        Cache::put($key, $value, $ttl ?? 3600 * 24 * 30);
    }

    public function delete(string $key): void
    {
        Cache::forget($key);
    }
}
bash
composer