Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. var user = $ionicUser.get();
  2. if(!user.user_id) {
  3. // Set your user_id here, or generate a random one.
  4. user.user_id = $ionicUser.generateGUID();
  5. };
  6.  
  7.  
  8. // Identify your user with the Ionic User Service
  9. $ionicUser.identify(user).then(function(){
  10. //$scope.identified = true;
  11. //alert('User ID ' + user.user_id);
  12. //alert("here");
  13. $ionicPush.register({
  14. canShowAlert: true, //Can pushes show an alert on your screen?
  15. canSetBadge: true, //Can pushes update app icon badges?
  16. canPlaySound: true, //Can notifications play a sound?
  17. canRunActionsOnWake: true, //Can run actions outside the app,
  18. onNotification: function(notification) {
  19.  
  20. // Handle new push notifications here
  21. // console.log(notification);
  22. return true;
  23. }
  24. });
  25. });
  26.  
  27.  
  28.  
  29. });
  30. })
  31.  
  32. .config(['$ionicAppProvider', function($ionicAppProvider) {
  33. $ionicAppProvider.identify({
  34. app_id: 'xxxxxxxxxxxxx',
  35. api_key: 'xxxxxxxxxxxxxx',
  36. dev_push: false
  37. });
  38. }])
  39.  
  40. $deviceToken = 'APA91bHKwBKrIjmmZ9lke97fl_GbOQ9iRRo-S2sNnZp085hPqVaTHMOd0wqhYFF1PtrtOzFrETX7ZNIkU0JDhC49Tby_AEFIQFRX99B0QpZd7xdiTqsP6sZ08P-8ESdJAie5AJNxhW89nQ7S9evZNcAc9tsJaG91Xw';
  41.  
  42. $registrationIds = explode(",",$deviceToken);
  43.  
  44. //$registrationIds = array($deviceToken);
  45.  
  46. // prep the bundle
  47.  
  48. $msg = array
  49.  
  50. (
  51.  
  52. 'notId' => time(),
  53.  
  54. 'message' => 'Technovault is awesome!!!',
  55.  
  56. 'title' => 'Title',
  57.  
  58. 'smallIcon' =>'icon'
  59.  
  60.  
  61.  
  62. );
  63.  
  64. $fields = array
  65.  
  66. (
  67.  
  68. 'registration_ids' => $registrationIds,
  69.  
  70. 'data' => $msg
  71.  
  72. );
  73.  
  74. $headers = array
  75.  
  76. (
  77.  
  78. 'Authorization: key=' . 'xxxxxxxxxx',
  79.  
  80. 'Content-Type: application/json'
  81.  
  82. );
  83.  
  84. $ch = curl_init();
  85.  
  86. curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
  87.  
  88. curl_setopt( $ch,CURLOPT_POST, true );
  89.  
  90. curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
  91.  
  92. curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
  93.  
  94. curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
  95.  
  96. curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
  97.  
  98. $result = curl_exec($ch );
  99.  
  100. curl_close( $ch );
  101.  
  102. echo $result;
  103.  
  104. }
  105.  
  106. else {
  107.  
  108. echo "Error";
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement