|
...
|
...
|
@@ -4,6 +4,7 @@ namespace App\Console\Commands\Test; |
|
|
|
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Models\Collect\CollectTask;
|
|
|
|
use App\Models\Com\Notify;
|
|
|
|
use App\Models\Com\UpdateLog;
|
|
|
|
use App\Models\Com\UpdateVisit;
|
|
|
|
use App\Models\Devops\ServerConfig;
|
|
...
|
...
|
@@ -33,28 +34,16 @@ class Temp extends Command |
|
|
|
*/
|
|
|
|
protected $description = '临时脚本';
|
|
|
|
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$domain_model = new DomainInfo();
|
|
|
|
$server_model = new ServerConfig();
|
|
|
|
$notify_model = new Notify();
|
|
|
|
$project_model = new Project();
|
|
|
|
|
|
|
|
$domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc');
|
|
|
|
$domain_list = $domain_model->list(['amp_status' => 1]);
|
|
|
|
foreach ($domain_list as $info) {
|
|
|
|
$this->output('domain:' . $info['domain'] . ',开始');
|
|
|
|
|
|
|
|
$project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');
|
|
|
|
if ($project_info === false) {
|
|
|
|
$this->output('获取项目数据失败');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
|
|
|
|
if ($server_info === false) {
|
|
|
|
$this->output('获取服务器数据失败');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$notify_info = $notify_model->read(['project_id' => $info['project_id']]);
|
|
|
|
if (!$notify_info) {
|
|
|
|
|
|
|
|
$domain_array = parse_url($info['domain']);
|
|
|
|
$host = $domain_array['host'] ?? $domain_array['path'];
|
|
...
|
...
|
@@ -65,42 +54,86 @@ class Temp extends Command |
|
|
|
$host_array[0] = 'm';
|
|
|
|
}
|
|
|
|
$amp_domain = implode('.', $host_array);
|
|
|
|
if (!$this->check_cname($amp_domain, $server_info)) {
|
|
|
|
$this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
|
|
|
|
$api_param = [
|
|
|
|
'domain' => $info['domain'],
|
|
|
|
'private_key' => '',
|
|
|
|
'cert' => ''
|
|
|
|
];
|
|
|
|
|
|
|
|
try {
|
|
|
|
$rs = HttpUtils::get($api_url, $api_param);
|
|
|
|
$rs = json_decode($rs, true);
|
|
|
|
if (isset($rs['status']) && $rs['status'] == 200) {
|
|
|
|
$this->output('创建AMP站点成功');
|
|
|
|
} else {
|
|
|
|
$this->output($rs['message'] ?? '');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} catch (\Exception | GuzzleException $e) {
|
|
|
|
errorLog('创建AMP站点', $api_param, $e);
|
|
|
|
$this->output('创建AMP站点失败');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'amp_status' => 1,
|
|
|
|
'amp_type' => 1,
|
|
|
|
];
|
|
|
|
$domain_model->edit($data, ['id' => $info['id']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '成功' . PHP_EOL;
|
|
|
|
}
|
|
|
|
$project_info = $project_model->read(['id' => $info['project_id']]);
|
|
|
|
|
|
|
|
$notify_model->add([
|
|
|
|
'project_id' => $info['project_id'],
|
|
|
|
'type' => 3,
|
|
|
|
'data' => json_encode(['domain' => $amp_domain, 'url' => [], 'language' => []]),
|
|
|
|
'server_id' => $project_info['serve_id'],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// public function handle()
|
|
|
|
// {
|
|
|
|
// $domain_model = new DomainInfo();
|
|
|
|
// $server_model = new ServerConfig();
|
|
|
|
// $project_model = new Project();
|
|
|
|
//
|
|
|
|
// $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc');
|
|
|
|
// foreach ($domain_list as $info) {
|
|
|
|
// $this->output('domain:' . $info['domain'] . ',开始');
|
|
|
|
//
|
|
|
|
// $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');
|
|
|
|
// if ($project_info === false) {
|
|
|
|
// $this->output('获取项目数据失败');
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
|
|
|
|
// if ($server_info === false) {
|
|
|
|
// $this->output('获取服务器数据失败');
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// $domain_array = parse_url($info['domain']);
|
|
|
|
// $host = $domain_array['host'] ?? $domain_array['path'];
|
|
|
|
// $host_array = explode('.', $host);
|
|
|
|
// if (count($host_array) <= 2) {
|
|
|
|
// array_unshift($host_array, 'm');
|
|
|
|
// } else {
|
|
|
|
// $host_array[0] = 'm';
|
|
|
|
// }
|
|
|
|
// $amp_domain = implode('.', $host_array);
|
|
|
|
// if (!$this->check_cname($amp_domain, $server_info)) {
|
|
|
|
// $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
|
|
|
|
// $api_param = [
|
|
|
|
// 'domain' => $info['domain'],
|
|
|
|
// 'private_key' => '',
|
|
|
|
// 'cert' => ''
|
|
|
|
// ];
|
|
|
|
//
|
|
|
|
// try {
|
|
|
|
// $rs = HttpUtils::get($api_url, $api_param);
|
|
|
|
// $rs = json_decode($rs, true);
|
|
|
|
// if (isset($rs['status']) && $rs['status'] == 200) {
|
|
|
|
// $this->output('创建AMP站点成功');
|
|
|
|
// } else {
|
|
|
|
// $this->output($rs['message'] ?? '');
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// } catch (\Exception | GuzzleException $e) {
|
|
|
|
// errorLog('创建AMP站点', $api_param, $e);
|
|
|
|
// $this->output('创建AMP站点失败');
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// $data = [
|
|
|
|
// 'amp_status' => 1,
|
|
|
|
// 'amp_type' => 1,
|
|
|
|
// ];
|
|
|
|
// $domain_model->edit($data, ['id' => $info['id']]);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// echo '成功' . PHP_EOL;
|
|
|
|
// }
|
|
|
|
|
|
|
|
public function check_cname($domain, $server_info)
|
|
|
|
{
|
...
|
...
|
|