Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function sendFCM($message, $receivers, $api_key){
- $fields = array(
- 'registration_ids' => is_array($receivers) ? $receivers : [$receivers],
- 'data' => $message,
- );
- $headers = array('Authorization:key='.$api_key,'Content-Type:application/json');
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
- curl_setopt( $ch, CURLOPT_POST, true);
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement