update 1.0.8.0
Commits for version update
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
<?php namespace LaravelFCM\Sender;
|
||||
|
||||
/**
|
||||
* Class BaseSender
|
||||
*
|
||||
* @package LaravelFCM\Sender
|
||||
*/
|
||||
abstract class BaseSender {
|
||||
|
||||
/**
|
||||
* Guzzle Client
|
||||
* @var \Illuminate\Foundation\Application|mixed
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* configuration
|
||||
* @var array
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* url
|
||||
* @var mixed
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* BaseSender constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = app('fcm.client');
|
||||
$this->config = app('config')->get('fcm.http', []);
|
||||
|
||||
$this->url = $this->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected abstract function getUrl();
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
||||
*
|
||||
* @package LaravelFCM\Sender
|
||||
*/
|
||||
class FCMGroup extends BaseSender {
|
||||
class FCMGroup extends HTTPSender {
|
||||
|
||||
const CREATE = "create";
|
||||
const ADD = "add";
|
||||
@@ -96,13 +96,4 @@ class FCMGroup extends BaseSender {
|
||||
return $response->getReasonPhrase() != 'OK' || $response->getStatusCode() != 200;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getUrl()
|
||||
{
|
||||
return $this->config['server_group_url'];
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,21 @@
|
||||
<?php namespace LaravelFCM\Sender;
|
||||
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use LaravelFCM\FCMRequest;
|
||||
use LaravelFCM\Message\Options;
|
||||
use LaravelFCM\Message\PayloadData;
|
||||
use LaravelFCM\Message\PayloadNotification;
|
||||
use \GuzzleHttp\Psr7\Response as GuzzleResponse;
|
||||
use LaravelFCM\Message\Topics;
|
||||
use LaravelFCM\Request\Request;
|
||||
use LaravelFCM\Response\DownstreamResponse;
|
||||
use LaravelFCM\Message\Options;
|
||||
use LaravelFCM\Message\PayloadData;
|
||||
use LaravelFCM\Response\GroupResponse;
|
||||
use LaravelFCM\Response\TopicResponse;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use LaravelFCM\Response\DownstreamResponse;
|
||||
use LaravelFCM\Message\PayloadNotification;
|
||||
|
||||
/**
|
||||
* Class FCMSender
|
||||
*
|
||||
* @package LaravelFCM\Sender
|
||||
*/
|
||||
class FCMSender extends BaseSender {
|
||||
class FCMSender extends HTTPSender {
|
||||
|
||||
const MAX_TOKEN_PER_REQUEST = 1000;
|
||||
|
||||
@@ -39,17 +37,13 @@ class FCMSender extends BaseSender {
|
||||
{
|
||||
$response = null;
|
||||
|
||||
if (is_array($to)) {
|
||||
if (is_array($to) && !empty($to)) {
|
||||
|
||||
$partialTokens = array_chunk($to, self::MAX_TOKEN_PER_REQUEST, false);
|
||||
foreach ($partialTokens as $tokens) {
|
||||
$request = new Request($tokens, $options, $notification, $data);
|
||||
|
||||
try {
|
||||
$responseGuzzle = $this->client->post($this->url, $request->build());
|
||||
}
|
||||
catch (ClientException $e) {
|
||||
$responseGuzzle = $e->getResponse();
|
||||
}
|
||||
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
$responsePartial = new DownstreamResponse($responseGuzzle, $tokens);
|
||||
if (!$response) {
|
||||
@@ -62,8 +56,9 @@ class FCMSender extends BaseSender {
|
||||
}
|
||||
else {
|
||||
$request = new Request($to, $options, $notification, $data);
|
||||
$response = $this->client->post($this->url, $request->build());
|
||||
$response = new DownstreamResponse($response, $to);
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
$response = new DownstreamResponse($responseGuzzle, $to);
|
||||
}
|
||||
|
||||
return $response;
|
||||
@@ -83,14 +78,9 @@ class FCMSender extends BaseSender {
|
||||
{
|
||||
$request = new Request($notificationKey, $options, $notification, $data);
|
||||
|
||||
try {
|
||||
$response = $this->client->post($this->url, $request->build());
|
||||
}
|
||||
catch (ClientException $e) {
|
||||
$response = $e->getResponse();
|
||||
}
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
return new GroupResponse($response, $notificationKey);
|
||||
return new GroupResponse($responseGuzzle, $notificationKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,27 +95,29 @@ class FCMSender extends BaseSender {
|
||||
*/
|
||||
public function sendToTopic(Topics $topics, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
|
||||
$request = new Request(null, $options, $notification, $data, $topics);
|
||||
try {
|
||||
$response = $this->client->post($this->url, $request->build());
|
||||
}
|
||||
catch (ClientException $e) {
|
||||
$response = $e->getResponse();
|
||||
}
|
||||
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
return new TopicResponse($response, $topics);
|
||||
return new TopicResponse($responseGuzzle, $topics);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the url
|
||||
* @internal
|
||||
*
|
||||
* @return string
|
||||
* @param $request
|
||||
*
|
||||
* @return null|\Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
protected function getUrl()
|
||||
private function post($request)
|
||||
{
|
||||
return $this->config[ 'server_send_url' ];
|
||||
try {
|
||||
$responseGuzzle = $this->client->post($this->url, $request->build());
|
||||
}
|
||||
catch (ClientException $e) {
|
||||
$responseGuzzle = $e->getResponse();
|
||||
}
|
||||
|
||||
return $responseGuzzle;
|
||||
}
|
||||
}
|
||||
38
vendor/brozot/laravel-fcm/src/Sender/HTTPSender.php
vendored
Normal file
38
vendor/brozot/laravel-fcm/src/Sender/HTTPSender.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php namespace LaravelFCM\Sender;
|
||||
|
||||
use GuzzleHttp\ClientInterface;
|
||||
|
||||
/**
|
||||
* Class BaseSender
|
||||
*
|
||||
* @package LaravelFCM\Sender
|
||||
*/
|
||||
abstract class HTTPSender {
|
||||
|
||||
/**
|
||||
* The client used to send messages.
|
||||
*
|
||||
* @var GuzzleHttp\ClientInterface
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* The URL entry point.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* Initializes a new sender object.
|
||||
*
|
||||
* @param GuzzleHttp\ClientInterface $client
|
||||
* @param string $url
|
||||
*/
|
||||
public function __construct(ClientInterface $client, $url)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user