作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !454
@@ -4,6 +4,7 @@ namespace App\Http\Logic\Aside\Domain; @@ -4,6 +4,7 @@ namespace App\Http\Logic\Aside\Domain;
4 4
5 5
6 use App\Http\Logic\Aside\BaseLogic; 6 use App\Http\Logic\Aside\BaseLogic;
  7 +use App\Jobs\EditDomainBt;
7 use App\Models\Devops\ServerConfig; 8 use App\Models\Devops\ServerConfig;
8 use App\Models\Domain\DomainInfo; 9 use App\Models\Domain\DomainInfo;
9 use App\Models\Project\CountryCustom; 10 use App\Models\Project\CountryCustom;
@@ -302,12 +303,13 @@ class DomainInfoLogic extends BaseLogic @@ -302,12 +303,13 @@ class DomainInfoLogic extends BaseLogic
302 ]; 303 ];
303 $this->model->edit($data,['id'=>$this->param['id']]); 304 $this->model->edit($data,['id'=>$this->param['id']]);
304 //生成证书 305 //生成证书
305 - $this->setDomainSsl($server_info['init_domain'],$info['domain'],$this->param['extend_config'] ?? [],$this->param['other_domain'] ?? [],$this->param['is_https'] ?? 0); 306 + EditDomainBt::dispatch($this->param['id']);
  307 +// $this->setDomainSsl($server_info['init_domain'],$info['domain'],$this->param['extend_config'] ?? [],$this->param['other_domain'] ?? [],$this->param['is_https'] ?? 0);
306 308
307 //amp站点生成证书 309 //amp站点生成证书
308 - if($data['amp_status']){  
309 - $this->setAmpDomainSsl($server_info['init_domain'],$info['domain']);  
310 - } 310 +// if($data['amp_status']){
  311 +// $this->setAmpDomainSsl($server_info['init_domain'],$info['domain']);
  312 +// }
311 313
312 return $this->success(); 314 return $this->success();
313 } 315 }
  1 +<?php
  2 +
  3 +namespace App\Jobs;
  4 +
  5 +use App\Models\Devops\ServerConfig;
  6 +use App\Models\Domain\DomainInfo;
  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 EditDomainBt implements ShouldQueue
  17 +{
  18 + use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  19 +
  20 + public $tries = 3; // 可配置任务重试次数
  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 DomainInfo();
  43 + $domain_info = $domain_model->read(['id' => $this->domain_id]);
  44 + if ($domain_info === false) {
  45 + return $this->output($domain_info['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['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['domain'] . ':获取服务器数据失败');
  60 + }
  61 +
  62 + //编辑主站
  63 + $rewrite = $domain_info['extend_config'] ? json_decode($domain_info['extend_config'], true) : [];
  64 + $other_domain = $domain_info['other_domain'] ? json_decode($domain_info['other_domain'], true) : [];
  65 + if ($domain_info['type'] == 2) {
  66 + $api_url = 'http://' . $server_info['init_domain'] . '/api/setSsl';
  67 + $api_param = [
  68 + 'domain' => $domain_info['domain'],
  69 + 'private_key' => $domain_info['private_key'],
  70 + 'cert' => $domain_info['private_cert'],
  71 + 'rewrite' => $rewrite,
  72 + 'other_domain' => $other_domain,
  73 + 'is_https' => $domain_info['is_https']
  74 + ];
  75 + } else {
  76 + $api_url = 'http://' . $server_info['init_domain'] . '/api/applySsl';
  77 + $api_param = [
  78 + 'domain' => $domain_info['domain'],
  79 + 'rewrite' => $rewrite,
  80 + 'other_domain' => $other_domain,
  81 + 'is_https' => $domain_info['is_https']
  82 + ];
  83 + }
  84 + try {
  85 + $rs = HttpUtils::get($api_url, $api_param);
  86 + $rs = json_decode($rs, true);
  87 + if (isset($rs['status']) && $rs['status'] == 200) {
  88 + $this->output($domain_info['domain'] . ':主站编辑成功');
  89 + } else {
  90 + $this->output($domain_info['domain'] . ':主站编辑失败,原因:' . ($rs['message'] ?? ''));
  91 + }
  92 + } catch (\Exception | GuzzleException $e) {
  93 + $this->output($domain_info['domain'] . ':主站编辑失败,原因:' . $e->getMessage());
  94 + }
  95 +
  96 + //编辑amp站
  97 + if ($domain_info['amp_status']) {
  98 + $api_url_amp = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
  99 + $api_param_amp = [
  100 + 'domain' => $domain_info['domain'],
  101 + 'private_key' => $domain_info['amp_private_key'],
  102 + 'cert' => $domain_info['amp_private_cert']
  103 + ];
  104 +
  105 + try {
  106 + $rs_amp = HttpUtils::get($api_url_amp, $api_param_amp);
  107 + $rs_amp = json_decode($rs_amp, true);
  108 + if (isset($rs_amp['status']) && $rs_amp['status'] == 200) {
  109 + $this->output($domain_info['domain'] . ':amp站编辑成功');
  110 + } else {
  111 + $this->output($domain_info['domain'] . ':amp站编辑失败,原因:' . ($rs_amp['message'] ?? ''));
  112 + }
  113 + } catch (\Exception | GuzzleException $e) {
  114 + $this->output($domain_info['domain'] . ':amp站编辑失败,原因:' . $e->getMessage());
  115 + }
  116 + }
  117 +
  118 + return true;
  119 + }
  120 +
  121 + /**
  122 + * 输出处理日志
  123 + * @param $message
  124 + * @return bool
  125 + */
  126 + public function output($message)
  127 + {
  128 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  129 + return true;
  130 + }
  131 +}