solved Push Notifications

nate
@nate
11 years ago
917 posts
I am about to use this script but I wanted to ask you guys if it's worth trying. Though I just started taking some formal php training I have no idea what curl_scrpt requires to run.

So, would the below curl functions work?

<?php

define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
(
    'message' => 'here is a message. message',
    'title'	=> 'This is a title. title',
    'subtitle'	=> 'This is a subtitle. subtitle',
    'tickerText'	=> 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate'	=> 1,
    'sound'	=> 1,
    'largeIcon'	=> 'large_icon',
    'smallIcon'	=> 'small_icon'
);
$fields = array (
    'registration_ids' => $registrationIds,
    'data'	=> $msg
);
$headers = array (
    'Authorization: key=' . API_ACCESS_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 );
echo $result; 

?>

updated by @nate: 01/13/15 05:41:14AM
brian
@brian
11 years ago
10,149 posts
This is for Google Cloud Messaging and looks OK to me. The only thing I would do is check that $_GET['id'] contains a valid ID (I think they are 160 chars long if I remember).

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
nate
@nate
11 years ago
917 posts
Yeah I am gonna change it to work off a queried ID. I was just curious that the curl_script would work.

Thanks.
brian
@brian
11 years ago
10,149 posts
Yeah the curl looks fine - you'll want to reference the docs for help on the supported parameters:

http://developer.android.com/google/gcm/index.html


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags