public function licensewalker() {
// Записываем в лог входные данные
file_put_contents(DIR_LOGS . 'licensewalker.log', "🔍 Полученные данные: " . var_export($this->request->post, true) . "\n", FILE_APPEND);
// capture post data
$extension_type = isset($this->request->post['license_key'])
? strtolower(substr(trim(str_replace(" ", "", $this->request->post['license_key'])), strlen($this->request->post['license_key']) - 2, 2))
: 'id';
$extension_code = isset($this->request->post['extension_code']) ? $this->request->post['extension_code'] : '';
$license_key = isset($this->request->post['license_key']) ? $this->request->post['license_key'] : '';
$domain = isset($this->request->post['domain']) ? $this->request->post['domain'] : '';
$json = ['error' => 1, 'message' => "License Key Invalid"];
if ($extension_type && $extension_code && $license_key && $domain) {
$domain = $this->request->post['domain'];
// ✅ Используем API license.1ts.kz
$base_url = 'https://license.1ts.kz/license_api.php?action=validate';
$url = "{$base_url}&domain=" . urlencode($domain) . "&license_key=" . urlencode($license_key) . "&extension_code=" . urlencode($extension_code);
file_put_contents(DIR_LOGS . 'licensewalker.log', "🔍 Отправляем запрос: {$url}\n", FILE_APPEND);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$err = curl_error($curl);
curl_close($curl);
file_put_contents(DIR_LOGS . 'licensewalker.log', "🔍 HTTP-код: {$http_code}\n", FILE_APPEND);
file_put_contents(DIR_LOGS . 'licensewalker.log', "🔍 Ответ API (сырые данные): " . var_export($response, true) . "\n", FILE_APPEND);
file_put_contents(DIR_LOGS . 'licensewalker.log', "🔍 Ошибка cURL (если есть): {$err}\n", FILE_APPEND);
if ($err) {
$json['error'] = "Ошибка cURL: $err";
} elseif ($http_code >= 400) {
$json['error'] = "Ошибка сервера API ($http_code)";
} elseif (!$response) {
$json['error'] = "API вернул пустой ответ";
} else {
$result = json_decode($response, true);
file_put_contents(DIR_LOGS . 'licensewalker.log', "🔍 API-ответ: " . var_export($result, true) . "\n", FILE_APPEND);
if (json_last_error() !== JSON_ERROR_NONE) {
file_put_contents(DIR_LOGS . 'licensewalker.log', "❌ Ошибка JSON-декодирования: " . json_last_error_msg() . "\n", FILE_APPEND);
$json['error'] = "Ошибка JSON-декодирования: " . json_last_error_msg();
} elseif (isset($result['status']) && $result['status'] === 'success') {
$license_key = isset($result['license']['license_key']) ? $result['license']['license_key'] : null;
$support_expiry = isset($result['license']['support_expiry']) ? $result['license']['support_expiry'] : null;
if (!$license_key || !$support_expiry) {
file_put_contents(DIR_LOGS . 'licensewalker.log', "❌ Ошибка: license_key или support_expiry отсутствуют!\n", FILE_APPEND);
$json['error'] = "Ошибка: API не вернул license_key или support_expiry!";
} else {
$json = [
'success' => 'Valid license key!. Successfully validate your domain. Now redirecting to setting page.',
'license' => $result['license']
];
$data = [
"license_key" => $license_key,
"code" => $extension_code,
"support_expiry" => $support_expiry,
];
file_put_contents(DIR_LOGS . 'licensewalker.log', "🔍 Данные перед записью в БД: " . var_export($data, true) . "\n", FILE_APPEND);
$this->addLicenseKey($data);
file_put_contents(DIR_LOGS . 'licensewalker.log', "✅ Данные успешно сохранены в addLicenseKey()\n", FILE_APPEND);
}
} else {
$json = [
'error' => 'Лицензия недействительна.',
'message' => $result['message'] ?? 'Ошибка проверки лицензии'
];
}
}
}
file_put_contents(DIR_LOGS . 'licensewalker.log', "🔍 Итоговый ответ JSON: " . var_export($json, true) . "\n", FILE_APPEND);
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
© 2023 Quttera Ltd. All rights reserved.