Added KolmisoftMore API Class
This commit is contained in:
82
lib/KolmisoftMore/KolmisoftMore.php
Normal file
82
lib/KolmisoftMore/KolmisoftMore.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user