getAuthStr()); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); // 设置Post参数 if ($method === Config::HTTP_POST) { curl_setopt($ch, CURLOPT_POST, true); } else if ($method === Config::HTTP_DELETE || $method === Config::HTTP_PUT) { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); } if (!is_null($body)) { curl_setopt($ch, CURLOPT_POSTFIELDS, $body); } curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Connection: Keep-Alive' )); $output = curl_exec($ch); $response = array(); $errorCode = curl_errno($ch); if ($errorCode) { $retries = $client->getRetryTimes(); if ($times < $retries) { return self::sendRequest($client, $url, $method, $body, ++$times); } else { if ($errorCode === 28) { throw new APIConnectionException("Response timeout. Your request has probably be received by JPush Server,please check that whether need to be pushed again."); } elseif ($errorCode === 56) { // resolve error[56 Problem (2) in the Chunked-Encoded data] throw new APIConnectionException("Response timeout, maybe cause by old CURL version. Your request has probably be received by JPush Server, please check that whether need to be pushed again."); } else { throw new APIConnectionException("Connect timeout. Please retry later. Error:" . $errorCode . " " . curl_error($ch)); } } } else { $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header_text = substr($output, 0, $header_size); $body = substr($output, $header_size); $headers = array(); foreach (explode("\r\n", $header_text) as $i => $line) { if (!empty($line)) { if ($i === 0) { $headers[0] = $line; } else if (strpos($line, ": ")) { list ($key, $value) = explode(': ', $line); $headers[$key] = $value; } } } $response['headers'] = $headers; $response['body'] = $body; $response['http_code'] = $httpCode; } curl_close($ch); return $response; } public static function processResp($response) { if($response['http_code'] === 200) { $result = array(); $data = json_decode($response['body'], true); if (!is_null($data)) { $result['body'] = $data; } $result['http_code'] = $response['http_code']; $result['headers'] = $response['headers']; return $result; } else { throw new APIRequestException($response); } } public static function log($client, $content) { if (!is_null($client->getLogFile())) { error_log($content . "\r\n", 3, $client->getLogFile()); } } }