321 |
www |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Command;
|
|
|
6 |
|
|
|
7 |
use Symfony\Component\Console\Command\Command;
|
|
|
8 |
use Symfony\Component\Console\Input\InputInterface;
|
|
|
9 |
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
10 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
11 |
use Laminas\Log\LoggerInterface;
|
|
|
12 |
use Laminas\Mvc\I18n\Translator;
|
|
|
13 |
use LeadersLinked\Cache\CacheInterface;
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
class TestSendPushCommand extends Command
|
|
|
17 |
{
|
|
|
18 |
/**
|
|
|
19 |
*
|
|
|
20 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
|
|
21 |
*/
|
|
|
22 |
private $adapter;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
*
|
|
|
26 |
* @var \LeadersLinked\Cache\CacheInterface
|
|
|
27 |
*/
|
|
|
28 |
private $cache;
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
*
|
|
|
33 |
* @var \Laminas\Log\LoggerInterface
|
|
|
34 |
*/
|
|
|
35 |
private $logger;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
*
|
|
|
39 |
* @var array
|
|
|
40 |
*/
|
|
|
41 |
private $config;
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
*
|
|
|
46 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
47 |
*/
|
|
|
48 |
private $translator;
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
*
|
|
|
53 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
54 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
55 |
* @param \Laminas\Log\LoggerInterface
|
|
|
56 |
* @param array $config
|
|
|
57 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
|
|
58 |
*/
|
|
|
59 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
|
|
60 |
{
|
|
|
61 |
$this->adapter = $adapter;
|
|
|
62 |
$this->cache = $cache;
|
|
|
63 |
$this->logger = $logger;
|
|
|
64 |
$this->config = $config;
|
|
|
65 |
$this->translator = $translator;
|
|
|
66 |
|
|
|
67 |
parent::__construct();
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
protected function execute(InputInterface $input, OutputInterface $output) : int
|
|
|
72 |
{
|
|
|
73 |
$output->writeln('Inicio del proceso');
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
$dirname = dirname(dirname(dirname(dirname(__DIR__))));
|
|
|
77 |
$filename = $dirname . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'google' . DIRECTORY_SEPARATOR . 'push-leaderslinked' . DIRECTORY_SEPARATOR . 'leaderlinked-1553079536948-firebase-adminsdk-1aahc-eecc297707.json';
|
|
|
78 |
|
|
|
79 |
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $filename);
|
|
|
80 |
|
|
|
81 |
$client= new \Google_Client();
|
|
|
82 |
$client->useApplicationDefaultCredentials();
|
|
|
83 |
$client->addScope('https://www.googleapis.com/auth/firebase.messaging');
|
|
|
84 |
$client->fetchAccessTokenWithAssertion();
|
|
|
85 |
$token = $client->getAccessToken();
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
$accessToken = $token['access_token'];
|
|
|
89 |
$devicesToken = [
|
|
|
90 |
'eJmAgQ0uSBqMvK5kyknWzs:APA91bGeJyEerjZX3jX5Ntl8CfaynmTRuZ2h3TPs2MYlpSAuBiR8lUUdosGtc54ZYvtTutZqeL07l4uZZrpy9QRc8k6zIzch-I2Ug1oE0smpF8MtuV4EJYk',
|
|
|
91 |
// 'fykf2Hx8QEiog4ZjiNvslh:APA91bFXE8zKW7yKdIzygEYYdyS9b6rCMI0ZKoJrs5JmA6GUhmHS0ccxCTqX3hjUThddSVR7GvCucogRUl7NLhEAjvs7Sg4sbBCr-PyyIk9g6gF2OhiwdYC8LmOSLVq18QtoBba6MWvs'
|
|
|
92 |
];
|
|
|
93 |
|
|
|
94 |
$headers = [
|
|
|
95 |
'Authorization: Bearer ' . $accessToken,
|
|
|
96 |
'Content-Type: application/json'
|
|
|
97 |
];
|
|
|
98 |
|
|
|
99 |
foreach( $devicesToken as $deviceToken)
|
|
|
100 |
{
|
|
|
101 |
$fields = [
|
|
|
102 |
'message' => [
|
|
|
103 |
'token' => $deviceToken,
|
|
|
104 |
'notification' => [
|
|
|
105 |
'body' => 'Body de Prueba 2 ',
|
|
|
106 |
'title' => 'Titulo de Prueba 2',
|
|
|
107 |
//'url' => 'https://dev-spa.leaderslinked.com/post/ed807f52-b418-4fd4-ba70-068604540212',
|
|
|
108 |
//'vibrate' => 1,
|
|
|
109 |
// 'sound' => 1
|
|
|
110 |
],
|
|
|
111 |
'data' => [
|
|
|
112 |
'url' => 'https://dev-spa.leaderslinked.com/post/ed807f52-b418-4fd4-ba70-068604540212',
|
|
|
113 |
],
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
],
|
|
|
117 |
];
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
$ch = curl_init();
|
|
|
125 |
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/v1/projects/leaderlinked-1553079536948/messages:send' );
|
|
|
126 |
curl_setopt( $ch,CURLOPT_POST, true );
|
|
|
127 |
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
|
|
|
128 |
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
|
|
|
129 |
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
|
|
|
130 |
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
|
|
|
131 |
$result = curl_exec($ch );
|
|
|
132 |
curl_close( $ch );
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
print_r($result);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
$output->writeln('Fin del proceso');
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
return 0;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
}
|