当前位置: 首页>>代码示例>>PHP>>正文


PHP ClientInterface::post方法代码示例

本文整理汇总了PHP中GuzzleHttp\ClientInterface::post方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::post方法的具体用法?PHP ClientInterface::post怎么用?PHP ClientInterface::post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\ClientInterface的用法示例。


在下文中一共展示了ClientInterface::post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: authenticate

 /**
  * Authenticates a user and returns an authentication token.
  *
  * @param string $username
  * @param string $password
  * @return TokenInterface
  * @throws AccountDisabledException
  * @throws AccountNotConfirmedException
  * @throws AuthenticationException
  * @throws AuthorizationLimitReachedException
  * @throws UserNotFoundException
  * @throws WrongPasswordException
  */
 public function authenticate($username, $password)
 {
     $response = $this->httpClient->post('/auth', ['body' => ['username' => $username, 'password' => $password]])->json();
     if (isset($response['error'])) {
         switch ($response['code']) {
             case 101:
                 throw new UserNotFoundException();
             case 102:
                 throw new AccountNotConfirmedException();
             case 103:
             case 104:
             case 105:
                 throw new AccountDisabledException();
             case 106:
                 throw new AuthorizationLimitReachedException();
             case 107:
                 throw new WrongPasswordException();
             default:
                 throw new AuthenticationException('An error occurred during the authentication');
         }
     }
     $token = new Token();
     $token->setUid($response['uid']);
     $token->setToken($response['token']);
     return $token;
 }
开发者ID:amiceli,项目名称:t411-api-client,代码行数:39,代码来源:Client.php

示例2: verify

 /**
  * @param VerifyYubikeyOtpCommand $command
  * @return YubikeyVerificationResult
  */
 public function verify(VerifyYubikeyOtpCommand $command)
 {
     $this->logger->info('Verifying Yubikey OTP');
     $body = ['requester' => ['institution' => $command->institution, 'identity' => $command->identity], 'otp' => ['value' => $command->otp]];
     $response = $this->guzzleClient->post('api/verify-yubikey', ['json' => $body, 'exceptions' => false]);
     $statusCode = $response->getStatusCode();
     if ($statusCode != 200) {
         $type = $statusCode >= 400 && $statusCode < 500 ? 'client' : 'server';
         $this->logger->info(sprintf('Yubikey OTP verification failed; %s error', $type));
         return new YubikeyVerificationResult(true, false);
     }
     try {
         $result = $response->json();
     } catch (\RuntimeException $e) {
         $this->logger->error('Yubikey OTP verification failed; server responded with malformed JSON.');
         return new YubikeyVerificationResult(false, true);
     }
     if (!isset($result['status'])) {
         $this->logger->error('Yubikey OTP verification failed; server responded without status report.');
         return new YubikeyVerificationResult(false, true);
     }
     if ($result['status'] !== 'OK') {
         $this->logger->error('Yubikey OTP verification failed; server responded with non-OK status report.');
         return new YubikeyVerificationResult(false, true);
     }
     return new YubikeyVerificationResult(false, false);
 }
开发者ID:eefjevanderharst,项目名称:Stepup-SelfService,代码行数:31,代码来源:YubikeyService.php

示例3: send

 /**
  * {@inheritdoc}
  */
 public function send(Swift_Mime_Message $message, &$failedRecipients = null)
 {
     $this->beforeSendPerformed($message);
     $options = ['auth' => ['api', $this->key]];
     $options['multipart'] = [['name' => 'to', 'contents' => $this->getTo($message)], ['name' => 'message', 'contents' => (string) $message, 'filename' => 'message.mime']];
     return $this->client->post($this->url, $options);
 }
开发者ID:karapuk,项目名称:framework,代码行数:10,代码来源:MailgunTransport.php

示例4: sendSms

 public function sendSms(SendSmsCommand $command)
 {
     $this->logger->info('Requesting Gateway to send SMS');
     $body = ['requester' => ['institution' => $command->institution, 'identity' => $command->identity], 'message' => ['originator' => $command->originator, 'recipient' => $command->recipient, 'body' => $command->body]];
     $response = $this->guzzleClient->post('api/send-sms', ['json' => $body, 'exceptions' => false]);
     $statusCode = $response->getStatusCode();
     if ($statusCode != 200) {
         $this->logger->error(sprintf('SMS sending failed, error: [%s] %s', $response->getStatusCode(), $response->getReasonPhrase()), ['http-body' => $response->getBody() ? $response->getBody()->getContents() : '']);
         return false;
     }
     try {
         $result = $response->json();
     } catch (\RuntimeException $e) {
         $this->logger->error('SMS sending failed; server responded with malformed JSON.');
         return false;
     }
     if (!isset($result['status'])) {
         $this->logger->error('SMS sending failed; server responded without status report.');
         return false;
     }
     if ($result['status'] !== 'OK') {
         $this->logger->error('SMS sending failed; server responded with non-OK status report.');
         return false;
     }
     return true;
 }
开发者ID:surfnet,项目名称:stepup-bundle,代码行数:26,代码来源:GatewayApiSmsService.php

