diff --git a/src/Apn.php b/src/Apn.php index 3bcee6f..a58df87 100644 --- a/src/Apn.php +++ b/src/Apn.php @@ -81,10 +81,14 @@ public function getUnregisteredDeviceTokens(array $devices_token) */ public function send(array $deviceTokens, array $message) { + if (false == $this->existCertificate()) { + return $this->feedback; + } + $responseCollection = [ 'success' => true, - 'errors' => [], - 'responses' => [], + 'error' => '', + 'results' => [], ]; if (!$this->curlMultiHandle) { @@ -151,7 +155,9 @@ public function send(array $deviceTokens, array $message) $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); if ($statusCode === 0) { - $responseCollection['errors'][] = [ + $responseCollection['success'] = false; + + $responseCollection['error'] = [ 'status' => $statusCode, 'headers' => $headers, 'body' => curl_error($handle), @@ -162,7 +168,7 @@ public function send(array $deviceTokens, array $message) $responseCollection['success'] = $responseCollection['success'] && $statusCode == 200; - $responseCollection['responses'][] = [ + $responseCollection['results'][] = [ 'status' => $statusCode, 'headers' => $headers, 'body' => (string)$body, @@ -280,4 +286,39 @@ public function prepareHandle($deviceToken, array $message) return $ch; } + /** + * Set the feedback with no exist any certificate. + * + * @return mixed|void + */ + private function messageNoExistCertificate() + { + $response = [ + 'success' => false, + 'error' => "Please, add your APN certificate to the iosCertificates folder." . PHP_EOL + ]; + + $this->setFeedback(json_decode(json_encode($response))); + } + + /** + * Check if the certificate file exist. + * @return bool + */ + private function existCertificate() + { + if (isset($this->config['certificate'])) { + $certificate = $this->config['certificate']; + if (!file_exists($certificate)) { + $this->messageNoExistCertificate(); + return false; + } + + return true; + } + + $this->messageNoExistCertificate(); + return false; + } + } \ No newline at end of file diff --git a/src/Gcm.php b/src/Gcm.php index 56b1664..fe29002 100644 --- a/src/Gcm.php +++ b/src/Gcm.php @@ -28,9 +28,9 @@ public function setApiKey($apiKey) */ public function __construct() { - $this->url = 'https://android.googleapis.com/gcm/send'; - - $this->config = $this->initializeConfig('gcm'); + $this->url = 'https://fcm.googleapis.com/fcm/send'; + + $this->config = $this->initializeConfig('fcm'); $this->client = new Client; } diff --git a/tests/PushNotificationTest.php b/tests/PushNotificationTest.php index 4ceb626..b8344e3 100644 --- a/tests/PushNotificationTest.php +++ b/tests/PushNotificationTest.php @@ -136,21 +136,6 @@ public function apn_without_certificate() $this->assertFalse($push->feedback->success); } - /** @test */ - public function apn_dry_run_option_update_the_apn_url() - { - $push = new PushNotification('apn'); - - $push->setConfig(['dry_run'=>false]); - - $this->assertEquals('ssl://gateway.push.apple.com:2195', $push->url); - - $push->setConfig(['dry_run'=>true]); - - $this->assertEquals('ssl://gateway.sandbox.push.apple.com:2195', $push->url); - } - - /** @test */ public function fcm_assert_send_method_returns_an_stdClass_instance() {