/**
  * @param ClientRequest $clientRequest
  * @return Response
  */
 public function getResponse(ClientRequest $clientRequest)
 {
     $client = new HttpClient();
     $headers = array();
     foreach ($clientRequest->getHeaders() as $key => $val) {
         $headers[] = "{$key}: {$val}";
     }
     switch ($clientRequest->getVerb()) {
         case ClientRequest::POST:
             $response = $client->post(array('url' => $clientRequest->getUrl(), 'content' => $clientRequest->getContent(), 'headers' => $headers));
             break;
         case ClientRequest::DELETE:
             $response = $client->delete(array('url' => $clientRequest->getUrl(), 'headers' => $headers));
             break;
         case ClientRequest::PUT:
             $response = $client->put(array('url' => $clientRequest->getUrl(), 'content' => $clientRequest->getContent(), 'headers' => $headers));
             break;
         case ClientRequest::GET:
         default:
             $response = $client->get(array('url' => $clientRequest->getUrl(), 'params' => $clientRequest->getParameters(), 'headers' => $headers));
             break;
     }
     if ($response instanceof \Vinelab\Http\Response) {
         $content = $response->content();
         if (is_bool($content) || is_null($content)) {
             $content = '';
         }
         $responseBag = new Response($content, $response->statusCode(), $response->headers());
         return $responseBag;
     } else {
         return null;
     }
 }
示例#2
0
 protected function doSend($to, $message)
 {
     $request = new ClientRequest($this->url, ClientRequest::GET);
     $request->setParameters(array('k' => $this->appkey, 'r' => 'json', 'p' => 1, 't' => $to, 'c' => $message));
     $response = $this->sendRequest($request);
     return true;
 }
 /**
  * @param HTTPApiClientException $e
  * @param Response               $response
  * @param ClientRequest          $clientRequest
  * @throws HTTPApiClientException
  */
 protected function throwException(HTTPApiClientException $e, Response $response, ClientRequest $clientRequest)
 {
     $e->setExceptionMetaData('status_code', $response->getStatusCode());
     $e->setExceptionMetaData('content', $response->getContent());
     $e->setExceptionMetaData('header', $response->headers);
     $e->setExceptionMetaData('request', $clientRequest->toArray());
     throw $e;
 }
 /**
  * @param HTTPApiClient $apiClient
  * @param Response      $response
  * @param ClientRequest $clientRequest
  * @return Response
  * @throws MQSEmptyMessageException
  * @throws MQSResponseException
  */
 public function handle(HTTPApiClient $apiClient, Response $response, ClientRequest $clientRequest)
 {
     if ((int) $response->getStatusCode() >= 400) {
         if ((int) $response->getStatusCode() == 404) {
             //404 有可能是 Message not exist. 或者是 The queue name you provided is not exist.
             if (strpos($response->getContent(), 'Message not exist.')) {
                 throw new MQSEmptyMessageException();
             }
         }
         $e = new MQSResponseException("MQS返回状态码:" . $response->getStatusCode());
         $e->setExceptionMetaData('content', $response->getContent());
         $e->setExceptionMetaData('header', $response->headers);
         $e->setExceptionMetaData('request', $clientRequest->toArray());
         throw $e;
     }
     return $response;
 }
 public function prepare(ClientRequest $clientRequest)
 {
     $this->renew();
     $this->setUrl($clientRequest->getUrl());
     $this->setData($clientRequest->getContent());
     $this->setHeaders($clientRequest->getHeaders());
     $this->setMethod($clientRequest->getVerb());
     return $this;
 }
示例#6
0
 /**
  * 修改未被查看消息时间
  * 本接口用于修改被消费过并且还处于的Inactive的消息到下次可被消费的时间,成功修改消息的VisibilityTimeout后,返回新的ReceiptHandle。
  * @param $queueName
  * @param $receiptHandle
  * @param $visibilitytimeout
  * @return array
  */
 public function changeMessageVisibility($queueName, $receiptHandle, $visibilitytimeout)
 {
     $request = new ClientRequest("/" . $queueName . "/messages?ReceiptHandle=" . $receiptHandle . "&VisibilityTimeout=" . $visibilitytimeout, ClientRequest::PUT);
     $request->setContent("");
     $response = $this->sendRequest($request);
     $content = $response->getContent();
     return Util::getXmlData($content);
 }
 public function handle(HTTPApiClient $apiClient, ClientRequest $clientRequest)
 {
     if (!$apiClient instanceof Client) {
         return $clientRequest;
     }
     $content_md5 = base64_encode(md5($clientRequest->getContent()));
     $gmt_date = Util::getGMTDate();
     $clientRequest->setHeader('x-mqs-version', static::X_MQS_VERSION);
     $canonicalizedMQSHeaders = array();
     foreach ($clientRequest->getHeaders() as $key => $value) {
         if (preg_match('/^x\\-mqs\\-/', $key)) {
             $canonicalizedMQSHeaders[$key] = $value;
         }
     }
     ksort($canonicalizedMQSHeaders, SORT_STRING);
     $sign = Util::getSignature($clientRequest->getVerb(), $content_md5, static::CONTENT_TYPE, $gmt_date, $canonicalizedMQSHeaders, $clientRequest->getUrl(), $apiClient->getAccessKey(), $apiClient->getAccessSecret());
     $clientRequest->setHeader('Host', $apiClient->getQueueOwnerId() . "." . $apiClient->getMqsUrl());
     $clientRequest->setHeader('Date', $gmt_date);
     $clientRequest->setHeader('Content-Type', static::CONTENT_TYPE);
     $clientRequest->setHeader('Content-MD5', $content_md5);
     $clientRequest->setHeader('Authorization', $sign);
     $clientRequest->setUrl('http://' . $apiClient->getQueueOwnerId() . "." . $apiClient->getMqsUrl() . $clientRequest->getUrl());
     return $clientRequest;
 }