Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5277 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4131 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
 
5
namespace LeadersLinked\Library;
6
 
7
 
8
use \Firebase\JWT\JWT;
9
use GuzzleHttp\Client;
10
use Laminas\Db\Adapter\Adapter;
11
use LeadersLinked\Model\ZoomMeeting;
12
 
13
 
14
class Zoom
15
{
16
    /**
17
     *
18
     * @var Adapter
19
     */
20
    private $adapter;
21
 
22
 
23
    /**
24
     *
25
     * @var array
26
     */
27
    private $config;
28
 
29
 
30
    /**
31
     *
32
     * @param Adapter $adapter
33
     * @param array config
34
     */
35
    public function __construct($adapter, $config)
36
    {
37
        $this->adapter = $adapter;
38
        $this->config = $config;
39
    }
40
 
41
 
42
 
43
    public function add($topic, $agenda, $type, $start_time, $duration, $timezone, $password)
44
    {
45
 
46
        $base_url = $this->config['leaderslinked.zoom.base_url'];
47
        $token = $this->getAccessToken();
48
 
49
 
50
        $client = new Client([
51
            'base_uri' => $base_url,
52
        ]);
53
 
54
 
55
 
56
        if($type == ZoomMeeting::TYPE_SCHEDULED) {
57
            $json = [
58
                'topic' => $topic,
59
                'agenda' => $agenda,
60
                'type' => 2,
61
                'start_time' => $start_time,
62
                'duration' => $duration,
63
                'password' => $password,
64
                'timezone' => $timezone,
65
            ];
66
        } else {
67
            $json = [
68
                'topic' => $topic,
69
                'agenda' => $agenda,
70
                'type' => 1,
71
                'duration' => $duration,
72
                'password' => $password,
73
                'timezone' => $timezone,
74
                'settings' => [
75
                    'participant_video'=> 'true',
76
                    'auto_recording' => 'none',
77
                ]
78
            ];
79
        }
80
 
81
 
82
        $request = [
83
            'headers' => [
84
                'Authorization' => 'Bearer ' . $token
85
            ],
86
            'json' => $json,
87
        ];
88
 
89
 
90
        $response = $client->request('POST', '/v2/users/me/meetings', $request );
91
 
92
        $statusCode = $response->getStatusCode() ;
93
 
94
        if($statusCode >= 200 && $statusCode <= 300) {
95
            $data = json_decode($response->getBody()->getContents());
96
 
97
 
98
            return [
99
                'success' => true,
100
                'data' => [
101
                    'id' => $data->id,
102
                    'uuid' => $data->uuid,
103
                    'join_url' => $data->join_url,
104
                    'password' => $data->password,
105
                ]
106
 
107
            ];
108
 
109
 
110
        } else {
111
            return [
112
                'success' => false,
113
                'data' => $response->getStatusCode()
114
            ];
115
        }
116
 
117
 
118
 
119
    }
120
 
121
 
122
    private function getAccessToken() {
123
 
124
        $api_key = $this->config['leaderslinked.zoom.api_key'];
125
        $api_secret   = $this->config['leaderslinked.zoom.api_secret'];
126
 
127
 
128
        $payload =[
129
            'iss'   => $api_key,
130
            'exp'   => time() + 3600,
131
        ];
132
        return JWT::encode($payload, $api_secret, 'HS256');
133
    }
134
 
135
 
136
}