-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.php
More file actions
70 lines (55 loc) · 2.09 KB
/
Copy pathcallback.php
File metadata and controls
70 lines (55 loc) · 2.09 KB
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
63
64
65
66
67
68
69
70
<?php
$client_id = "1544093738";
$client_secret = "90be3b4a84edaa6b462cae997eff7949";
$redirect_uri = "https://praibool-autobot.herokuapp.com/callback.php";
$token = "";
function getToken($code){
global $client_id, $client_secret,$redirect_uri;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.line.me/v1/oauth/accessToken",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=authorization_code&code=".$code."&client_id=".$client_id."&client_secret=".$client_secret."&redirect_uri=".$redirect_uri,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
function getProfile(){
global $token;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.line.me/v1/profile",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer ".$token,
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
$obj = json_decode(getToken($_GET['code']),true);
$token = $obj['access_token'];
$obj_profile = json_decode(getProfile(),true);
?>
<div id="result">
<img height="100px" width="80px" src="<?php echo $obj_profile['pictureUrl'] ?>"><br>
Name : <?php echo $obj_profile['displayName'] ?><br>
statusMessage : <?php echo $obj_profile['statusMessage'] ?><br>
token : <?php echo $token ?><br>
mid : <?php echo $obj_profile['mid'] ?>
</div>
<script>
window.opener.loginCallback("<?php echo $token ?>","<?php echo $obj_profile['displayName'] ?>","<?php echo $obj_profile['mid'] ?>","<?php echo $obj_profile['pictureUrl'] ?>","<?php echo $obj_profile['statusMessage'] ?>");
window.close();
</script>