4use \Bitrix\Main\Text\Encoding;
36 public function __construct(
string $apiKey,
string $secretKey)
38 $this->apiKey = $apiKey;
39 $this->secretKey = $secretKey;
40 $this->http = new \Bitrix\Main\Web\HttpClient;
41 $this->http->setTimeout(5);
50 private function setHeaders(
string $endPoint, ?
string $payLoad =
null): void
57 $signature = hash_hmac(
'sha256', $this->apiKey . $endPoint . $payLoad, $this->secretKey);
58 $this->http->setHeader(
'X-OMNI-APIKEY', $this->apiKey);
59 $this->http->setHeader(
'X-OMNI-SIGNATURE', $signature);
60 $this->http->setHeader(
'content-type',
'application/json');
69 private function sendPostCommand(
string $endPoint,
string $payLoad): string
71 $endPoint = $this::BASE_ENDPOINT . $endPoint;
72 $this->setHeaders($endPoint, $payLoad);
73 $this->http->post($endPoint, $payLoad);
74 return $this->http->getResult();
82 private function sendGetCommand(
string $endPoint): string
84 $endPoint = $this::BASE_ENDPOINT . $endPoint;
85 $this->setHeaders($endPoint);
86 $this->http->get($endPoint);
87 return $this->http->getResult();
98 public static function checkDomain(
string $user,
string $password,
string $domain, ?
string &$error): ?bool
100 $domain = mb_strtolower($domain);
101 $domain = Encoding::convertEncoding($domain, SITE_CHARSET,
'UTF-8');
103 $omnilance =
new self($user, $password);
105 $payLoad = json_encode([
110 $res = $omnilance->sendPostCommand(
'domains/checkAvailability', $payLoad);
111 $res = json_decode($res,
true);
113 if (isset($res[
'error']))
115 $error = $res[
'message'] ?? $res[
'error'];
119 if (isset($res[
'results']) && is_array($res[
'results']))
121 foreach ($res[
'results'] as $item)
123 if ($item[
'domainName'] == $domain)
125 if ($item[
'status'] ==
'registered')
147 public static function suggestDomain(
string $user,
string $password,
string $word1,
string $word2, array $tlds, ?
string &$error): ?array
162 public static function createDomain(
string $user,
string $password,
string $domain, array $params, ?
string &$error): ?bool
164 $domain = mb_strtolower($domain);
165 $domain = Encoding::convertEncoding($domain, SITE_CHARSET,
'UTF-8');
167 $payLoad = json_encode([
169 'domainName' => $domain,
170 'privacyEnabled' =>
true
175 $omnilance =
new self($user, $password);
176 $res = $omnilance->sendPostCommand(
'domains/createDomain', $payLoad);
177 $res = json_decode($res,
true);
179 if (isset($res[
'error']))
181 $error = $res[
'message'] ?? $res[
'error'];
196 public static function renewDomain(
string $user,
string $password,
string $domain, ?
string &$error): ?bool
198 $domain = mb_strtolower($domain);
199 $domain = Encoding::convertEncoding($domain, SITE_CHARSET,
'UTF-8');
201 $payLoad = json_encode([
203 'domainName' => $domain
208 $omnilance =
new self($user, $password);
209 $res = $omnilance->sendPostCommand(
'domains/renewDomain/'.$domain, $payLoad);
210 $res = json_decode($res,
true);
212 if (isset($res[
'error']))
214 $error = $res[
'message'] ?? $res[
'error'];
230 public static function updateDns(
string $user,
string $password,
string $domain, array $params, ?
string &$error): ?bool
233 $domain = mb_strtolower($domain);
234 $domain = Encoding::convertEncoding($domain, SITE_CHARSET,
'UTF-8');
235 $params = Encoding::convertEncoding($params, SITE_CHARSET,
'UTF-8');
238 foreach ($params as $dns)
241 'type' => (isset($dns[
'type']) && is_string($dns[
'type'])) ? strtoupper($dns[
'type']) :
null,
242 'name' => (isset($dns[
'name']) && is_string($dns[
'name'])) ? $dns[
'name'] :
'',
243 'value' => isset($dns[
'value']) ? [$dns[
'value']] : [],
246 $payLoad = json_encode($payLoad);
248 $omnilance =
new self($user, $password);
252 $res = $omnilance->sendPostCommand(
'domains/createZoneRecord/'.$domain, $payLoad);
256 $res = $omnilance->sendPostCommand(
'domains/createDnsRecord/'.$domain, $payLoad);
259 $res = json_decode($res,
true);
261 if (isset($res[
'error']))
263 $error = $res[
'message'] ?? $res[
'error'];
268 return $error ===
null;
278 public static function getDomainsList(
string $user,
string $password, ?
string &$error): ?array
282 $omnilance =
new self($user, $password);
286 $res = $omnilance->sendGetCommand(
'domains/100/' . $currentPage);
287 $res = json_decode($res,
true);
289 if (isset($res[
'error']))
291 $error = $res[
'message'] ?? $res[
'error'];
295 if (!isset($res[
'domains']) || !isset($res[
'lastPage']))
297 $error =
'Unknown error';
301 foreach ($res[
'domains'] as $domain)
303 $list[$domain[
'domainName']] = [
304 'domain_name' => $domain[
'domainName'],
305 'creation_date' => $domain[
'createDate'],
306 'expiration_date' => $domain[
'expireDate'],
313 }
while ($currentPage <= $res[
'lastPage']);
static renewDomain(string $user, string $password, string $domain, ?string &$error)
static updateDns(string $user, string $password, string $domain, array $params, ?string &$error)
static suggestDomain(string $user, string $password, string $word1, string $word2, array $tlds, ?string &$error)
static checkDomain(string $user, string $password, string $domain, ?string &$error)
static createDomain(string $user, string $password, string $domain, array $params, ?string &$error)
static getDomainsList(string $user, string $password, ?string &$error)
__construct(string $apiKey, string $secretKey)