PDO::ERRMODE_EXCEPTION]); $stmt = $pdo->prepare('SELECT label,value FROM ' . $map['DB_PREFIX'] . 'system_site_settings WHERE label IN (?, ?) ORDER BY id ASC'); $stmt->execute(['backendUrl', 'apiKey']); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $backendUrl = ''; $apiKey = ''; foreach ($rows as $r) { if ($r['label'] === 'backendUrl') $backendUrl = (string)$r['value']; if ($r['label'] === 'apiKey') $apiKey = (string)$r['value']; } if ($backendUrl === '' || $apiKey === '') { echo "missing backendUrl/apiKey\n"; exit(1); } $url = rtrim($backendUrl, '/') . '/api/v1/business/outbound-tasks?limit=3'; $headers = [ 'X-Api-Key: ' . $apiKey, 'Accept: application/json', ]; $headerStr = implode("\r\n", $headers); $context = stream_context_create([ 'http' => [ 'method' => 'GET', 'header' => $headerStr, 'timeout' => 10, // 关键:即便 HTTP code 非 2xx,也让 file_get_contents 返回响应体 'ignore_errors' => true, ], ]); $respBody = @file_get_contents($url, false, $context); $status = 0; if (!empty($http_response_header) && is_array($http_response_header)) { foreach ($http_response_header as $line) { if (preg_match('#^HTTP/\\S+\\s+(\\d+)#', $line, $m)) { $status = (int)$m[1]; break; } } } echo "GET $url\n"; echo "HTTP status=$status\n"; if ($respBody === false) { echo "body=false\n"; } else { $preview = substr((string)$respBody, 0, 500); echo "body_preview=" . str_replace(["\r", "\n"], ['\\r', '\\n'], $preview) . "\n"; }