-
Notifications
You must be signed in to change notification settings - Fork 34
/
callback.php
62 lines (59 loc) · 2.13 KB
/
callback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once SMS_PLUGIN_DIR. '/lib/vendor/autoload.php';
$client = new GuzzleHttp\Client(['base_uri' => 'https://zoom.us']);
$CLIENT_ID = get_option('smgt_virtual_classroom_client_id');
$CLIENT_SECRET = get_option('smgt_virtual_classroom_client_secret_id');
$REDIRECT_URI = site_url().'?page=callback';
if(empty(get_option('smgt_virtual_classroom_access_token')) OR get_option('smgt_virtual_classroom_access_token'))
{
$response = $client->request('POST', '/oauth/token', [
"headers" => [
"Authorization" => "Basic ". base64_encode($CLIENT_ID.':'.$CLIENT_SECRET)
],
'form_params' => [
"grant_type" => "authorization_code",
"code" => $_GET['code'],
"redirect_uri" => $REDIRECT_URI
],
]);
$token = $response->getBody()->getContents();
update_option( 'smgt_virtual_classroom_access_token', $token );
$site_url=site_url().'/wp-admin/admin.php?page=smgt_virtual_classroom&tab=meeting_list&message=4';
// $site_url= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header('Location:'.$site_url);
// wp_redirect($site_url);
// exit();
}
else
{
$get_token = get_option('smgt_virtual_classroom_access_token');
$token_decode = json_decode($get_token);
$refresh_token = $token_decode->refresh_token;
$response = $client->request('POST', '/oauth/token', [
"headers" => [
"Authorization" => "Basic ". base64_encode($CLIENT_ID.':'.$CLIENT_SECRET)
],
"query" => [
"grant_type" => "refresh_token",
"refresh_token" => $refresh_token
],
]);
$token = $response->getBody()->getContents();
update_option( 'smgt_virtual_classroom_access_token', $token );
}
// $redirect_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
// if (!headers_sent())
// {
// header('Location: '.$redirect_url);
// }
// else
// {
// echo '<script type="text/javascript">';
// echo 'window.location.href="'.$redirect_url.'";';
// echo '</script>';
// }
// $url="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
// apply_filters( 'wp_redirect', $url );
// wp_redirect ($url);
// die();
?>