Created
February 4, 2019 22:28
-
-
Save webnitros/faa0ee5b061baa4fbb334b90bd6179b1 to your computer and use it in GitHub Desktop.
Проверка сайта на доступ для приложения
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by Andrey Stepanenko. | |
* User: webnitros | |
* Date: 24.01.2019 | |
* Time: 1:00 | |
*/ | |
ini_set('display_errors', 1); | |
ini_set("max_execution_time", 50); | |
define('MODX_API_MODE', true); | |
require 'index.php'; | |
$signature = 'mspre'; | |
/* @var transport.modTransportPackage $object */ | |
$q = $modx->newQuery('transport.modTransportPackage'); | |
$q->where(array( | |
'package_name' => $signature, | |
)); | |
$q->sortby('installed', 'DESC'); | |
if ($package = $modx->getObject('transport.modTransportPackage', $q)) { | |
$version = $package->get(array('version_major', 'version_minor', 'version_patch', 'release')); | |
$version = implode('.', $version);; | |
if ($provider = $modx->getObject('transport.modTransportProvider', [ | |
'service_url:LIKE' => '%modstore.pro%', | |
])) { | |
$api_url = 'https://modstore.pro/extras/package/decode/install'; | |
$params = http_build_query([ | |
'package' => 'msPre', | |
'http_host' => $modx->getOption('http_host'), // Адрес сайта | |
'username' => $provider->get('username'), // E-mail пользователя | |
'api_key' => $provider->get('api_key'), // Ключ сайта | |
'version' => $version, // Версия пакета | |
'vehicle_version' => '2.0.0' // Версия API | |
]); | |
$curl = curl_init($api_url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $params); | |
// Ответ придёт в виде XML | |
$data = new SimpleXMLElement(curl_exec($curl)); | |
if (!empty($data->key)) { | |
print 'Key: ' . $data->key; | |
} | |
curl_close($curl); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment