$url, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CONNECTTIMEOUT => min(10, $timeoutSeconds), CURLOPT_TIMEOUT => $timeoutSeconds, CURLOPT_HTTPHEADER => [ 'Accept: application/json', 'User-Agent: sendcard-php/1.0', ], // 外部是 http,通常不需要证书校验;若换成 https,可再调整。 ]); $body = curl_exec($ch); if ($body === false) { $err = curl_error($ch); curl_close($ch); throw new RuntimeException('External request failed: ' . $err); } $statusCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $json = json_decode($body, true); if (!is_array($json)) { throw new RuntimeException('External response is not valid JSON'); } // 返回:包含 HTTP 状态码与解析后的 JSON return [ 'http_status' => $statusCode, 'json' => $json, ]; }