Advertisement
vergepuppeter

GCM Php code

Dec 10th, 2015
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2. // API access key from Google API's Console
  3. define( 'API_ACCESS_KEY', 'AIzaSyB41Wf8s_i8kSU_0hX-UusCh3k8GiSpA6w' );
  4. $registrationIds = array( 'cyMSGTKBzwU:APA91bFcP4l_h7r9u1tlK58fx2bRff1Vo8xLgj0Vkhq9uHHPqgRgp3TW9DkIQcBn81Y0ToLK0Z95kgtkksKmeHrkA5YnrgEOtHq-U1ppt9BT-Kj01tLVA_J7S8_xMKgjgN32WfoJY6mI' ); //Device token for target device
  5.  
  6.  
  7. // Modify payload here
  8. $msg = array
  9. (
  10.     //This is for redirect no 1
  11.     //  'message'       => 'You received a new message on wowintro!',
  12.     //  'redirect'      => '1',
  13.     //  'user_key'      => '1025',
  14.     //  'user_name'     =>  'Amad Yus'
  15.    
  16.     //This is for redirect no 2
  17.     //  'message'       => 'Your wowintro was just favorited!',
  18.     //   'redirect'      => '2'
  19.    
  20.     //This is for redirect no 3
  21.     //  'message'       => 'You just got wowed!',
  22.     //   'redirect'      => '3'
  23.    
  24.     //This is for redirect no 4
  25.     //  'message'       => 'Your video has been uploaded!',
  26.     //   'redirect'      => '4'
  27.    
  28.     //This is for redirect no 5
  29.     //    'message'       => 'You have a knock on your door!',
  30.     //    'redirect'      => '5',
  31.     //  'job_post_key'  => '24'
  32.    
  33.     //This is for redirect no 6
  34.         'message'       => 'A familiar face just registered with wowintro!',
  35.         'redirect'      => '6',
  36.         'user_name' => 'ahmadyusri91'
  37.        
  38. );
  39. $fields = array
  40. (
  41.         'registration_ids'      => $registrationIds,
  42.         'data'                  => $msg
  43. );
  44.  
  45. $headers = array
  46. (
  47.         'Authorization: key=' . API_ACCESS_KEY,
  48.         'Content-Type: application/json'
  49. );
  50.  
  51. $ch = curl_init();
  52. curl_setopt( $ch,CURLOPT_URL, 'https://gcm-http.googleapis.com/gcm/send' );
  53. curl_setopt( $ch,CURLOPT_POST, true );
  54. curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
  55. curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
  56. curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
  57. curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
  58. $result = curl_exec($ch );
  59. curl_close( $ch );
  60. echo $result;
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement