Last active
December 24, 2015 06:46
-
-
Save rahulpandey/c04e38c17429bdd65ac3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // generic php function to send GCM push notification | |
| public function sendPushNotificationToGCM($registatoin_ids, $message) { | |
| // Google cloud messaging GCM-API url | |
| $url = 'https://android.googleapis.com/gcm/send'; | |
| $fields = array ( | |
| 'registration_ids' => $registatoin_ids, | |
| 'data' => $message | |
| ); | |
| // Google Cloud Messaging GCM API Key | |
| define ( "GOOGLE_API_KEY", " GCM_KEY" ); | |
| $headers = array ( | |
| 'Authorization: key=' . GOOGLE_API_KEY, | |
| 'Content-Type: application/json' | |
| ); | |
| $ch = curl_init (); | |
| curl_setopt ( $ch, CURLOPT_URL, $url ); | |
| curl_setopt ( $ch, CURLOPT_POST, true ); | |
| curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers ); | |
| curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); | |
| curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); | |
| curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false ); | |
| curl_setopt ( $ch, CURLOPT_POSTFIELDS, json_encode ( $fields ) ); | |
| $result = curl_exec ( $ch ); | |
| if ($result === FALSE) { | |
| die ( 'Curl failed: ' . curl_error ( $ch ) ); | |
| } | |
| curl_close ( $ch ); | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
android wala bhi add kardo