Files
thetool/lib/KolmisoftMore/KolmisoftMore.php
Luca Haid f39978e7a9 Added Voice Functionality
[KolmisoftMore] implemented getActiveCalls function
[menu.php] added menu point for active voice calls
[config.sample.php] added KOLMISOFT configuration constants
[VoiceCallActive] implemented active voice calls view
[VoiceCallHistoryController] fixed importCallsFromToday Time
[tt-table] fixed pagination displays
2024-04-11 10:00:27 +02:00

100 lines
2.6 KiB
PHP

<?php
class KolmisoftMore {
private string $host;
private string $username;
private string $apiKey;
public function __construct($host, $apiKey, $username) {
$this->host = $host;
$this->apiKey = $apiKey;
$this->username = $username;
}
/**
* Generate hash for the given query parameters
* @param $queryParameters - Array of query parameters to generate hash
* @return string
*/
public function generateHash($queryParameters): string {
// concatenate all query parameters values in order of the array and then add apiKey to the end
$queryString = implode('', $queryParameters);
$queryString .= $this->apiKey;
return hash('sha1', $queryString);
}
/**
* Make a request to the Kolmisoft API
* @param $path - API path
* @param $queryString - Query string
* @return array|bool
*/
public function makeRequest($path, $queryString) {
$url = "https://{$this->host}/billing/api/$path?$queryString";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
try {
$response = new SimpleXMLElement($response);
} catch (Exception $e) {
return false;
}
$response = json_decode(json_encode($response), true);
if (is_array($response)) {
return $response;
} else {
return false;
}
}
public function getVoiceCallHistory($startDate, $endDate) {
$queryParameters = [
'period_start' => $startDate,
'period_end' => $endDate
];
$hash = $this->generateHash($queryParameters);
$queryParameters['hash'] = $hash;
$queryParameters['u'] = $this->username;
$queryString = http_build_query($queryParameters);
$response = $this->makeRequest('user_calls_get', $queryString);
if ($response) {
return $response['calls_stat']['calls']['call'];
} else {
return false;
}
}
public function getActiveCalls() {
$queryParameters = ['u' => $this->username];
$hash = $this->generateHash($queryParameters);
$queryParameters['hash'] = $hash;
$queryString = http_build_query($queryParameters);
$response = $this->makeRequest('active_calls_get', $queryString);
if ($response) {
return $response['status']['active_call'];
} else {
return false;
}
}
}