作者 Your Name
... ... @@ -35,7 +35,7 @@ class CreateSite extends Command
if ($task) {
$model->edit(['status' => DomainCreateTask::STATUS_ING], ['id' => $task['id']]);
$re = $this->editDomainBt($task['domain_id']);
$re = $this->editDomainBt($task['domain_id'], $task['type']);
if (is_array($re)) {
$model->edit(['status' => DomainCreateTask::STATUS_FAL, 'error_msg' => $re[1]], ['id' => $task['id']]);
... ... @@ -45,7 +45,7 @@ class CreateSite extends Command
}
}
protected function editDomainBt($domain_id)
protected function editDomainBt($domain_id, $type)
{
//获取域名数据
$domain_model = new DomainInfo();
... ... @@ -73,6 +73,7 @@ class CreateSite extends Command
return [false, '获取服务器数据失败2'];
}
if ($type == 1) {
/*****************编辑主站*******************/
if ($domain_info['type'] == 2) {
$api_url = 'http://' . $serverInfo['init_domain'] . '/api/setSsl';
... ... @@ -101,17 +102,17 @@ class CreateSite extends Command
}
try {
$rs = HttpUtils::get($api_url, $api_param);
$rs = HttpUtils::get($api_url, $api_param, [], 180);
$rs = json_decode($rs, true);
if (isset($rs['status']) && $rs['status'] == 200) {
$this->output($domain_info['domain'] . ',主站创建成功');
} else {
return [false, '主站:' . ($rs['message'] ?? '未知错误')];
return [false, $rs['message'] ?? '未知错误'];
}
} catch (\Exception | GuzzleException $e) {
return [false, '主站:' . $e->getMessage()];
return [false, $e->getMessage()];
}
} else {
/*****************编辑amp站*******************/
if ($domain_info['amp_status']) {
$api_url_amp = 'http://' . $serverInfo['init_domain'] . '/api/createSiteAmp';
... ... @@ -127,15 +128,16 @@ class CreateSite extends Command
}
try {
$rs_amp = HttpUtils::get($api_url_amp, $api_param_amp);
$rs_amp = HttpUtils::get($api_url_amp, $api_param_amp, [], 180);
$rs_amp = json_decode($rs_amp, true);
if (isset($rs_amp['status']) && $rs_amp['status'] == 200) {
$this->output($domain_info['domain'] . ',amp站创建成功');
} else {
return [false, 'amp站:' . ($rs['message'] ?? '未知错误')];
return [false, $rs['message'] ?? '未知错误'];
}
} catch (\Exception | GuzzleException $e_amp) {
return [false, 'amp站:' . $e_amp->getMessage()];
return [false, $e_amp->getMessage()];
}
}
}
... ...
... ... @@ -39,18 +39,18 @@ class HttpUtils
* @return int
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public static function get($url, $data, $headers = [])
public static function get($url, $data, $headers = [],$timeout=60)
{
LogUtils::info("HttpUtils-GET请求URL:" . $url);
$response = Http::timeout(60)->withHeaders($headers)->get($url, $data);
$response = Http::timeout($timeout)->withHeaders($headers)->get($url, $data);
self::checkSuccess($response);
return $response->getBody()->getContents();
}
public static function post($url, $data, $headers = [])
public static function post($url, $data, $headers = [],$timeout=60)
{
LogUtils::info("HttpUtils-POST请求URL:" . $url);
$response = Http::timeout(60)->withHeaders($headers)->post($url, $data);
$response = Http::timeout($timeout)->withHeaders($headers)->post($url, $data);
self::checkSuccess($response);
return $response->getBody()->getContents();
}
... ...