示例5: notify

 /**
  * Notifies the Flowdock channel of a deployment stage being initiated
  *
  * @param string $branchName
  * @param string $applicationName
  * @param string $connectionName
  * @param string $eventTitle
  * @param string $threadTitle
  * @return ResponseInterface
  * @throws FlowdockApiException
  */
 public function notify($branchName, $applicationName, $connectionName, $eventTitle, $threadTitle)
 {
     if (empty($branchName)) {
         throw new \InvalidArgumentException('branchName is an Invalid Argument');
     }
     if (empty($applicationName)) {
         throw new \InvalidArgumentException('applicationName is an Invalid Argument');
     }
     if (empty($connectionName)) {
         throw new \InvalidArgumentException('connectionName is an Invalid Argument');
     }
     if (empty($eventTitle)) {
         throw new \InvalidArgumentException('eventTitle is an Invalid Argument');
     }
     if (empty($threadTitle)) {
         throw new \InvalidArgumentException('threadTitle is an Invalid Argument');
     }
     $title = $this->formatEventTitle($branchName, $applicationName, $connectionName, $eventTitle);
     $body = json_encode(['flow_token' => $this->flowToken, 'event' => 'activity', 'author' => ['name' => get_current_user()], 'title' => $title, 'external_thread_id' => $this->externalThreadID, 'thread' => ['title' => $threadTitle, 'body' => '']]);
     $clientOptions = ['headers' => ['Content-Type' => 'application/json'], 'body' => $body];
     $response = $this->client->post(self::MESSAGE_API, $clientOptions);
     if ($response->getStatusCode() != 202) {
         throw new FlowdockApiException("Error: HTTP " . $response->getStatusCode() . " with message " . $response->getReasonPhrase());
     }
     return $response;
 }
开发者ID:peak-adventure-travel,项目名称:rocketeer-flowdock,代码行数:37,代码来源:RocketeerFlowdockMessage.php

示例6: execute

 /**
  * Execute an operaction
  *
  * A successful operation will return result as an array.
  * An unsuccessful operation will return null.
  *
  * @param  OperationInterface $op
  * @return array|null
  */
 public function execute(OperationInterface $op)
 {
     try {
         if ($op instanceof DeleteOperationInterface) {
             $response = $this->httpClient->delete($op->getEndpoint(), ['headers' => $op->getHeaders()]);
         } elseif ($op instanceof PostOperationInterface) {
             $response = $this->httpClient->post($op->getEndpoint(), ['headers' => $op->getHeaders(), 'body' => $op->getData()]);
         } elseif ($op instanceof PatchOperationInterface) {
             $response = $this->httpClient->patch($op->getEndpoint(), ['headers' => $op->getHeaders(), 'body' => $op->getData()]);
         } elseif ($op instanceof PutOperationInterface) {
             $response = $this->httpClient->put($op->getEndpoint(), ['headers' => $op->getHeaders(), 'body' => $op->getData()]);
         } else {
             $response = $this->httpClient->get($op->getEndpoint());
         }
     } catch (GuzzleHttp\Exception\ClientException $e) {
         throw new Exception\ClientException('ClientException occurred in request to Orchestrate: ' . $e->getMessage(), $e->getCode(), $e);
     } catch (GuzzleHttp\Exception\ServerException $e) {
         throw new Exception\ServerException('ServerException occurred in request to Orchestrate: ' . $e->getMessage(), $e->getCode(), $e);
     }
     $refLink = null;
     $location = null;
     if ($response->hasHeader('ETag')) {
         $refLink = str_replace('"', '', $response->getHeaderLine('ETag'));
     } elseif ($response->hasHeader('Link')) {
         $refLink = str_replace(['<', '>; rel="next"'], ['', ''], $response->getHeaderLine('Link'));
     }
     if ($response->hasHeader('Location')) {
         $location = $response->getHeaderLine('Location');
     }
     $rawValue = $response->getBody(true);
     $value = json_decode($rawValue, true);
     return $op->getObjectFromResponse($refLink, $location, $value, $rawValue);
 }
开发者ID:absynthe,项目名称:orchestrate-php-client,代码行数:42,代码来源:Client.php

示例7: post

 /**
  * {@inheritdoc}
  */
 public function post($url, array $headers = array(), $content = '')
 {
     $options = array('headers' => $headers, 'body' => $content);
     $request = $this->client->post($url, $options);
     $this->response = $request;
     return $this->response->getBody();
 }
开发者ID:fideloper,项目名称:DigitalOceanV2,代码行数:10,代码来源:Guzzle5Adapter.php

示例8: send

 /**
  * {@inheritdoc}
  */
 public function send(Swift_Mime_Message $message, &$failedRecipients = null)
 {
     $this->beforeSendPerformed($message);
     $data = ['key' => $this->key, 'to' => $this->getToAddresses($message), 'raw_message' => $message->toString(), 'async' => false];
     $options = ['form_params' => $data];
     $this->client->post('https://mandrillapp.com/api/1.0/messages/send-raw.json', $options);
     return $this->numberOfRecipients($message);
 }
