PHP code example of pelock / radio-code-calculator
1. Go to this page and download the library: Download pelock/radio-code-calculator 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/ */
pelock / radio-code-calculator example snippets
declare(strict_types=1);
/******************************************************************************
*
* Radio Code Calculator API - WebApi interface usage example
*
* In this example, we will demonstrate how to generate a code for a specific
* type of car radio.
*
* Version : v1.1.6
* PHP : >= 7
* Dependencies : cURL
* Author : Bartosz Wójcik ([email protected])
* Project : https://www.pelock.com/products/radio-code-calculator
* Homepage : https://www.pelock.com
*
* @link https://www.pelock.com/products/radio-code-calculator
* @copyright Copyright (c) 2021-2024 PELock LLC
* @license Apache-2.0
*
/*****************************************************************************/
//
// serialMaxLen"] . " characters)"; break;
case RadioErrors::INVALID_SERIAL_PATTERN: echo "Invalid serial number regular expression pattern (expected " . $result["serialRegexPattern"]["php"] . " regex pattern)"; break;
case RadioErrors::INVALID_SERIAL_NOT_SUPPORTED: echo "This serial number is not supported"; break;
case RadioErrors::INVALID_EXTRA_LENGTH: echo "Invalid extra data length (expected " . $result["extraMaxLen"] . " characters)"; break;
case RadioErrors::INVALID_EXTRA_PATTERN: echo "Invalid extra data regular expression pattern (expected " . $result["extraRegexPattern"]["php"] . " regex pattern"; break;
case RadioErrors::INVALID_INPUT: echo "Invalid input data"; break;
case RadioErrors::INVALID_COMMAND: echo "Invalid command sent to the Web API interface"; break;
case RadioErrors::INVALID_LICENSE: echo "Invalid license key!"; break;
default: echo "Something unexpected happen while trying to login to the service (error code {error})."; break;
}
declare(strict_types=1);
/******************************************************************************
*
* Radio Code Calculator API - WebApi interface usage example
*
* In this example, we will demonstrate how to generate a code for a specific
* type of car radio. This example shows how to use an extended offline
* validation.
*
* Version : v1.1.6
* PHP : >= 7
* Dependencies : cURL
* Author : Bartosz Wójcik ([email protected])
* Project : https://www.pelock.com/products/radio-code-calculator
* Homepage : https://www.pelock.com
*
* @link https://www.pelock.com/products/radio-code-calculator
* @copyright Copyright (c) 2021-2024 PELock LLC
* @license Apache-2.0
*
/*****************************************************************************/
//
// include Radio Code Calculator API module
//
use PELock\RadioCodeCalculator\RadioCodeCalculator;
use PELock\RadioCodeCalculator\RadioErrors;
use PELock\RadioCodeCalculator\RadioModel;
use PELock\RadioCodeCalculator\RadioModels;
//
// create Radio Code Calculator API class instance (we are using our activation key)
//
$myRadioCodeCalculator = new RadioCodeCalculator("ABCD-ABCD-ABCD-ABCD");
//
// generate a single radio unlocking code
//
$serial = "123456";
$extra = "";
//
// select a radio model
//
$radioModel = RadioModels::get(RadioModels::FORD_M_SERIES);
//
// display radio model information, you can use it to set limits in your controls e.g.
//
// textFieldRadioSerial.maxLength = radioModel->serial_max_len
// textFieldRadioSerial.regEx = radioModel->serial_regex_pattern()
//
// (if allowed by your controls)
//
echo "Radio model $radioModel->name expects a serial number of $radioModel->serial_max_len length and {$radioModel->serial_regex_pattern()} regex pattern<br>";
// additional information
if ($radioModel->extra_max_len > 0)
{
echo "Additionally an extra field is valid extra data regular expression pattern (expected " . $result["extraRegexPattern"]["php"] . " regex pattern"; break;
case RadioErrors::INVALID_INPUT: echo "Invalid input data"; break;
case RadioErrors::INVALID_COMMAND: echo "Invalid command sent to the Web API interface"; break;
case RadioErrors::INVALID_LICENSE: echo "Invalid license key!"; break;
default: echo "Something unexpected happen while trying to login to the service (error code {error})."; break;
}
declare(strict_types=1);
/******************************************************************************
*
* Radio Code Calculator API - WebApi interface usage example
*
* In this example we will list all the available calculators and, their
* parameters like name, maximum length of the radio serial number and its
* regex pattern.
*
* Version : v1.1.6
* PHP : >= 7
* Dependencies : cURL
* Author : Bartosz Wójcik ([email protected])
* Project : https://www.pelock.com/products/radio-code-calculator
* Homepage : https://www.pelock.com
*
* @link https://www.pelock.com/products/radio-code-calculator
* @copyright Copyright (c) 2021-2024 PELock LLC
* @license Apache-2.0
*
/*****************************************************************************/
//
// ern() . "<br>";
// is extra field specified?
if ($radio_model->extra_max_len > 0)
{
echo "Max. length of the radio extra data - " . $radio_model->extra_max_len . "<br>";
echo "Regex pattern for the radio extra data - " . $radio_model->extra_regex_pattern() . "<br>";
echo "<br>";
}
}
}
else if ($error == RadioErrors::INVALID_LICENSE)
echo "Invalid license key!";
else
echo "Something unexpected happen while trying to login to the service (error code {error}).";
declare(strict_types=1);
/******************************************************************************
*
* Radio Code Calculator API - WebApi interface usage example
*
* In this example, we will demonstrate how to get information about the
* specific radio calculator and its parameters (max. length & regex pattern).
*
* Version : v1.1.6
* PHP : >= 7
* Dependencies : cURL
* Author : Bartosz Wójcik ([email protected])
* Project : https://www.pelock.com/products/radio-code-calculator
* Homepage : https://www.pelock.com
*
* @link https://www.pelock.com/products/radio-code-calculator
* @copyright Copyright (c) 2021-2024 PELock LLC
* @license Apache-2.0
*
/*****************************************************************************/
//
// " . $radio_model->extra_max_len . "<br>";
echo "Regex pattern for the radio extra data - " . $radio_model->extra_regex_pattern() . "<br>";
echo "<br>";
}
}
elseif ($error == RadioErrors::INVALID_LICENSE)
echo "Invalid license key!";
else
echo "Something unexpected happen while trying to login to the service (error code {error}).";
declare(strict_types=1);
/******************************************************************************
*
* Radio Code Calculator API - WebApi interface usage example
*
* In this example we will verify our activation key status.
*
* Version : v1.1.6
* PHP : >= 7
* Dependencies : cURL
* Author : Bartosz Wójcik ([email protected])
* Project : https://www.pelock.com/products/radio-code-calculator
* Homepage : https://www.pelock.com
*
* @link https://www.pelock.com/products/radio-code-calculator
* @copyright Copyright (c) 2021-2024 PELock LLC
* @license Apache-2.0
*
/*****************************************************************************/
//
// rationDate"] - license expiration date (in YYYY-MM-DD format)
//
if ($error == RadioErrors::SUCCESS)
{
echo "License activation status - " . ($result["license"]["activationStatus"] ? "True" : "False") . "<br>";
echo "License owner - " . $result["license"]["userName"];
echo "License type - " . ($result["license"]["type"] == 0 ? "Personal" : "Company") . "<br>";
echo "Expiration date - " . $result["license"]["expirationDate"] . "<br>";
}
else if ($error == RadioErrors::INVALID_LICENSE)
echo "Invalid license key!";
else
echo "Something unexpected happen while trying to login to the service (error code {error}).";
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.