|
|
|
1
|
+<?php
|
|
|
|
2
|
+
|
|
|
|
3
|
+namespace App\Jobs;
|
|
|
|
4
|
+
|
|
|
|
5
|
+use App\Models\Devops\ServerConfig;
|
|
|
|
6
|
+use App\Models\Project\CountryCustom;
|
|
|
|
7
|
+use App\Models\Project\Project;
|
|
|
|
8
|
+use App\Utils\HttpUtils;
|
|
|
|
9
|
+use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
10
|
+use Illuminate\Bus\Queueable;
|
|
|
|
11
|
+use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
12
|
+use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
13
|
+use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
14
|
+use Illuminate\Queue\SerializesModels;
|
|
|
|
15
|
+
|
|
|
|
16
|
+class EditCustomDomainBt implements ShouldQueue
|
|
|
|
17
|
+{
|
|
|
|
18
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
19
|
+
|
|
|
|
20
|
+ public $tries = 1; // 可配置任务重试次数
|
|
|
|
21
|
+
|
|
|
|
22
|
+ protected $domain_id;
|
|
|
|
23
|
+
|
|
|
|
24
|
+ /**
|
|
|
|
25
|
+ * Create a new job instance.
|
|
|
|
26
|
+ *
|
|
|
|
27
|
+ * @param $domain_id
|
|
|
|
28
|
+ */
|
|
|
|
29
|
+ public function __construct($domain_id)
|
|
|
|
30
|
+ {
|
|
|
|
31
|
+ $this->domain_id = $domain_id;
|
|
|
|
32
|
+ }
|
|
|
|
33
|
+
|
|
|
|
34
|
+ /**
|
|
|
|
35
|
+ * Execute the job.
|
|
|
|
36
|
+ *
|
|
|
|
37
|
+ * @return bool
|
|
|
|
38
|
+ */
|
|
|
|
39
|
+ public function handle()
|
|
|
|
40
|
+ {
|
|
|
|
41
|
+ //获取域名数据
|
|
|
|
42
|
+ $domain_model = new CountryCustom();
|
|
|
|
43
|
+ $domain_info = $domain_model->read(['id' => $this->domain_id]);
|
|
|
|
44
|
+ if ($domain_info === false) {
|
|
|
|
45
|
+ return $this->output($domain_info['custom_domain'] . ':获取域名数据失败');
|
|
|
|
46
|
+ }
|
|
|
|
47
|
+
|
|
|
|
48
|
+ //获取项目数据
|
|
|
|
49
|
+ $project_model = new Project();
|
|
|
|
50
|
+ $project_info = $project_model->read(['id' => $domain_info['project_id']], 'serve_id');
|
|
|
|
51
|
+ if ($project_info === false) {
|
|
|
|
52
|
+ return $this->output($domain_info['custom_domain'] . ':获取项目数据失败');
|
|
|
|
53
|
+ }
|
|
|
|
54
|
+
|
|
|
|
55
|
+ //获取服务器数据
|
|
|
|
56
|
+ $server_model = new ServerConfig();
|
|
|
|
57
|
+ $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
|
|
|
|
58
|
+ if ($server_info === false) {
|
|
|
|
59
|
+ return $this->output($domain_info['custom_domain'] . ':获取服务器数据失败');
|
|
|
|
60
|
+ }
|
|
|
|
61
|
+
|
|
|
|
62
|
+ //编辑站点
|
|
|
|
63
|
+ if ($domain_info['type'] == 2) {
|
|
|
|
64
|
+ $api_url = 'http://' . $server_info['init_domain'] . '/api/setSsl';
|
|
|
|
65
|
+ $api_param = [
|
|
|
|
66
|
+ 'domain' => $domain_info['custom_domain'],
|
|
|
|
67
|
+ 'private_key' => $domain_info['private_key'],
|
|
|
|
68
|
+ 'cert' => $domain_info['private_cert'],
|
|
|
|
69
|
+ 'rewrite' => [],
|
|
|
|
70
|
+ 'other_domain' => [],
|
|
|
|
71
|
+ 'is_https' => 1
|
|
|
|
72
|
+ ];
|
|
|
|
73
|
+ } else {
|
|
|
|
74
|
+ $api_url = 'http://' . $server_info['init_domain'] . '/api/applySsl';
|
|
|
|
75
|
+ $api_param = [
|
|
|
|
76
|
+ 'domain' => $domain_info['custom_domain'],
|
|
|
|
77
|
+ 'rewrite' => [],
|
|
|
|
78
|
+ 'other_domain' => [],
|
|
|
|
79
|
+ 'is_https' => 1
|
|
|
|
80
|
+ ];
|
|
|
|
81
|
+ }
|
|
|
|
82
|
+ try {
|
|
|
|
83
|
+ $rs = HttpUtils::get($api_url, $api_param);
|
|
|
|
84
|
+ $rs = json_decode($rs, true);
|
|
|
|
85
|
+ if (isset($rs['status']) && $rs['status'] == 200) {
|
|
|
|
86
|
+ $this->output($domain_info['custom_domain'] . ':站点编辑成功');
|
|
|
|
87
|
+ } else {
|
|
|
|
88
|
+ $this->output($domain_info['custom_domain'] . ':站点编辑失败,原因:' . ($rs['message'] ?? ''));
|
|
|
|
89
|
+ }
|
|
|
|
90
|
+ } catch (\Exception | GuzzleException $e) {
|
|
|
|
91
|
+ $this->output($domain_info['custom_domain'] . ':站点编辑失败,原因:' . $e->getMessage());
|
|
|
|
92
|
+ }
|
|
|
|
93
|
+
|
|
|
|
94
|
+ return true;
|
|
|
|
95
|
+ }
|
|
|
|
96
|
+
|
|
|
|
97
|
+ /**
|
|
|
|
98
|
+ * 输出处理日志
|
|
|
|
99
|
+ * @param $message
|
|
|
|
100
|
+ * @return bool
|
|
|
|
101
|
+ */
|
|
|
|
102
|
+ public function output($message)
|
|
|
|
103
|
+ {
|
|
|
|
104
|
+ echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
|
|
|
|
105
|
+ return true;
|
|
|
|
106
|
+ }
|
|
|
|
107
|
+
|
|
|
|
108
|
+ public function failed(\Exception $exception)
|
|
|
|
109
|
+ {
|
|
|
|
110
|
+ return $this->output($exception->getMessage());
|
|
|
|
111
|
+ }
|
|
|
|
112
|
+} |