开发者ID:narrowspark,项目名称:framework,代码行数:11,代码来源:Mandrill.php

示例9: send

 /**
  * {@inheritdoc}
  */
 public function send(Swift_Mime_Message $message, &$failedRecipients = null)
 {
     $this->beforeSendPerformed($message);
     $version = phpversion() ?? 'Unknown PHP version';
     $os = PHP_OS ?? 'Unknown OS';
     $this->client->post('https://api.postmarkapp.com/email', ['headers' => ['X-Postmark-Server-Token' => $this->serverToken, 'Content-Type' => 'application/json', 'User-Agent' => "postmark (PHP Version: {$version}, OS: {$os})"], 'json' => $this->getMessagePayload($message)]);
     return $this->numberOfRecipients($message);
 }
开发者ID:narrowspark,项目名称:framework,代码行数:11,代码来源:Postmark.php

示例10: send

 /**
  * {@inheritdoc}
  */
 public function send(Swift_Mime_Message $message, &$failedRecipients = null)
 {
     $this->beforeSendPerformed($message);
     $recipients = $this->getRecipients($message);
     $message->setBcc([]);
     $options = ['headers' => ['Authorization' => $this->key], 'json' => ['recipients' => $recipients, 'content' => ['email_rfc822' => $message->toString()]]];
     return $this->client->post('https://api.sparkpost.com/api/v1/transmissions', $options);
 }
开发者ID:Penderis,项目名称:penderis.co.za,代码行数:11,代码来源:SparkPostTransport.php

示例11: send

 /**
  * {@inheritdoc}
  */
 public function send(Swift_Mime_Message $message, &$failedRecipients = null)
 {
     $this->beforeSendPerformed($message);
     $recipients = $this->getRecipients($message);
     $message->setBcc([]);
     $options = ['headers' => ['Authorization' => $this->key], 'json' => ['recipients' => $recipients, 'content' => ['html' => $message->getBody(), 'from' => $this->getFrom($message), 'reply_to' => $this->getReplyTo($message), 'subject' => $message->getSubject()]]];
     return $this->client->post('https://api.sparkpost.com/api/v1/transmissions', $options);
 }
开发者ID:hakoncms,项目名称:hakoncms,代码行数:11,代码来源:SparkPostTransport.php

示例12: auth

 /**
  * Authentication
  */
 public function auth()
 {
     $this->handlerStack->remove('reAuth');
     $res = $this->client->post($this->config->get('authUri'), ['form_params' => ['client_id' => $this->config->get('clientId'), 'client_secret' => $this->config->get('clientSecret'), 'grant_type' => 'client_credentials', 'scope' => 'https://graph.microsoft.com/.default']]);
     $json = \GuzzleHttp\json_decode($res->getBody(), true);
     $now = new \DateTime('now', new \DateTimeZone('UTC'));
     $json['expires_in'] = $now->getTimestamp() + $json['expires_in'];
     $this->tokenStorage->write($json);
 }
开发者ID:radutopala,项目名称:skype-bot-php,代码行数:12,代码来源:Client.php

示例13: verifyIpnMessage

 /**
  * {@inheritdoc}
  */
 public function verifyIpnMessage(Message $message)
 {
     $requestBody = array_merge(['cmd' => '_notify-validate'], $message->getAll());
     try {
         $response = $this->httpClient->post($this->serviceEndpoint, array('form_params' => $requestBody));
     } catch (\Exception $e) {
         throw new ServiceException($e->getMessage());
     }
     return new ServiceResponse((string) $response->getBody());
 }
开发者ID:mike182uk,项目名称:paypal-ipn-listener,代码行数:13,代码来源:GuzzleService.php

示例14: uuidApi

 public function uuidApi($username)
 {
     $response = $this->client->post(static::UUID_API, array('headers' => array('Content-Type' => 'application/json'), 'body' => json_encode(array('agent' => 'minecraft', 'name' => $username))))->json(array('object' => true));
     if (!$response) {
         throw new \RuntimeException('Bad JSON from API: on username ' . $username);
     } elseif (isset($response->error)) {
         throw new \RuntimeException('Error from API: ' . $response->error . ' on username ' . $username);
     }
     return $response;
 }
开发者ID:kyroskoh,项目名称:MinecraftProfile,代码行数:10,代码来源:ApiClient.php

示例15: send

 /**
  * {@inheritdoc}
  */
 public function send(Swift_Mime_Message $message, &$failedRecipients = null)
 {
     $options = ['auth' => ['api', $this->key]];
     if (version_compare(ClientInterface::VERSION, '6') === 1) {
         $options['multipart'] = [['name' => 'to', 'contents' => $this->getTo($message)], ['name' => 'message', 'contents' => (string) $message, 'filename' => 'message.mime']];
     } else {
         $options['body'] = ['to' => $this->getTo($message), 'message' => new PostFile('message', (string) $message)];
     }
     return $this->client->post($this->url, $options);
 }
开发者ID:nsoimaru,项目名称:Laravel51-starter,代码行数:13,代码来源:MailgunTransport.php


注:本文中的GuzzleHttp\ClientInterface::post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。