Proyectos de Subversion LeadersLinked - Services

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 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
 
12
use Laminas\Mvc\Controller\AbstractActionController;
13
use Laminas\Log\LoggerInterface;
14
use Laminas\View\Model\JsonModel;
15
use LeadersLinked\Library\Zoom;
16
 
17
class ZoomController extends AbstractActionController
18
{
19
    /**
20
     *
21
     * @var \Laminas\Db\Adapter\AdapterInterface
22
     */
23
    private $adapter;
24
 
25
    /**
26
     *
27
     * @var \LeadersLinked\Cache\CacheInterface
28
     */
29
    private $cache;
30
 
31
 
32
    /**
33
     *
34
     * @var \Laminas\Log\LoggerInterface
35
     */
36
    private $logger;
37
 
38
    /**
39
     *
40
     * @var array
41
     */
42
    private $config;
43
 
44
 
45
    /**
46
     *
47
     * @var \Laminas\Mvc\I18n\Translator
48
     */
49
    private $translator;
50
 
51
 
52
    /**
53
     *
54
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
55
     * @param \LeadersLinked\Cache\CacheInterface $cache
56
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
57
     * @param array $config
58
     * @param \Laminas\Mvc\I18n\Translator $translator
59
     */
60
    public function __construct($adapter, $cache, $logger, $config, $translator)
61
    {
62
        $this->adapter      = $adapter;
63
        $this->cache        = $cache;
64
        $this->logger       = $logger;
65
        $this->config       = $config;
66
        $this->translator   = $translator;
67
    }
68
 
69
 
70
    public function indexAction()
71
    {
72
 
73
 
74
        $data = [
75
            'success' => false,
76
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
77
        ];
78
 
79
 
80
 
81
        return new JsonModel($data);
82
    }
83
 
84
    public function addAction()
85
    {
86
 
87
        $token = 'EAAJaDxnm8uIBAGYjnYpOvjzm1BXbBgTtqfwn4YbagqIBGxfpWVZBObWtcnvfTJB6hMfHLWZBgG7dQ2O2UYMqZALYSLIQZC8swoNsHNYe3AMBkOjkt7YZBuIfXe22yyTgUZCBzGlsjbs0f72nNDvMlGNQlkCYNi3ZCDdXH61z9nW9xxUcdAnhk6M';
88
        $token = 'EAAJaDxnm8uIBAF3XfBml8yh9PqHOfO0UcwYALZAmoZCSPx6IkNZCRaVQaSWJfQALBqaRZCMziTddfvKgiVs1jwftg2sMyZBGixRTSDcXfvOv3nO4gZA2pCyruxa5iA1ZB01C83o2ZAg1Lnb07jeGF2C4d1Tauu3ZB9sZCJTkY4jMPt1Gnx8tpm5MAd';
89
        $client = new Client([
90
 
91
            'base_uri' => 'https://graph.facebook.com/v15.0',
92
        ]);
93
 
94
        //$to = '584244343638';
95
        //$to = '59898137899';
96
        $to = '584122788242';
97
 
98
        $response = $client->request('POST', '/111473331819706/messages', [
99
            'headers' => [
100
                'Authorization' => 'Bearer ' . $token
101
            ],
102
            'json' => [
103
                'messaging_product' => 'whatsapp',
104
                'recipient_type' => 'individual',
105
                'to' => $to,
106
 
107
                'type' => 'text',
108
                'text' => [
109
                    'preview_url' =>  false,
110
                    'body' => 'MESSAGE_CONTENT'
111
                ]
112
                /*
113
                'type' => 'template',
114
                'template' => [
115
                    'name' => 'hello_world',
116
                    'language' => [
117
                        'code' => 'en_US'
118
                    ]
119
                ] */
120
            ],
121
        ]);
122
 
123
 
124
    }
125
 
126
    public function listingAction()
127
    {
128
        $request = $this->getRequest();
129
 
130
        if($request->isGet()) {
131
 
132
 
133
            $zoom = new Zoom($this->adapter, $this->config, $this->cache);
134
            $response =  $zoom->getOAuthAccessToken();
135
 
136
 
137
 
138
            if($response['success']) {
139
                $next_page_token = $this->params()->fromRoute('next_page');
140
 
141
 
142
                $access_token = $response['data'];
143
                $response = $zoom->getMeetings($access_token, $next_page_token) ;
144
                return new JsonModel($response);
145
 
146
 
147
            } else {
148
               return new JsonModel($response);
149
            }
150
 
151
 
152
 
153
 
154
        } else {
155
            $data = [
156
                'success' => false,
157
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
158
            ];
159
 
160
 
161
        }
162
 
163
        return new JsonModel($data);
164
    }
165
 
166
    public function  deleteAction()
167
    {
168
        $request = $this->getRequest();
169
 
170
        //if($request->isPost()) {
171
 
172
            $meeting_id =  $this->params()->fromRoute('id');
173
 
174
 
175
 
176
            $base_url = $this->config['leaderslinked.zoom.base_url'];
177
            $token = $this->getAccessToken();
178
 
179
            $client = new Client([
180
                'base_uri' => $base_url,
181
            ]);
182
 
183
            $response = $client->request('DELETE', '/v2/meetings/' .  $meeting_id, [
184
                'headers' => [
185
                    'Authorization' => 'Bearer ' .  $token
186
                ]
187
            ]);
188
 
189
 
190
            echo 'StatusCode : ' . $response->getStatusCode();
191
            exit;
192
 
193
            /*
194
 
195
            if (204 == $response->getStatusCode()) {
196
                $data = [
197
                    'success' => true,
198
                    'data' => 'Meeting deleted.'
199
                ];
200
            } else {
201
                $data = [
202
                    'success' => false,
203
                    'data' => $response->getBody()->getContents()
204
                ];
205
            }
206
 
207
 
208
        } else {
209
            $data = [
210
                'success' => false,
211
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
212
            ];
213
 
214
 
215
        }
216
 
217
        return new JsonModel($data);*/
218
    }
219
 
220
    public function participantsAction()
221
    {
222
        $request = $this->getRequest();
223
 
224
       // if($request->isGet()) {
225
 
226
            $meeting_id =  $this->params()->fromRoute('id');
227
 
228
 
229
 
230
            $base_url = $this->config['leaderslinked.zoom.base_url'];
231
            $token = $this->getAccessToken();
232
 
233
            $client = new Client([
234
                'base_uri' => $base_url,
235
            ]);
236
 
237
            $response = $client->request('GET', '/v2/past_meetings/' . $meeting_id , [
238
                'headers' => [
239
                    'Authorization' => 'Bearer '. $token
240
                ]
241
            ]);
242
 
243
    }
244
 
245
 
246
 
247
 
248
 
249
}