Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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