$timeout, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HTTPHEADER => $header ); $errJson['status'] = 'error'; /* 根据请求类型设置特定参数 */ switch (strtoupper($method)) { case 'GET': $opts[CURLOPT_URL] = $url . '?' . http_build_query($params); break; case 'POST': //$params = http_build_query($params); $opts[CURLOPT_URL] = $url; $opts[CURLOPT_POST] = 1; $opts[CURLOPT_POSTFIELDS] = $params; break; case 'DELETE': $opts[CURLOPT_URL] = $url; $opts[CURLOPT_HTTPHEADER] = array("X-HTTP-Method-Override: DELETE"); $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; $opts[CURLOPT_POSTFIELDS] = $params; break; case 'PUT': $opts[CURLOPT_URL] = $url; $opts[CURLOPT_POST] = 0; $opts[CURLOPT_CUSTOMREQUEST] = 'PUT'; $opts[CURLOPT_POSTFIELDS] = $params; break; default: $errJson['desc'] = '不支持的请求方式'; return $errJson; } if (empty(curl_setopt_array($curlHandler, $opts))) { $errJson['desc'] = "curl_setopt_array error"; return $errJson; } $data = curl_exec($curlHandler); if (empty($data)) { $errJson['desc'] = curl_error($curlHandler); return $errJson; } // curl_close($curlHandler); // $curlHandler = null $res = json_decode($data, true); if (empty($res)) { $errJson['desc'] = "tdHttp request failed json_decode,val:{$data}"; return $errJson; } return $res; } }