public function request($url, $data, $header, $method = 'POST') { $logger = JPushLog::getLogger(); $logger->debug("Send " . $method, array("method" => $method, "uri" => $url, "headers" => $header, "body" => $data)); $request = null; if ($method === 'POST') { $request = Request::post($url); } else { if ($method == 'DELETE') { $request = Request::delete($url); } else { $request = Request::get($url); } } if (!is_null($data)) { $request->body($data); } $request->addHeaders($header)->authenticateWith($this->appKey, $this->masterSecret)->timeout(self::READ_TIMEOUT); $response = null; for ($retryTimes = 0;; $retryTimes++) { try { $response = $request->send(); break; } catch (ConnectionErrorException $e) { if (strpos($e->getMessage(), '28')) { throw new APIConnectionException("Response timeout. Your request has probably be received by JPUsh Server,please check that whether need to be pushed again.", true); } if ($retryTimes >= $this->retryTimes) { throw new APIConnectionException("Connect timeout. Please retry later."); } else { $logger->debug("Retry again send " . $method, array("method" => $method, "uri" => $url, "headers" => $header, "body" => $data, "retryTimes" => $retryTimes + 1)); } } } return $response; }