TOP000_G4.php
2.42 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
//*****************************************************************************
//*
//* プログラム名:カレンダーAPI接続情報取得(個人)
//* プログラムID:TOP000_G4.php
//* 作成者 :
//*
//*****************************************************************************
header("Content-type: text/html; charset=EUC-JP");
include("include/session_start.inc");
include("include/SessionChk.inc");
include('include/smarty.conf');
include('include/date.inc');
include('./include/Get_GooGleCal.inc');
include('./include/XML_unserialize.php');
include('include/Google_API_Info.inc');
$strDBinc="include/dbcon.inc";
include($strDBinc);
//リフレッシュトークン取得
$strSQL="SELECT * FROM kojin_data_tbl WHERE seq=52 AND syain_cd='$syain_cd'";
$objID = pg_exec($strSQL);
if($objID==false){
echo("SQL実行に失敗しました(SELECT)");
exit;
}
if (pg_numrows($objID) > 0){
$objIDData = pg_fetch_object($objID, 0);
$reflesh_token = $objIDData->memo;
}else{
$reflesh_token = "";
}
//リフレッシュトークンからアクセストークン取得
if($reflesh_token){
$url = "https://accounts.google.com/o/oauth2/token";
$params = array(
'client_id'=>CLIENT_ID,
'client_secret'=>CLIENT_SECRET,
'refresh_token'=>$reflesh_token,
'grant_type'=>'refresh_token'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);
$token_array = json_decode($json, true) ;
if($token_array["access_token"]){
$access_token = $token_array["access_token"];
//アクセストークンを更新
$strSQL="DELETE FROM kojin_data_tbl WHERE seq=51 AND syain_cd='$PHP_SYAIN_CD'";
$objID = pg_exec($strSQL);
$strSQL="INSERT INTO kojin_data_tbl (syain_cd, seq, memo) VALUES ('".$PHP_SYAIN_CD."',51, '".$access_token."')";
$objID = pg_exec($strSQL);
}else{
$access_token = "";
}
}
//カレンダーID取得
$strSQL="SELECT * FROM kojin_data_tbl WHERE seq=50 AND syain_cd='$PHP_SYAIN_CD'";
$objID = pg_exec($strSQL);
if($objID==false){
echo("SQL実行に失敗しました(SELECT)");
exit;
}
if (pg_numrows($objID) > 0){
$objIDData=pg_fetch_object($objID, 0);
$calender_id=$objIDData->memo;
}else{
$calender_id="";
}
//データセット
$RetunData["syain_cd"] = $PHP_SYAIN_CD;
$RetunData["access_token"] = $access_token;
$RetunData["calender_id"] = $calender_id;
echo json_encode($RetunData);
?>