作者 刘锟

update

@@ -4,6 +4,7 @@ namespace App\Console\Commands\Test; @@ -4,6 +4,7 @@ namespace App\Console\Commands\Test;
4 4
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 use App\Models\Collect\CollectTask; 6 use App\Models\Collect\CollectTask;
  7 +use App\Models\Com\Notify;
7 use App\Models\Com\UpdateLog; 8 use App\Models\Com\UpdateLog;
8 use App\Models\Com\UpdateVisit; 9 use App\Models\Com\UpdateVisit;
9 use App\Models\Devops\ServerConfig; 10 use App\Models\Devops\ServerConfig;
@@ -33,75 +34,107 @@ class Temp extends Command @@ -33,75 +34,107 @@ class Temp extends Command
33 */ 34 */
34 protected $description = '临时脚本'; 35 protected $description = '临时脚本';
35 36
36 -  
37 public function handle() 37 public function handle()
38 { 38 {
39 $domain_model = new DomainInfo(); 39 $domain_model = new DomainInfo();
40 - $server_model = new ServerConfig(); 40 + $notify_model = new Notify();
41 $project_model = new Project(); 41 $project_model = new Project();
42 42
43 - $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc'); 43 + $domain_list = $domain_model->list(['amp_status' => 1]);
44 foreach ($domain_list as $info) { 44 foreach ($domain_list as $info) {
45 - $this->output('domain:' . $info['domain'] . ',开始');  
46 -  
47 - $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');  
48 - if ($project_info === false) {  
49 - $this->output('获取项目数据失败');  
50 - continue;  
51 - }  
52 -  
53 - $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);  
54 - if ($server_info === false) {  
55 - $this->output('获取服务器数据失败');  
56 - continue;  
57 - }  
58 -  
59 - $domain_array = parse_url($info['domain']);  
60 - $host = $domain_array['host'] ?? $domain_array['path'];  
61 - $host_array = explode('.', $host);  
62 - if (count($host_array) <= 2) {  
63 - array_unshift($host_array, 'm');  
64 - } else {  
65 - $host_array[0] = 'm';  
66 - }  
67 - $amp_domain = implode('.', $host_array);  
68 - if (!$this->check_cname($amp_domain, $server_info)) {  
69 - $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');  
70 - continue;  
71 - }  
72 -  
73 - $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';  
74 - $api_param = [  
75 - 'domain' => $info['domain'],  
76 - 'private_key' => '',  
77 - 'cert' => ''  
78 - ];  
79 -  
80 - try {  
81 - $rs = HttpUtils::get($api_url, $api_param);  
82 - $rs = json_decode($rs, true);  
83 - if (isset($rs['status']) && $rs['status'] == 200) {  
84 - $this->output('创建AMP站点成功'); 45 + $notify_info = $notify_model->read(['project_id' => $info['project_id']]);
  46 + if (!$notify_info) {
  47 +
  48 + $domain_array = parse_url($info['domain']);
  49 + $host = $domain_array['host'] ?? $domain_array['path'];
  50 + $host_array = explode('.', $host);
  51 + if (count($host_array) <= 2) {
  52 + array_unshift($host_array, 'm');
85 } else { 53 } else {
86 - $this->output($rs['message'] ?? '');  
87 - continue; 54 + $host_array[0] = 'm';
88 } 55 }
89 - } catch (\Exception | GuzzleException $e) {  
90 - errorLog('创建AMP站点', $api_param, $e);  
91 - $this->output('创建AMP站点失败');  
92 - continue;  
93 - } 56 + $amp_domain = implode('.', $host_array);
94 57
95 - $data = [  
96 - 'amp_status' => 1,  
97 - 'amp_type' => 1,  
98 - ];  
99 - $domain_model->edit($data, ['id' => $info['id']]);  
100 - } 58 + $project_info = $project_model->read(['id' => $info['project_id']]);
101 59
102 - echo '成功' . PHP_EOL; 60 + $notify_model->add([
  61 + 'project_id' => $info['project_id'],
  62 + 'type' => 3,
  63 + 'data' => json_encode(['domain' => $amp_domain, 'url' => [], 'language' => []]),
  64 + 'server_id' => $project_info['serve_id'],
  65 + ]);
  66 + }
  67 + }
103 } 68 }
104 69
  70 +// public function handle()
  71 +// {
  72 +// $domain_model = new DomainInfo();
  73 +// $server_model = new ServerConfig();
  74 +// $project_model = new Project();
  75 +//
  76 +// $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc');
  77 +// foreach ($domain_list as $info) {
  78 +// $this->output('domain:' . $info['domain'] . ',开始');
  79 +//
  80 +// $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');
  81 +// if ($project_info === false) {
  82 +// $this->output('获取项目数据失败');
  83 +// continue;
  84 +// }
  85 +//
  86 +// $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
  87 +// if ($server_info === false) {
  88 +// $this->output('获取服务器数据失败');
  89 +// continue;
  90 +// }
  91 +//
  92 +// $domain_array = parse_url($info['domain']);
  93 +// $host = $domain_array['host'] ?? $domain_array['path'];
  94 +// $host_array = explode('.', $host);
  95 +// if (count($host_array) <= 2) {
  96 +// array_unshift($host_array, 'm');
  97 +// } else {
  98 +// $host_array[0] = 'm';
  99 +// }
  100 +// $amp_domain = implode('.', $host_array);
  101 +// if (!$this->check_cname($amp_domain, $server_info)) {
  102 +// $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');
  103 +// continue;
  104 +// }
  105 +//
  106 +// $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
  107 +// $api_param = [
  108 +// 'domain' => $info['domain'],
  109 +// 'private_key' => '',
  110 +// 'cert' => ''
  111 +// ];
  112 +//
  113 +// try {
  114 +// $rs = HttpUtils::get($api_url, $api_param);
  115 +// $rs = json_decode($rs, true);
  116 +// if (isset($rs['status']) && $rs['status'] == 200) {
  117 +// $this->output('创建AMP站点成功');
  118 +// } else {
  119 +// $this->output($rs['message'] ?? '');
  120 +// continue;
  121 +// }
  122 +// } catch (\Exception | GuzzleException $e) {
  123 +// errorLog('创建AMP站点', $api_param, $e);
  124 +// $this->output('创建AMP站点失败');
  125 +// continue;
  126 +// }
  127 +//
  128 +// $data = [
  129 +// 'amp_status' => 1,
  130 +// 'amp_type' => 1,
  131 +// ];
  132 +// $domain_model->edit($data, ['id' => $info['id']]);
  133 +// }
  134 +//
  135 +// echo '成功' . PHP_EOL;
  136 +// }
  137 +
105 public function check_cname($domain, $server_info) 138 public function check_cname($domain, $server_info)
106 { 139 {
107 $checkA = false; 140 $checkA = false;