Home » Mobile » Android » Run php code online for android push notification

Run php code online for android push notification

Run php code online for android push notification

To Test push notification code online run below code with replace of $deviceTocken and $GOOGLE_API_KEY

To create API_KEY click here

 

<?php

 echo("Send notification");

 	$type = 'TEST';
	$greetMsg = 'Demo Notification';
	$respJson = '{"type":"'.$type.'","message":"'.$greetMsg.'"}';
$registation_ids = array();
$deviceTocken = '';
$GOOGLE_API_KEY ='';
		array_push($registation_ids, $deviceTocken);

    
 echo("Send notification\n\n=====");
	//Google cloud messaging GCM-API url
        $url = 'https://android.googleapis.com/gcm/send';
        $fields = array(
            'registration_ids' => $registation_ids,
            'data' => json_decode($respJson),
        );
		// Update your Google Cloud Messaging API Key
		if (!defined('GOOGLE_API_KEY')) {
			define("GOOGLE_API_KEY", $GOOGLE_API_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);
        
     echo("responce co================= $result" + $result );

?>

Then copy code from here to http://phpfiddle.org and past code in site and press run button.

About

Software Developer in android,java,phone gap,angular js etc interested in challenging work in problem solving.

Leave a Reply