diff --git a/src/app/CompanionApp.php b/src/app/CompanionApp.php --- a/src/app/CompanionApp.php +++ b/src/app/CompanionApp.php @@ -2,8 +2,9 @@ namespace App; -use Illuminate\Database\Eloquent\Model; use App\Traits\UuidStrKeyTrait; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Http; /** * The eloquent definition of a CompanionApp. @@ -35,31 +36,18 @@ private static function pushFirebaseNotification($deviceIds, $data): bool { \Log::debug("sending notification to " . var_export($deviceIds, true)); - $apiKey = \config('firebase.api_key'); - $client = new \GuzzleHttp\Client( - [ - 'verify' => \config('firebase.api_verify_tls') - ] - ); - $response = $client->request( - 'POST', - \config('firebase.api_url'), - [ - 'headers' => [ - 'Authorization' => "key={$apiKey}", - ], - 'json' => [ - 'registration_ids' => $deviceIds, - 'data' => $data - ] - ] - ); + $apiKey = \config('firebase.api_key'); + $apiUrl = \config('firebase.api_url'); + $verify = \config('firebase.api_verify_tls'); + HTTP::withOptions(['verify' => $verify]) + ->withHeaders(['Authorization' => "key={$apiKey}"]) + ->timeout(5) + ->connectTimeout(5) + ->post($apiUrl, ['registration_ids' => $deviceIds, 'data' => $data]) + ->throwUnlessStatus(200); - if ($response->getStatusCode() != 200) { - throw new \Exception('FCM Send Error: ' . $response->getStatusCode()); - } return true; }