Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4124 | Ir a la última revisión | | 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
 
17
 
18
 
19
class ZoomController extends AbstractActionController
20
{
21
    /**
22
     *
23
     * @var AdapterInterface
24
     */
25
    private $adapter;
26
 
27
 
28
    /**
29
     *
30
     * @var AbstractAdapter
31
     */
32
    private $cache;
33
 
34
    /**
35
     *
36
     * @var  LoggerInterface
37
     */
38
    private $logger;
39
 
40
    /**
41
     *
42
     * @var array
43
     */
44
    private $config;
45
 
46
 
47
 
48
 
49
    /**
50
     *
51
     * @param AdapterInterface $adapter
52
     * @param AbstractAdapter $cache
53
     * @param LoggerInterface $logger
54
     * @param array $config
55
     */
56
    public function __construct($adapter, $cache , $logger, $config)
57
    {
58
        $this->adapter      = $adapter;
59
        $this->cache        = $cache;
60
        $this->logger       = $logger;
61
        $this->config       = $config;
62
    }
63
 
64
 
65
    public function indexAction()
66
    {
67
 
68
        $data = [
69
            'success' => false,
70
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
71
        ];
72
 
73
 
74
        return new JsonModel($data);
75
    }
76
 
77
    public function createAction()
78
    {
79
 
80
 
81
        $request = $this->getRequest();
82
 
83
       // if($request->isPost()) {
84
 
85
 
86
            $base_url = $this->config['leaderslinked.zoom.base_url'];
87
            $token = $this->getAccessToken();
88
 
89
 
90
            $client = new Client([
91
 
92
                'base_uri' => $base_url,
93
            ]);
94
 
95
            $response = $client->request('POST', '/v2/users/me/meetings', [
96
                'headers' => [
97
                    'Authorization' => 'Bearer ' . $token
98
                ],
99
                'json' => [
100
                    'topic' => 'Let s Learn WordPress',
101
                    'type' => 2,
102
                    'start_time' => '2023-01-30T20:30:00',
103
                    'duration' => '30', // 30 mins
104
                    'password' => '123456',
105
                    'timezone' => 'America/Caracas',
106
                ],
107
            ]);
108
 
109
print_r($response->getBody()->getContents()); exit;
110
 
111
 
112
            $data = json_decode($response->getBody());
113
            echo "Join URL: ". $data->join_url;
114
            echo "<br>";
115
            echo "Meeting Password: ". $data->password;
116
 
117
          /*
118
        } else {
119
            $data = [
120
                'success' => false,
121
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
122
            ];
123
 
124
            return new JsonModel($data);
125
        }
126
 
127
        return new JsonModel($data);*/
128
 
129
    }
130
 
131
    public function listingAction()
132
    {
133
        $request = $this->getRequest();
134
 
135
        //if($request->isGet()) {
136
 
137
            $next_page_token = $this->params()->fromRoute('next_page');
138
 
139
 
140
            $base_url = $this->config['leaderslinked.zoom.base_url'];
141
            $token = $this->getAccessToken();
142
 
143
            $client = new Client([
144
 
145
                'base_uri' => $base_url,
146
            ]);
147
 
148
            $request = [
149
                'headers' => [
150
                    'Authorization' => 'Bearer '. $token
151
                ],
152
                'type' => 'scheduled'
153
            ];
154
 
155
            if (!empty($next_page_token)) {
156
                $request['query'] = ['next_page_token' => $next_page_token];
157
            }
158
 
159
            $response = $client->request('GET', '/v2/users/me/meetings', $request);
160
 
161
echo '<pre>';
162
print_r(json_decode($response->getBody()->getContents()));
163
echo '</pre>';
164
exit;
165
 
166
            $data = json_decode($response->getBody());
167
 
168
            if ( !empty($data) ) {
169
                foreach ( $data->meetings as $d ) {
170
                    $topic = $d->topic;
171
                    $join_url = $d->join_url;
172
                    echo "<h3>Topic: $topic</h3>";
173
                    echo "Join URL: $join_url";
174
                }
175
 
176
                if ( !empty($data->next_page_token) ) {
177
                    list_meetings($data->next_page_token);
178
                }
179
            }
180
 
181
           /*
182
        } else {
183
            $data = [
184
                'success' => false,
185
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
186
            ];
187
 
188
 
189
        }
190
 
191
        return new JsonModel($data);*/
192
    }
193
 
194
    public function  deleteAction()
195
    {
196
        $request = $this->getRequest();
197
 
198
        //if($request->isPost()) {
199
 
200
            $meeting_id =  $this->params()->fromRoute('id');
201
 
202
 
203
 
204
            $base_url = $this->config['leaderslinked.zoom.base_url'];
205
            $token = $this->getAccessToken();
206
 
207
            $client = new Client([
208
                'base_uri' => $base_url,
209
            ]);
210
 
211
            $response = $client->request('DELETE', '/v2/meetings/' .  $meeting_id, [
212
                'headers' => [
213
                    'Authorization' => 'Bearer ' .  $token
214
                ]
215
            ]);
216
 
217
 
218
            echo 'StatusCode : ' . $response->getStatusCode();
219
            exit;
220
 
221
            /*
222
 
223
            if (204 == $response->getStatusCode()) {
224
                $data = [
225
                    'success' => true,
226
                    'data' => 'Meeting deleted.'
227
                ];
228
            } else {
229
                $data = [
230
                    'success' => false,
231
                    'data' => $response->getBody()->getContents()
232
                ];
233
            }
234
 
235
 
236
        } else {
237
            $data = [
238
                'success' => false,
239
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
240
            ];
241
 
242
 
243
        }
244
 
245
        return new JsonModel($data);*/
246
    }
247
 
248
    public function participantsAction()
249
    {
250
        $request = $this->getRequest();
251
 
252
       // if($request->isGet()) {
253
 
254
            $meeting_id =  $this->params()->fromRoute('id');
255
 
256
 
257
 
258
            $base_url = $this->config['leaderslinked.zoom.base_url'];
259
            $token = $this->getAccessToken();
260
 
261
            $client = new Client([
262
                'base_uri' => $base_url,
263
            ]);
264
 
265
            $response = $client->request('GET', '/v2/past_meetings/' . $meeting_id , [
266
                'headers' => [
267
                    'Authorization' => 'Bearer '. $token
268
                ]
269
            ]);
270
 
271
            print_r($response->getBody()->getContents());
272
            exit;
273
 
274
            /*
275
            $data = json_decode($response->getBody());
276
            if ( !empty($data) ) {
277
                foreach ( $data->participants as $p ) {
278
                    $name = $p->name;
279
                    $email = $p->user_email;
280
                    echo "Name: $name";
281
                    echo "Email: $email";
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
    private function getAccessToken() {
299
 
300
        $api_key = $this->config['leaderslinked.zoom.api_key'];
301
        $api_secret   = $this->config['leaderslinked.zoom.api_secret'];
302
 
303
 
304
        $payload =[
305
            'iss'   => $api_key,
306
            'exp'   => time() + 3600,
307
        ];
308
        return JWT::encode($payload, $api_secret, 'HS256');
309
    }
310
 
311
 
312
 
313
}