120 lines
2.6 KiB
PHP
120 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Zoom;
|
|
|
|
use Zoom\Endpoint\Users;
|
|
use GuzzleHttp\Client;
|
|
|
|
class ZoomAPI
|
|
{
|
|
|
|
/**
|
|
* @var null
|
|
*/
|
|
private $apiKey = null;
|
|
|
|
/**
|
|
* @var null
|
|
*/
|
|
private $apiSecret = null;
|
|
|
|
/**
|
|
* @var null
|
|
*/
|
|
private $users = null;
|
|
|
|
protected string $accessToken;
|
|
protected $client;
|
|
/**
|
|
* Retorna uma instância única de uma classe.
|
|
*
|
|
* @staticvar Singleton $instance A instância única dessa classe.
|
|
*
|
|
* @return Singleton A Instância única.
|
|
*/
|
|
public function getInstance()
|
|
{
|
|
static $users = null;
|
|
if (null === $users) {
|
|
$this->users = new Users($this->apiKey, $this->apiSecret);
|
|
}
|
|
|
|
return $users;
|
|
}
|
|
|
|
/**
|
|
* Zoom constructor.
|
|
* @param $apiKey
|
|
* @param $apiSecret
|
|
*/
|
|
public function __construct($apiKey, $apiSecret, $account_id)
|
|
{
|
|
|
|
$this->apiKey = $apiKey;
|
|
|
|
$this->apiSecret = $apiSecret;
|
|
|
|
$client = new Client([
|
|
'headers' => [
|
|
'Authorization' => 'Basic ' . base64_encode($this->apiKey . ':' . $this->apiSecret),
|
|
'Host' => 'zoom.us',
|
|
],
|
|
]);
|
|
$response = $client->request('POST', "https://zoom.us/oauth/token", [
|
|
'form_params' => [
|
|
'grant_type' => 'account_credentials',
|
|
'account_id' => $account_id,
|
|
],
|
|
]);
|
|
$responseBody = json_decode($response->getBody(), true);
|
|
// print_r($responseBody);
|
|
// die;
|
|
$this->accessToken = $responseBody['access_token'];
|
|
// return $responseBody['access_token'];
|
|
}
|
|
public function createMeeting($data)
|
|
{
|
|
$now = date("Y-m-d\TH:i", strtotime(date('Y-m-d H:i:s', time())));
|
|
$postFields = [
|
|
'topic' => $data['title'],
|
|
'type' => 2, // Scheduled meeting
|
|
'start_time' => $now, // Meeting start time in ISO 8601 format
|
|
'duration' => 60 * 12, // Meeting duration in minutes
|
|
'timezone' => 'UTC+07',
|
|
'agenda' => $data['description']
|
|
];
|
|
$this->client = new Client([
|
|
'base_uri' => 'https://api.zoom.us/v2/',
|
|
'headers' => [
|
|
'Authorization' => 'Bearer ' . $this->accessToken,
|
|
'Content-Type' => 'application/json',
|
|
],
|
|
]);
|
|
try {
|
|
$response = $this->client->request('POST', 'users/me/meetings', [
|
|
'json' => $postFields,
|
|
]);
|
|
$res = json_decode($response->getBody(), true);
|
|
return [
|
|
'status' => true,
|
|
'data' => $res,
|
|
];
|
|
} catch (\Throwable $th) {
|
|
return [
|
|
'status' => false,
|
|
'message' => $th->getMessage(),
|
|
];
|
|
}
|
|
}
|
|
/*Functions for management of users*/
|
|
|
|
// public function createUser()
|
|
// {
|
|
// $createAUserArray['action'] = 'create';
|
|
// $createAUserArray['email'] = $_POST['email'];
|
|
// $createAUserArray['user_info'] = $_POST['user_info'];
|
|
|
|
// return $this->users->create($createAUserArray);
|
|
// }
|
|
}
|