$source, 'X-Date' => $datetime, 'Authorization' => $auth, ); // 查询参数 $queryParams = array ( ); // body参数(POST方法下) $bodyParams = array ( 'ip' => $ip, ); // url参数拼接 $url = 'https://service-hnhpr5tw-1305308687.gz.apigw.tencentcs.com/release/ip/query'; if (count($queryParams) > 0) { $url .= '?' . http_build_query($queryParams); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_HTTPHEADER, array_map(function ($v, $k) { return $k . ': ' . $v; }, array_values($headers), array_keys($headers))); if (in_array($method, array('POST', 'PUT', 'PATCH'), true)) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($bodyParams)); } $data = curl_exec($ch); if (curl_errno($ch)) { echo "Error: " . curl_error($ch); } else { print_r($data); } curl_close($ch); }