Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Console\Commands;
  4.  
  5. use Illuminate\Console\Command;
  6. use LaravelFCM\Message\OptionsBuilder;
  7. use LaravelFCM\Message\PayloadDataBuilder;
  8. use LaravelFCM\Message\PayloadNotificationBuilder;
  9. use FCM;
  10.  
  11. class PushNotificationSend extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'push_notification:send';
  19.  
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'Command description';
  26.  
  27. /**
  28. * Create a new command instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct()
  33. {
  34. parent::__construct();
  35. }
  36.  
  37. /**
  38. * Execute the console command.
  39. *
  40. * @return mixed
  41. */
  42. public function handle()
  43. {
  44. $optionBuilder = new OptionsBuilder();
  45. $optionBuilder->setTimeToLive(60*20);
  46.  
  47. $notificationBuilder = new PayloadNotificationBuilder();
  48. $notificationBuilder->setTitle('Hello')->setBody('world')
  49. ->setSound('default');
  50.  
  51. $dataBuilder = new PayloadDataBuilder();
  52. $dataBuilder->addData([
  53. 'body' => 'hello',
  54. 'title' => 'hello world',
  55. 'notification' => [
  56. 'name' => 'mahmud',
  57. 'age' => 25
  58. ]
  59. ]);
  60.  
  61. $option = $optionBuilder->build();
  62. $notification = $notificationBuilder->build();
  63. $data = $dataBuilder->build();
  64.  
  65. $token = "afT67fauFSG0:APA91bERkTizELghpP0G1lguz6gvwS0DgMdMfhq0UZrfWAnxIIzmjnFGtuHPbNfhf4M0Tm3oHZx7naVg0ph3XljaeZZ6qq0kBAEVv56DunGbLFQCtYZHG2Fdo8NG2hvOXasHz-c1war7a";
  66.  
  67. $downstreamResponse = FCM::sendTo($token, $option, $notification, $data);
  68.  
  69. dd(
  70. $downstreamResponse->numberSuccess(),
  71. $downstreamResponse->numberFailure()
  72. );
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement