Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
FirebaseNotificationSerice
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 Send
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Services;
4
5use Illuminate\Support\Facades\Hash;
6
7class FirebaseNotificationSerice
8{
9    public function  Send($title, $body, $image, $tokens, $data = [])
10    {
11        $registrationIDs = $tokens;
12        
13        $fcmMsg = array(
14            'body' => $body,
15            'title' => $title,
16            'image' => $image,
17            "sound"=> "default"
18        );
19
20        $fcmFields = array(
21            'registration_ids' => $registrationIDs,
22            'priority' => 'high',
23            'notification' => $fcmMsg,
24            'data' => response()->json($data),
25            'content_available' => true,
26        );
27
28        $headers = array(
29            'Authorization: key = ' . config('app.FIREBASE_API_KEY'),
30            'Content-Type: application/json'
31        );
32
33
34
35        $ch = curl_init();
36        curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
37        curl_setopt($ch, CURLOPT_POST, true);
38        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
39        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
40        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
41        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmFields));
42        $result = curl_exec($ch);
43
44        return $result;
45    }
46}