Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4131 | Rev 5837 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4113 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
 
7
use \Firebase\JWT\JWT;
8
use GuzzleHttp\Client;
9
 
10
use Laminas\Db\Adapter\AdapterInterface;
11
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
12
use Laminas\Mvc\Controller\AbstractActionController;
13
use Laminas\Log\LoggerInterface;
14
use Laminas\View\Model\JsonModel;
15
 
16
class ZoomController extends AbstractActionController
17
{
18
    /**
19
     *
20
     * @var AdapterInterface
21
     */
22
    private $adapter;
23
 
24
 
25
    /**
26
     *
27
     * @var AbstractAdapter
28
     */
29
    private $cache;
30
 
31
    /**
32
     *
33
     * @var  LoggerInterface
34
     */
35
    private $logger;
36
 
37
    /**
38
     *
39
     * @var array
40
     */
41
    private $config;
42
 
43
 
44
 
45
 
46
    /**
47
     *
48
     * @param AdapterInterface $adapter
49
     * @param AbstractAdapter $cache
50
     * @param LoggerInterface $logger
51
     * @param array $config
52
     */
53
    public function __construct($adapter, $cache , $logger, $config)
54
    {
55
        $this->adapter      = $adapter;
56
        $this->cache        = $cache;
57
        $this->logger       = $logger;
58
        $this->config       = $config;
59
    }
60
 
61
 
62
    public function indexAction()
63
    {
64
 
65
        $data = [
66
            'success' => false,
67
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
68
        ];
69
 
70
 
71
        return new JsonModel($data);
72
    }
73
 
4131 efrain 74
    public function addAction()
4113 efrain 75
    {
4419 efrain 76
        /*
4131 efrain 77
        $currentUserPlugin = $this->plugin('currentUserPlugin');
78
        $currentUser = $currentUserPlugin->getUser();
4113 efrain 79
 
80
        $request = $this->getRequest();
81
 
4131 efrain 82
      //  if($request->isPost()) {
83
 
4113 efrain 84
            $base_url = $this->config['leaderslinked.zoom.base_url'];
85
            $token = $this->getAccessToken();
86
 
87
 
88
            $client = new Client([
89
 
90
                'base_uri' => $base_url,
91
            ]);
92
 
93
            $response = $client->request('POST', '/v2/users/me/meetings', [
94
                'headers' => [
95
                    'Authorization' => 'Bearer ' . $token
96
                ],
97
                'json' => [
98
                    'topic' => 'Let s Learn WordPress',
4131 efrain 99
                    'agenda' => 'Description Let s Learn WordPress',
4113 efrain 100
                    'type' => 2,
101
                    'start_time' => '2023-01-30T20:30:00',
102
                    'duration' => '30', // 30 mins
103
                    'password' => '123456',
104
                    'timezone' => 'America/Caracas',
4131 efrain 105
                    'settings' => [
106
                        'participant_video'=> 'true',
107
                        'auto_recording' => 'none',
108
                    ]
4113 efrain 109
                ],
110
            ]);
111
 
112
 
4131 efrain 113
 
4113 efrain 114
 
4131 efrain 115
            $data = json_decode($response->getBody()->getContents());
116
            echo '<pre>';
117
            print_r($data);
118
            echo '</pre>';
119
            exit;
120
 
121
 
122
            //echo "Join URL: ". $data->join_url;
123
            //echo "<br>";
124
            //echo "Meeting Password: ". $data->password;
4113 efrain 125
 
4131 efrain 126
 
4419 efrain 127
       } else {
4113 efrain 128
            $data = [
129
                'success' => false,
130
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
131
            ];
132
 
133
            return new JsonModel($data);
134
        }
135
 
4419 efrain 136
        */
4113 efrain 137
 
4419 efrain 138
        $token = 'EAAJaDxnm8uIBAGYjnYpOvjzm1BXbBgTtqfwn4YbagqIBGxfpWVZBObWtcnvfTJB6hMfHLWZBgG7dQ2O2UYMqZALYSLIQZC8swoNsHNYe3AMBkOjkt7YZBuIfXe22yyTgUZCBzGlsjbs0f72nNDvMlGNQlkCYNi3ZCDdXH61z9nW9xxUcdAnhk6M';
139
        $token = 'EAAJaDxnm8uIBAF3XfBml8yh9PqHOfO0UcwYALZAmoZCSPx6IkNZCRaVQaSWJfQALBqaRZCMziTddfvKgiVs1jwftg2sMyZBGixRTSDcXfvOv3nO4gZA2pCyruxa5iA1ZB01C83o2ZAg1Lnb07jeGF2C4d1Tauu3ZB9sZCJTkY4jMPt1Gnx8tpm5MAd';
140
        $client = new Client([
141
 
142
            'base_uri' => 'https://graph.facebook.com/v15.0',
143
        ]);
144
 
145
        //$to = '584244343638';
146
        //$to = '59898137899';
147
        $to = '584122788242';
148
 
149
        $response = $client->request('POST', '/111473331819706/messages', [
150
            'headers' => [
151
                'Authorization' => 'Bearer ' . $token
152
            ],
153
            'json' => [
154
                'messaging_product' => 'whatsapp',
155
                'recipient_type' => 'individual',
156
                'to' => $to,
157
 
158
                'type' => 'text',
159
                'text' => [
160
                    'preview_url' =>  false,
161
                    'body' => 'MESSAGE_CONTENT'
162
                ]
163
                /*
164
                'type' => 'template',
165
                'template' => [
166
                    'name' => 'hello_world',
167
                    'language' => [
168
                        'code' => 'en_US'
169
                    ]
170
                ] */
171
            ],
172
        ]);
173
 
174
        echo '<pre>';
175
       print_r($response->getBody()->getContents());
176
       echo '</pre>';
177
       exit;
178
 
4113 efrain 179
    }
180
 
181
    public function listingAction()
182
    {
183
        $request = $this->getRequest();
184
 
185
        //if($request->isGet()) {
186
 
187
            $next_page_token = $this->params()->fromRoute('next_page');
188
 
189
 
190
            $base_url = $this->config['leaderslinked.zoom.base_url'];
191
            $token = $this->getAccessToken();
192
 
193
            $client = new Client([
194
 
195
                'base_uri' => $base_url,
196
            ]);
197
 
198
            $request = [
199
                'headers' => [
200
                    'Authorization' => 'Bearer '. $token
201
                ],
202
                'type' => 'scheduled'
203
            ];
204
 
205
            if (!empty($next_page_token)) {
206
                $request['query'] = ['next_page_token' => $next_page_token];
207
            }
208
 
209
            $response = $client->request('GET', '/v2/users/me/meetings', $request);
210
 
211
echo '<pre>';
212
print_r(json_decode($response->getBody()->getContents()));
213
echo '</pre>';
214
exit;
215
 
216
            $data = json_decode($response->getBody());
217
 
218
            if ( !empty($data) ) {
219
                foreach ( $data->meetings as $d ) {
220
                    $topic = $d->topic;
221
                    $join_url = $d->join_url;
222
                    echo "<h3>Topic: $topic</h3>";
223
                    echo "Join URL: $join_url";
224
                }
225
 
226
                if ( !empty($data->next_page_token) ) {
227
                    list_meetings($data->next_page_token);
228
                }
229
            }
230
 
231
           /*
232
        } else {
233
            $data = [
234
                'success' => false,
235
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
236
            ];
237
 
238
 
239
        }
240
 
241
        return new JsonModel($data);*/
242
    }
243
 
244
    public function  deleteAction()
245
    {
246
        $request = $this->getRequest();
247
 
248
        //if($request->isPost()) {
249
 
250
            $meeting_id =  $this->params()->fromRoute('id');
251
 
252
 
253
 
254
            $base_url = $this->config['leaderslinked.zoom.base_url'];
255
            $token = $this->getAccessToken();
256
 
257
            $client = new Client([
258
                'base_uri' => $base_url,
259
            ]);
260
 
261
            $response = $client->request('DELETE', '/v2/meetings/' .  $meeting_id, [
262
                'headers' => [
263
                    'Authorization' => 'Bearer ' .  $token
264
                ]
265
            ]);
266
 
267
 
268
            echo 'StatusCode : ' . $response->getStatusCode();
269
            exit;
270
 
271
            /*
272
 
273
            if (204 == $response->getStatusCode()) {
274
                $data = [
275
                    'success' => true,
276
                    'data' => 'Meeting deleted.'
277
                ];
278
            } else {
279
                $data = [
280
                    'success' => false,
281
                    'data' => $response->getBody()->getContents()
282
                ];
283
            }
284
 
285
 
286
        } else {
287
            $data = [
288
                'success' => false,
289
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
290
            ];
291
 
292
 
293
        }
294
 
295
        return new JsonModel($data);*/
296
    }
297
 
298
    public function participantsAction()
299
    {
300
        $request = $this->getRequest();
301
 
302
       // if($request->isGet()) {
303
 
304
            $meeting_id =  $this->params()->fromRoute('id');
305
 
306
 
307
 
308
            $base_url = $this->config['leaderslinked.zoom.base_url'];
309
            $token = $this->getAccessToken();
310
 
311
            $client = new Client([
312
                'base_uri' => $base_url,
313
            ]);
314
 
315
            $response = $client->request('GET', '/v2/past_meetings/' . $meeting_id , [
316
                'headers' => [
317
                    'Authorization' => 'Bearer '. $token
318
                ]
319
            ]);
320
 
321
            print_r($response->getBody()->getContents());
322
            exit;
323
 
324
            /*
325
            $data = json_decode($response->getBody());
326
            if ( !empty($data) ) {
327
                foreach ( $data->participants as $p ) {
328
                    $name = $p->name;
329
                    $email = $p->user_email;
330
                    echo "Name: $name";
331
                    echo "Email: $email";
332
                }
333
            }
334
 
335
 
336
        } else {
337
            $data = [
338
                'success' => false,
339
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
340
            ];
341
 
342
 
343
        }
344
 
345
        return new JsonModel($data);*/
346
    }
347
 
348
    private function getAccessToken() {
349
 
350
        $api_key = $this->config['leaderslinked.zoom.api_key'];
351
        $api_secret   = $this->config['leaderslinked.zoom.api_secret'];
352
 
353
 
354
        $payload =[
355
            'iss'   => $api_key,
356
            'exp'   => time() + 3600,
357
        ];
358
        return JWT::encode($payload, $api_secret, 'HS256');
359
    }
360
 
361
 
362
 
363
}