本文整理匯總了PHP中Buzz\Browser類的典型用法代碼示例。如果您正苦於以下問題:PHP Browser類的具體用法?PHP Browser怎麽用?PHP Browser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Browser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: checkAnswer
/**
* Calls an HTTP POST function to verify if the user's guess was correct
*
* @param string $remoteIp
* @param string $challenge
* @param string $response
* @throws Exception
* @return boolean
*/
public function checkAnswer($remoteIp, $challenge, $response)
{
if (empty($remoteIp)) {
throw new CaptchaException('RemoteIp missing');
}
$headers = array('User-Agent' => 'solvemedia/PHP', 'Content-Type' => 'application/x-www-form-urlencoded', 'Connection' => 'close');
$content = array('privatekey' => $this->privateKey, 'remoteip' => $remoteIp, 'challenge' => $challenge, 'response' => $response);
$browser = new Browser();
try {
/** @var Response $resp */
$resp = $browser->post(self::ADCOPY_VERIFY_SERVER, $headers, http_build_query($content));
} catch (Exception $e) {
throw new CaptchaException('Failed to check captcha', 500, $e);
}
if (!$resp->isSuccessful()) {
throw new CaptchaException('Error: ' . $resp->getStatusCode());
}
/**
* 0: true|false
* 1: errorMessage (optional)
* 2: hash
*/
$answers = explode("\n", $resp->getContent());
$success = filter_var($answers[0], FILTER_VALIDATE_BOOLEAN);
if (!$success) {
return new CaptchaResponse($success, $answers[1]);
}
$hashMaterial = $answers[0] . $challenge . $this->hashKey;
$hash = sha1($hashMaterial);
if ($hash != $answers[2]) {
throw new CaptchaException('Hash verification error');
}
return new CaptchaResponse($success);
}
示例2: plugAction
/**
* @Route("/produit/{id}", name="product_plug")
* @Template()
*/
public function plugAction($id)
{
$browser = new Browser();
$response = $browser->get($this->container->getParameter("back_site") . 'api/products/' . $id);
$product = $this->get('jms_serializer')->deserialize($response->getContent(), 'Kali\\Front\\CommandBundle\\Entity\\Product', 'json');
return array('product' => $product, 'site' => $this->container->getParameter("back_site"), 'caracteristics' => $product->getCaracteristics());
}
示例3: checkAnswer
/**
* Calls an HTTP POST function to verify if the user's guess was correct
*
* @param string $remoteIp
* @param string $challenge
* @param string $response
* @throws Exception
* @return boolean
*/
public function checkAnswer($remoteIp, $challenge, $response)
{
if (empty($remoteIp)) {
throw new CaptchaException('RemoteIp missing');
}
$headers = array('Connection' => 'close');
$content = array('secret' => $this->privateKey, 'remoteip' => $remoteIp, 'response' => $response);
$browser = new Browser();
$browser->getClient()->setVerifyPeer(false);
try {
/** @var Response $resp */
$resp = $browser->post(self::VERIFY_SERVER, $headers, http_build_query($content));
} catch (Exception $e) {
throw new CaptchaException('Failed to check captcha', 500, $e);
}
if (!$resp->isSuccessful()) {
throw new CaptchaException('Error: ' . $resp->getStatusCode());
}
$answer = json_decode($resp->getContent());
if (!$answer) {
throw new CaptchaException('Error: Invalid captcha response');
}
$success = isset($answer->success) && filter_var($answer->success, FILTER_VALIDATE_BOOLEAN);
if (!$success) {
return new CaptchaResponse($success, 'Invalid captcha');
}
return new CaptchaResponse($success);
}
示例4: sendHeartbeat
public function sendHeartbeat()
{
$ip = null;
$localIps = $this->getLocalIp();
if (isset($localIps['eth0'])) {
$ip = $localIps['eth0'];
} elseif (isset($localIps['wlan0'])) {
$ip = $localIps['wlan0'];
}
if (null == $ip) {
throw new \Exception('No local IP available.');
}
$settings = $this->em->getRepository('AppBundle:Settings')->findAll();
if (count($settings) > 0) {
$settings = $settings[0];
} else {
throw new \Exception('No settings provided.');
}
$buzz = new Browser();
$response = $buzz->post($settings->getHeartbeatUrl(), array('Content-Type' => 'application/json'), json_encode(array('locale_ip' => $ip, 'printbox' => $settings->getPrintboxPid())));
if ($response->isSuccessful()) {
return $ip;
}
throw new \Exception('Heartbeat failed: ' . $settings->getHeartbeatUrl() . ' ' . $response->getStatusCode() . ' ' . $response->getContent());
}
示例5: checkAnswer
/**
* Calls an HTTP POST function to verify if the user's guess was correct
*
* @param string $remoteIp
* @param string $challenge
* @param string $response
* @throws Exception
* @return boolean
*/
public function checkAnswer($remoteIp, $challenge, $response)
{
$headers = array('Connection' => 'close');
$content = array('private_key' => $this->privateKey, 'session_token' => $response, 'simple_mode' => 1);
$browser = new Browser();
$browser->getClient()->setVerifyPeer(false);
try {
/** @var Response $resp */
$resp = $browser->post(self::VERIFY_SERVER, $headers, http_build_query($content));
} catch (Exception $e) {
throw new CaptchaException('Failed to send captcha', 500, $e);
}
if (!$resp->isSuccessful()) {
throw new CaptchaException('Error: ' . $resp->getStatusCode());
}
$answer = $resp->getContent();
if (!$answer) {
throw new CaptchaException('Error: Invalid captcha response');
}
$success = isset($answer) && filter_var($answer, FILTER_VALIDATE_INT);
if (!$success) {
return new CaptchaResponse($success, 'Invalid captcha');
}
return new CaptchaResponse($success);
}
示例6: testYuml
/**
* @dataProvider fileProvider
*/
public function testYuml(BuilderInterface $builder, $fixture, $config)
{
$result = $builder->configure($config)->setPath($fixture)->build();
$this->assertInternalType('array', $result);
$this->assertGreaterThan(0, count($result));
$b = new Browser();
foreach ($result as $message) {
$url = explode(' ', $message);
$response = $b->get($url[1]);
$contentType = null;
switch ($url[0]) {
case '<info>PNG</info>':
$contentType = 'image/png';
break;
case '<info>PDF</info>':
$contentType = 'application/pdf';
break;
case '<info>URL</info>':
$contentType = 'text/html; charset=utf-8';
break;
case '<info>JSON</info>':
$contentType = 'application/json';
break;
case '<info>SVG</info>':
$contentType = 'image/svg+xml';
break;
}
$this->assertEquals($contentType, $response->getHeader('Content-Type'));
}
}
示例7: listAction
/**
* @Route("/category/list", name="category_list")
* @Template()
*/
public function listAction()
{
$browser = new Browser();
$response = $browser->get($this->container->getParameter("back_site") . 'api/all/category');
$categories = $this->get('jms_serializer')->deserialize($response->getContent(), 'Doctrine\\Common\\Collections\\ArrayCollection', 'json');
return array("categories" => $categories);
}
示例8: sloganAction
/**
* @Route("/slogan", name="site_slogan")
* @Template()
*/
public function sloganAction()
{
$browser = new Browser();
$response = $browser->get($this->container->getParameter("back_site") . 'api/parameters');
$paramater = $this->get('jms_serializer')->deserialize($response->getContent(), 'Kali\\Front\\SiteBundle\\Entity\\Parameter', 'json');
return array('slogan' => $paramater->getSlogan(), 'site' => $this->container->getParameter("back_site"));
}
示例9: send
/**
* Send request and generate response.
*
* @param Bool secure
*
* @throws UniversalAnalytics\Exception\InvalidRequestException
*
* @return Response
*/
public function send($secure = true)
{
$buzzBrowser = new Browser();
$buzzBrowser->setClient(new Curl());
$base = $secure ? $this->base_ssl : $this->base;
$buzzResponse = $buzzBrowser->submit($base, $this->attributes, RequestInterface::METHOD_POST, array());
return new Response($buzzResponse);
}
示例10: execute
/**
* Executes a http request.
*
* @param Request $request The http request.
*
* @return Response The http response.
*/
public function execute(Request $request)
{
$method = $request->getMethod();
$endpoint = $request->getEndpoint();
$params = $request->getParams();
$headers = $request->getHeaders();
try {
if ($method === 'GET') {
$buzzResponse = $this->client->call($endpoint . '?' . http_build_query($params), $method, $headers, array());
} else {
$buzzRequest = new FormRequest();
$buzzRequest->fromUrl($endpoint);
$buzzRequest->setMethod($method);
$buzzRequest->setHeaders($headers);
foreach ($params as $key => $value) {
if ($value instanceof Image) {
$value = new FormUpload($value->getData());
}
$buzzRequest->setField($key, $value);
}
$buzzResponse = new BuzzResponse();
$this->client->send($buzzRequest, $buzzResponse);
}
} catch (RequestException $e) {
throw new Exception($e->getMessage());
}
return static::convertResponse($request, $buzzResponse);
}
示例11: send
/**
* Sends the message via the GCM server.
*
* @param mixed $data
* @param array $registrationIds
* @param array $options
* @param string $payload_type
*
* @return bool
*/
public function send($data, array $registrationIds = array(), array $options = array(), $payload_type = 'data')
{
$this->responses = array();
if (!in_array($payload_type, ['data', 'notification'])) {
$payload_type = 'data';
}
$data = array_merge($options, array($payload_type => $data));
if (isset($options['to'])) {
$this->responses[] = $this->browser->post($this->apiUrl, $this->getHeaders(), json_encode($data));
} elseif (count($registrationIds) > 0) {
// Chunk number of registration ID's according to the maximum allowed by GCM
$chunks = array_chunk($registrationIds, $this->registrationIdMaxCount);
// Perform the calls (in parallel)
foreach ($chunks as $registrationIds) {
$data['registration_ids'] = $registrationIds;
$this->responses[] = $this->browser->post($this->apiUrl, $this->getHeaders(), json_encode($data));
}
}
$this->client->flush();
foreach ($this->responses as $response) {
$message = json_decode($response->getContent());
if ($message === null || $message->success == 0 || $message->failure > 0) {
return false;
}
}
return true;
}
示例12: getLatestResponseHeaders
/**
* {@inheritdoc}
*/
public function getLatestResponseHeaders()
{
if (null === ($response = $this->browser->getLastResponse())) {
return;
}
return ['reset' => (int) $response->getHeader('RateLimit-Reset'), 'remaining' => (int) $response->getHeader('RateLimit-Remaining'), 'limit' => (int) $response->getHeader('RateLimit-Limit')];
}
示例13: getUserDetails
/**
* @param string $token
*
* @return ProviderMetadata
*/
public function getUserDetails($token)
{
try {
// Fetch user data
list($identifier, $secret) = explode('@', $token);
$tokenObject = new TokenCredentials();
$tokenObject->setIdentifier($identifier);
$tokenObject->setSecret($secret);
$url = 'https://api.bitbucket.org/2.0/user';
$headers = $this->oauthProvider->getHeaders($tokenObject, 'GET', $url);
$response = $this->httpClient->get($url, $headers);
$data = json_decode($response->getContent(), true);
if (empty($data) || json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json error');
}
// Fetch email
$url = sprintf('https://api.bitbucket.org/1.0/users/%s/emails', $data['username']);
$headers = $this->oauthProvider->getHeaders($tokenObject, 'GET', $url);
$response = $this->httpClient->get($url, $headers);
$emails = json_decode($response->getContent(), true);
if (empty($emails) || json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json error');
}
$emails = array_filter($emails, function ($emailData) {
return true === $emailData['primary'];
});
$data['email'] = empty($emails) ? '' : current($emails)['email'];
return new ProviderMetadata(['uid' => $data['uuid'], 'nickName' => $data['username'], 'realName' => $data['display_name'], 'email' => $data['email'], 'profilePicture' => $data['links']['avatar']['href'], 'homepage' => $data['links']['html']['href'], 'location' => $data['location']]);
} catch (\Exception $e) {
throw new \RuntimeException('cannot fetch account details', 0, $e);
}
}
示例14: send
/**
* @param string $endpoint
* @param string $content
* @param array $headers
* @param array $files
* @return Response
*/
public function send($endpoint, $content, array $headers = array(), array $files = array())
{
// Make headers buzz friendly
array_walk($headers, function (&$value, $key) {
$value = sprintf('%s: %s', $key, $value);
});
if ($files) {
// HTTP query content
parse_str($content, $fields);
// Add files to request
foreach ($files as $key => $items) {
$fields[$key] = array();
foreach ($items as $name => $item) {
$item = new FormUpload($item);
if (!is_numeric($name)) {
$item->setName($name);
}
$fields[$key] = $item;
}
}
$response = $this->browser->submit($endpoint, $fields, RequestInterface::METHOD_POST, array_values($headers));
} else {
// JSON content
$response = $this->browser->post($endpoint, array_values($headers), $content);
}
return new Response($response->getStatusCode(), $response->getContent());
}
示例15: send
/**
* Sends the data to the given registration IDs via the GCM server
*
* @param \RMS\PushNotificationsBundle\Message\MessageInterface $message
* @throws \RMS\PushNotificationsBundle\Exception\InvalidMessageTypeException
* @return bool
*/
public function send(MessageInterface $message)
{
if (!$message instanceof AndroidMessage) {
throw new InvalidMessageTypeException(sprintf("Message type '%s' not supported by GCM", get_class($message)));
}
if (!$message->isGCM()) {
throw new InvalidMessageTypeException("Non-GCM messages not supported by the Android GCM sender");
}
$headers = array("Authorization: key=" . $this->apiKey, "Content-Type: application/json");
$data = array_merge($message->getGCMOptions(), array("data" => $message->getData()));
// Chunk number of registration IDs according to the maximum allowed by GCM
$chunks = array_chunk($message->getGCMIdentifiers(), $this->registrationIdMaxCount);
// Perform the calls (in parallel)
$this->responses = array();
foreach ($chunks as $registrationIDs) {
$data["registration_ids"] = $registrationIDs;
$this->responses[] = $this->browser->post($this->apiURL, $headers, json_encode($data));
}
// If we're using multiple concurrent connections via MultiCurl
// then we should flush all requests
if ($this->browser->getClient() instanceof MultiCurl) {
$this->browser->getClient()->flush();
}
// Determine success
foreach ($this->responses as $response) {
$message = json_decode($response->getContent());
if ($message === null || $message->success == 0 || $message->failure > 0) {
return false;
}
}
return true;
}