作者 刘锟

update

@@ -1520,3 +1520,36 @@ function thumbImageByUrl($url, $width = 360) @@ -1520,3 +1520,36 @@ function thumbImageByUrl($url, $width = 360)
1520 1520
1521 return $url; 1521 return $url;
1522 } 1522 }
  1523 +
  1524 +if(!function_exists('httpGetSsl')){
  1525 + /**
  1526 + * 获取通配符证书
  1527 + * @param $domain
  1528 + * @return mixed
  1529 + * @author Akun
  1530 + * @date 2025/04/21 16:51
  1531 + */
  1532 + function httpGetSsl($domain){
  1533 + $header = array(
  1534 + "Accept:application/json",
  1535 + "Content-Type:application/json;charset=utf-8",
  1536 + "X-CmerApi-Host:".env('GET_SSL_HOST'),
  1537 + "Apikey:".env('GET_SSL_KEY'),
  1538 + );
  1539 + $ch = curl_init();
  1540 + curl_setopt($ch, CURLOPT_URL, env('GET_SSL_URL').'?domain='.$domain);
  1541 + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  1542 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1543 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1544 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1545 + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  1546 + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1547 + curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  1548 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1549 + $res = curl_exec($ch);
  1550 + curl_close($ch);
  1551 +
  1552 + $result = json_decode($res, true);
  1553 + return is_array($result) ? $result : $res;
  1554 + }
  1555 +}
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace App\Http\Controllers\Api; 3 namespace App\Http\Controllers\Api;
4 4
5 use App\Exceptions\InquiryFilterException; 5 use App\Exceptions\InquiryFilterException;
  6 +use App\Models\Domain\DomainInfo;
6 use App\Models\Mail\Mail; 7 use App\Models\Mail\Mail;
7 use App\Models\Project\DeployBuild; 8 use App\Models\Project\DeployBuild;
8 use App\Models\Project\Project; 9 use App\Models\Project\Project;
@@ -69,7 +70,7 @@ class SelfSiteController extends BaseController @@ -69,7 +70,7 @@ class SelfSiteController extends BaseController
69 $cos = new CosService(); 70 $cos = new CosService();
70 $fileName = uniqid() . rand(10000, 99999) . '.' . $file['ext']; 71 $fileName = uniqid() . rand(10000, 99999) . '.' . $file['ext'];
71 $file_data = base64_decode($file['data']); 72 $file_data = base64_decode($file['data']);
72 - $path = $cos->uploadFile($file_data, '/inquiry/' . date('Ymd'), $fileName,true); 73 + $path = $cos->uploadFile($file_data, '/inquiry/' . date('Ymd'), $fileName, true);
73 $data[$key] = [ 74 $data[$key] = [
74 'path' => $path, 75 'path' => $path,
75 'original_name' => $file['name'], 76 'original_name' => $file['name'],
@@ -191,4 +192,50 @@ class SelfSiteController extends BaseController @@ -191,4 +192,50 @@ class SelfSiteController extends BaseController
191 192
192 return $this->success([]); 193 return $this->success([]);
193 } 194 }
  195 +
  196 + /**
  197 + * 自建站获取通配符证书接口
  198 + * @param Request $request
  199 + * @return false|string
  200 + * @author Akun
  201 + * @date 2025/09/02 16:55
  202 + */
  203 + public function selfSiteSsl(Request $request)
  204 + {
  205 + $token = $request->header('token');//token
  206 + $pid = $request->header('pid');//项目id
  207 +
  208 + if (empty($token) || empty($pid)) {
  209 + return $this->error('token无效', 401);
  210 + }
  211 +
  212 + //判断token是否有效
  213 + $project_model = new Project();
  214 + $project_info = $project_model->read(['id' => $pid, 'site_token' => $token]);
  215 + if (!$project_info) {
  216 + return $this->error('token无效', 401);
  217 + }
  218 +
  219 + //获取域名信息
  220 + $domain_model = new DomainInfo();
  221 + $domain_info = $domain_model->read(['project_id' => $pid]);
  222 + if (!$domain_info) {
  223 + return $this->error('获取域名失败', 401);
  224 + }
  225 +
  226 + //获取通配符证书
  227 + $top_domain = getTopDomain($domain_info['domain']);
  228 + $ssl_re = httpGetSsl($top_domain);
  229 + $return = [
  230 + 'ssl_key' => '',
  231 + 'ssl_cert' => ''
  232 + ];
  233 + if (isset($ssl_re['status']) && $ssl_re['status'] == 2) {
  234 + //获取成功
  235 + $return['ssl_key'] = $ssl_re['ssl_key'];
  236 + $return['ssl_cert'] = $ssl_re['ssl_cert'];
  237 + }
  238 +
  239 + return $this->success($return);
  240 + }
194 } 241 }
@@ -66,6 +66,7 @@ Route::any('get_monitor_keyword', [\App\Http\Controllers\Api\PrivateController:: @@ -66,6 +66,7 @@ Route::any('get_monitor_keyword', [\App\Http\Controllers\Api\PrivateController::
66 Route::post('selfSiteApi', [\App\Http\Controllers\Api\SelfSiteController::class, 'selfSiteApi']); 66 Route::post('selfSiteApi', [\App\Http\Controllers\Api\SelfSiteController::class, 'selfSiteApi']);
67 Route::post('selfSiteNotify', [\App\Http\Controllers\Api\SelfSiteController::class, 'selfSiteNotify']); 67 Route::post('selfSiteNotify', [\App\Http\Controllers\Api\SelfSiteController::class, 'selfSiteNotify']);
68 Route::post('selfSiteVerify', [\App\Http\Controllers\Api\SelfSiteController::class, 'selfSiteVerify']); 68 Route::post('selfSiteVerify', [\App\Http\Controllers\Api\SelfSiteController::class, 'selfSiteVerify']);
  69 +Route::post('selfSiteSsl', [\App\Http\Controllers\Api\SelfSiteController::class, 'selfSiteSsl']);
69 70
70 //创建301跳转任务 71 //创建301跳转任务
71 Route::any('/addRedirect',[\App\Http\Controllers\Api\NoticeController::class,'addRedirect']); 72 Route::any('/addRedirect',[\App\Http\Controllers\Api\NoticeController::class,'addRedirect']);