| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
|
|
6 |
Copyright (C) 2015~2025 Min-Jhin,Chen
|
|
|
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
存取Amazon服務的類別
|
|
|
29 |
備註:
|
|
|
30 |
建議改用 odrive 來跟雲端硬碟互動,參考資料https://docs.odrive.com/v1.0/docs.
|
|
|
31 |
*/
|
|
|
32 |
class amazon{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#可省略參數:
|
|
|
45 |
#無.
|
|
|
46 |
#參考資料:
|
|
|
47 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
48 |
#備註:
|
|
|
49 |
#無.
|
|
|
50 |
*/
|
|
|
51 |
public function __call($method,$arguments){
|
|
|
52 |
|
|
|
53 |
#取得當前執行的函式
|
|
|
54 |
$result["function"]=__FUNCTION__;
|
|
|
55 |
|
|
|
56 |
#設置執行不正常
|
|
|
57 |
$result["status"]="false";
|
|
|
58 |
|
|
|
59 |
#設置執行錯誤
|
|
|
60 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
61 |
|
|
|
62 |
#設置所丟入的參數
|
|
|
63 |
$result["error"][]=$arguments;
|
|
|
64 |
|
|
|
65 |
#回傳結果
|
|
|
66 |
return $result;
|
|
|
67 |
|
|
|
68 |
}#function __call end
|
|
|
69 |
|
|
|
70 |
/*
|
|
|
71 |
#函式說明:
|
|
|
72 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
73 |
#回傳結果:
|
|
|
74 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
75 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
76 |
#$result["function"],當前執行的函式名稱.
|
|
|
77 |
#必填參數:
|
|
|
78 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
79 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
80 |
#可省略參數:
|
|
|
81 |
#無.
|
|
|
82 |
#參考資料:
|
|
|
83 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
84 |
#備註:
|
|
|
85 |
#無.
|
|
|
86 |
*/
|
|
|
87 |
public static function __callStatic($method,$arguments){
|
|
|
88 |
|
|
|
89 |
#取得當前執行的函式
|
|
|
90 |
$result["function"]=__FUNCTION__;
|
|
|
91 |
|
|
|
92 |
#設置執行不正常
|
|
|
93 |
$result["status"]="false";
|
|
|
94 |
|
|
|
95 |
#設置執行錯誤
|
|
|
96 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
97 |
|
|
|
98 |
#設置所丟入的參數
|
|
|
99 |
$result["error"][]=$arguments;
|
|
|
100 |
|
|
|
101 |
#回傳結果
|
|
|
102 |
return $result;
|
|
|
103 |
|
|
|
104 |
}#function __callStatic end
|
|
|
105 |
|
|
|
106 |
/*
|
|
|
107 |
#函式說明:
|
|
|
108 |
#用 amazon 的登入機制來認證,登入成功後轉址到特定頁面.
|
|
|
109 |
#回傳結果:
|
|
|
110 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
111 |
#$result["error"],錯誤訊息
|
|
|
112 |
#$result["content"],語法
|
|
|
113 |
#$result["function"],當前執行的函數名稱
|
|
|
114 |
#必填參數:
|
|
|
115 |
#$conf["clientId"],字串,login app 用戶端的 id.
|
|
|
116 |
$conf["clientId"]="";
|
|
|
117 |
#可省略參數:
|
|
|
118 |
#$conf["redirect_uri"],字串,認證完要轉址到哪哩,預設為$_SERVER["REQUEST_URI"].
|
|
|
119 |
#$conf["redirect_uri"]="";
|
|
|
120 |
#可省略參數:
|
|
|
121 |
#無
|
|
|
122 |
#參考資料:
|
|
|
123 |
#http://login.amazon.com/website
|
|
|
124 |
#http://login.amazon.com/documentation
|
|
|
125 |
#https://images-na.ssl-images-amazon.com/images/G/01/lwa/dev/docs/website-developer-guide._TTH_.pdf
|
|
|
126 |
#https://sellercentral.amazon.com/gp/homepage.html
|
|
|
127 |
#備註:
|
|
|
128 |
#好像壞了,請檢查.
|
|
|
129 |
*/
|
|
|
130 |
public static function loginWithAmazonAccount(&$conf){
|
|
|
131 |
|
|
|
132 |
#初始化要回傳的結果
|
|
|
133 |
$result=array();
|
|
|
134 |
|
|
|
135 |
#取得當前執行的函數名稱
|
|
|
136 |
$result["function"]=__FUNCTION__;
|
|
|
137 |
|
|
|
138 |
#初始化要回傳的語法
|
|
|
139 |
$result["content"]="";
|
|
|
140 |
|
|
|
141 |
#如果沒有參數
|
|
|
142 |
if(func_num_args()==0){
|
|
|
143 |
|
|
|
144 |
#設置執行失敗
|
|
|
145 |
$result["status"]="false";
|
|
|
146 |
|
|
|
147 |
#設置執行錯誤訊息
|
|
|
148 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
149 |
|
|
|
150 |
#回傳結果
|
|
|
151 |
return $result;
|
|
|
152 |
|
|
|
153 |
}#if end
|
|
|
154 |
|
|
|
155 |
#取得參數
|
|
|
156 |
$result["argu"]=$conf;
|
|
|
157 |
|
|
|
158 |
#如果 $conf 不為陣列
|
|
|
159 |
if(gettype($conf)!=="array"){
|
|
|
160 |
|
|
|
161 |
#設置執行失敗
|
|
|
162 |
$result["status"]="false";
|
|
|
163 |
|
|
|
164 |
#設置執行錯誤訊息
|
|
|
165 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
166 |
|
|
|
167 |
#如果傳入的參數為 null
|
|
|
168 |
if($conf===null){
|
|
|
169 |
|
|
|
170 |
#設置執行錯誤訊息
|
|
|
171 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
172 |
|
|
|
173 |
}#if end
|
|
|
174 |
|
|
|
175 |
#回傳結果
|
|
|
176 |
return $result;
|
|
|
177 |
|
|
|
178 |
}#if end
|
|
|
179 |
|
|
|
180 |
#檢查參數
|
|
|
181 |
#函式說明:
|
|
|
182 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
183 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
184 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
185 |
#$result["function"],當前執行的函式名稱.
|
|
|
186 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
187 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
188 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
189 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
190 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
191 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
192 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
193 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
194 |
#必填寫的參數:
|
|
|
195 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
196 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
197 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
198 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("clientId");
|
|
|
199 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
200 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
201 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
202 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
203 |
#可以省略的參數:
|
|
|
204 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
205 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
206 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
207 |
#$conf["canNotBeEmpty"]=array();
|
|
|
208 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
209 |
#$conf["canBeEmpty"]=array();
|
|
|
210 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
211 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
212 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
213 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("redirect_uri");
|
|
|
214 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
215 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
216 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
217 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["REQUEST_URI"]);
|
|
|
218 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
219 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
220 |
#參考資料來源:
|
|
|
221 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
222 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
223 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
224 |
|
|
|
225 |
#如果參數檢查失敗
|
|
|
226 |
if($checkArguments["status"]==="false"){
|
|
|
227 |
|
|
|
228 |
#設置執行不正常
|
|
|
229 |
$result["status"]="false";
|
|
|
230 |
|
|
|
231 |
#設置執行錯誤
|
|
|
232 |
$result["error"]=$checkArguments;
|
|
|
233 |
|
|
|
234 |
#回傳結果
|
|
|
235 |
return $result;
|
|
|
236 |
|
|
|
237 |
}#if end
|
|
|
238 |
|
|
|
239 |
#如果參數檢查不通過
|
|
|
240 |
if($checkArguments["passed"]==="false"){
|
|
|
241 |
|
|
|
242 |
#設置執行不正常
|
|
|
243 |
$result["status"]="false";
|
|
|
244 |
|
|
|
245 |
#設置執行錯誤
|
|
|
246 |
$result["error"]=$checkArguments;
|
|
|
247 |
|
|
|
248 |
#回傳結果
|
|
|
249 |
return $result;
|
|
|
250 |
|
|
|
251 |
}#if end
|
|
|
252 |
|
|
|
253 |
#設置登入按鈕
|
|
|
254 |
$result["content"]=$result["content"]."
|
|
|
255 |
<!-- login button -->
|
|
|
256 |
<div id=\"LoginWithAmazon\">
|
|
|
257 |
<img
|
|
|
258 |
border=\"0\"
|
|
|
259 |
alt=\"Login with Amazon\"
|
|
|
260 |
src=\"https://images-na.ssl-images-amazon.com/images/G/01/lwa/btnLWA_gold_156x32.png\"
|
|
|
261 |
width=\"156\" height=\"32\"
|
|
|
262 |
/img>
|
|
|
263 |
</div>
|
|
|
264 |
";
|
|
|
265 |
|
|
|
266 |
#設置登出按鈕
|
|
|
267 |
$result["content"]=$result["content"]."
|
|
|
268 |
<!-- logout div -->
|
|
|
269 |
<div id=\"Logout\">Logout</div>
|
|
|
270 |
";
|
|
|
271 |
|
|
|
272 |
#設置取得資訊的區塊
|
|
|
273 |
$result["content"]=$result["content"]."<div id=\"amazon-root\"></div>";
|
|
|
274 |
|
|
|
275 |
#設置嵌入 amazon login js jdk 與登入、登出事件的js語法
|
|
|
276 |
$result["content"]=$result["content"]."
|
|
|
277 |
<script>
|
|
|
278 |
//當 amazon login sdk 載入完畢後在設置 app client id
|
|
|
279 |
window.onAmazonLoginReady = function()
|
|
|
280 |
{
|
|
|
281 |
amazon.Login.setClientId('".$conf["clientId"]."');
|
|
|
282 |
};
|
|
|
283 |
|
|
|
284 |
//優先載入amazon login sdk
|
|
|
285 |
(function(d)
|
|
|
286 |
{
|
|
|
287 |
var a = d.createElement('script'); a.type = 'text/javascript';
|
|
|
288 |
a.async = true; a.id = 'amazon-login-sdk';
|
|
|
289 |
a.src = 'https://api-cdn.amazon.com/sdk/login1.js';
|
|
|
290 |
d.getElementById('amazon-root').appendChild(a);
|
|
|
291 |
})(document);
|
|
|
292 |
|
|
|
293 |
//登入與取得個資
|
|
|
294 |
document.getElementById('LoginWithAmazon').onclick = function()
|
|
|
295 |
{
|
|
|
296 |
options = { scope : 'profile' };
|
|
|
297 |
amazon.Login.authorize(options, '".$conf["redirect_uri"]."');
|
|
|
298 |
return false;
|
|
|
299 |
};
|
|
|
300 |
|
|
|
301 |
//登出事件
|
|
|
302 |
document.getElementById('Logout').onclick = function()
|
|
|
303 |
{
|
|
|
304 |
amazon.Login.logout();
|
|
|
305 |
};
|
|
|
306 |
</script>
|
|
|
307 |
";
|
|
|
308 |
|
|
|
309 |
#設置執行正常
|
|
|
310 |
$result["status"]="true";
|
|
|
311 |
|
|
|
312 |
#回傳結果
|
|
|
313 |
return $result;
|
|
|
314 |
|
|
|
315 |
}#function loginWithAmazonAccount end
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
/*
|
|
|
320 |
#函式說明:
|
|
|
321 |
#解析從 amazon 認證過後的 token 與相關資訊,並將結果儲存到$_SESSION["amazon::parseToken"]
|
|
|
322 |
#回傳結果:
|
|
|
323 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
324 |
#$result["founded"],是否有找到必備的token.
|
|
|
325 |
#$result["error"],錯誤訊息
|
|
|
326 |
#$result["content"],解析後的結果
|
|
|
327 |
#$result["function"],當前執行的函數名稱
|
|
|
328 |
#必填參數:
|
|
|
329 |
#無.
|
|
|
330 |
#可省略參數:
|
|
|
331 |
#無.
|
|
|
332 |
#參考資料:
|
|
|
333 |
#無.
|
|
|
334 |
#備註:
|
|
|
335 |
#請勿跟authenticateToAC()用在同一個頁面.
|
|
|
336 |
*/
|
|
|
337 |
public static function parseToken(){
|
|
|
338 |
|
|
|
339 |
#初始化要回傳的結果
|
|
|
340 |
$result=array();
|
|
|
341 |
|
|
|
342 |
#取得當前執行的函數名稱
|
|
|
343 |
$result["function"]=__FUNCTION__;
|
|
|
344 |
|
|
|
345 |
#接收變數
|
|
|
346 |
#涵式說明:
|
|
|
347 |
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
|
|
|
348 |
#回傳的結果:
|
|
|
349 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
350 |
#$result["error"],錯誤訊息陣列.
|
|
|
351 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
352 |
#$result["warning"],警告訊息陣列.
|
|
|
353 |
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
|
|
|
354 |
#$result["lostVarName"],沒有皆收到的變數名稱陣列
|
|
|
355 |
#$result["inputDataContent"],所接收的參數陣列.
|
|
|
356 |
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
|
|
|
357 |
#$result["inputDataCount"],從表單總共接收到幾個元素.
|
|
|
358 |
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
|
|
|
359 |
#必填的參數:
|
|
|
360 |
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
|
|
|
361 |
$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="GET";
|
|
|
362 |
#可省略的參數:
|
|
|
363 |
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
|
|
|
364 |
$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";
|
|
|
365 |
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
|
|
|
366 |
#$conf["limitPrePage"]=array("");
|
|
|
367 |
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
|
|
|
368 |
#$conf["transferLocation"]="";
|
|
|
369 |
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
|
|
|
370 |
#$conf["ignore"]=array();
|
|
|
371 |
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
|
|
|
372 |
#$conf["correctCharacter"]="false";
|
|
|
373 |
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
|
|
|
374 |
$conf["form::responseMultiInputDataSecurityEnhance"]["checkedVarName"]=array("access_token");
|
|
|
375 |
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
|
|
|
376 |
#$conf["canBeEmptyString"]="false";
|
|
|
377 |
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
|
|
|
378 |
#$conf["sessionNameArray"]=array();
|
|
|
379 |
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
|
|
|
380 |
#$conf["unsetSessionArray"]=array();
|
|
|
381 |
#參考資料來源:
|
|
|
382 |
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
|
|
|
383 |
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
|
|
|
384 |
#備註:
|
|
|
385 |
#表單變數的名稱若含有「.」,則會變成「-」。
|
|
|
386 |
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
387 |
unset($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
388 |
|
|
|
389 |
#如果接收變數失敗
|
|
|
390 |
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
|
|
|
391 |
|
|
|
392 |
#設置執行不正常
|
|
|
393 |
$result["status"]="false";
|
|
|
394 |
|
|
|
395 |
#設置執行錯誤
|
|
|
396 |
$result["error"]=$responseMultiInputDataSecurityEnhance;
|
|
|
397 |
|
|
|
398 |
#回傳結果
|
|
|
399 |
return $result;
|
|
|
400 |
|
|
|
401 |
}#if end
|
|
|
402 |
|
|
|
403 |
#如果沒有接收到一定要的變數
|
|
|
404 |
if($responseMultiInputDataSecurityEnhance["passed"]==="false"){
|
|
|
405 |
|
|
|
406 |
#嘗試取得 session 變數 amazon::parseToken
|
|
|
407 |
#函式說明:
|
|
|
408 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
409 |
#回傳的結果:
|
|
|
410 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
411 |
#$result["error"],錯誤訊息.
|
|
|
412 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
413 |
#$result["content"],取得的變數內容.
|
|
|
414 |
#$result["function"],當前執行的函數名稱.
|
|
|
415 |
#必填的參數:
|
|
|
416 |
#$conf["sessionVarName"],字串,要取得內容的session變數名稱
|
|
|
417 |
$conf["session::getSessionValue"]["sessionVarName"]="amazon::parseToken";
|
|
|
418 |
#可省略的參數:
|
|
|
419 |
#$conf["unsetSessionVar"],字串,代表要卸除session變數,預設為"false"不卸除,"true"代表要卸除.
|
|
|
420 |
$conf["session::getSessionValue"]["unsetSessionVar"]="true";
|
|
|
421 |
#參考資料:
|
|
|
422 |
#call-time-pass-by-reference-easy-fix-available=>http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
423 |
#可變變數=>http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
424 |
#卸除參考的原始變數=>http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
425 |
$getSessionValue=session::getSessionValue($conf["session::getSessionValue"]);
|
|
|
426 |
unset($conf["session::getSessionValue"]);
|
|
|
427 |
|
|
|
428 |
#如果嘗試取得session變數失敗
|
|
|
429 |
if($getSessionValue["status"]==="false"){
|
|
|
430 |
|
|
|
431 |
#設置執行不正常
|
|
|
432 |
$result["status"]="false";
|
|
|
433 |
|
|
|
434 |
#設置執行錯誤
|
|
|
435 |
$result["error"]=$getSessionValue;
|
|
|
436 |
|
|
|
437 |
#回傳結果
|
|
|
438 |
return $result;
|
|
|
439 |
|
|
|
440 |
}#if end
|
|
|
441 |
|
|
|
442 |
#如果取得到session變數
|
|
|
443 |
if($getSessionValue["founded"]==="true"){
|
|
|
444 |
|
|
|
445 |
#取得 session 變數值
|
|
|
446 |
$result["content"]=$getSessionValue["content"];
|
|
|
447 |
|
|
|
448 |
#設置執行正常
|
|
|
449 |
$result["status"]="true";
|
|
|
450 |
|
|
|
451 |
#設置有取得到token
|
|
|
452 |
$result["founded"]="true";
|
|
|
453 |
|
|
|
454 |
#回傳結果
|
|
|
455 |
return $result;
|
|
|
456 |
|
|
|
457 |
}#if end
|
|
|
458 |
|
|
|
459 |
#反之
|
|
|
460 |
else{
|
|
|
461 |
|
|
|
462 |
#設置執行正常
|
|
|
463 |
$result["status"]="true";
|
|
|
464 |
|
|
|
465 |
#設置沒有取得到token
|
|
|
466 |
$result["founded"]="false";
|
|
|
467 |
|
|
|
468 |
#回傳結果
|
|
|
469 |
return $result;
|
|
|
470 |
|
|
|
471 |
}#else end
|
|
|
472 |
|
|
|
473 |
}#if end
|
|
|
474 |
|
|
|
475 |
#將網址的GET變數去掉
|
|
|
476 |
#函式說明:
|
|
|
477 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
478 |
#回傳結果:
|
|
|
479 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
480 |
#$result["error"],錯誤訊息陣列.
|
|
|
481 |
#$result["warning"],警告訊息鎮列.
|
|
|
482 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
483 |
#$result["function"],當前執行的函數名稱.
|
|
|
484 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
485 |
#$result["content"],處理好的的字串內容.
|
|
|
486 |
#必填的參數:
|
|
|
487 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$_SERVER["REQUEST_URI"];#要處理的字串.
|
|
|
488 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]="?";#特定字串.
|
|
|
489 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
490 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
491 |
|
|
|
492 |
#如果濾掉get變數失敗
|
|
|
493 |
if($delStrAfterKeyWord["status"]==="false"){
|
|
|
494 |
|
|
|
495 |
#設置執行不正常
|
|
|
496 |
$result["status"]="false";
|
|
|
497 |
|
|
|
498 |
#設置執行錯誤
|
|
|
499 |
$result["error"]=$delStrAfterKeyWord;
|
|
|
500 |
|
|
|
501 |
#回傳結果
|
|
|
502 |
return $result;
|
|
|
503 |
|
|
|
504 |
}#if end
|
|
|
505 |
|
|
|
506 |
#如果濾掉get變數失敗
|
|
|
507 |
if($delStrAfterKeyWord["founded"]==="false"){
|
|
|
508 |
|
|
|
509 |
#設置執行不正常
|
|
|
510 |
$result["status"]="false";
|
|
|
511 |
|
|
|
512 |
#設置執行錯誤
|
|
|
513 |
$result["error"]=$delStrAfterKeyWord;
|
|
|
514 |
|
|
|
515 |
#回傳結果
|
|
|
516 |
return $result;
|
|
|
517 |
|
|
|
518 |
}#if end
|
|
|
519 |
|
|
|
520 |
#建立session變數,然後轉址到不含get變數的當前頁面.
|
|
|
521 |
#函式說明:
|
|
|
522 |
#設定session變數後,立即轉址.
|
|
|
523 |
#回傳的結果:
|
|
|
524 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
|
|
|
525 |
#$result["function"],當前執行的函數名稱.
|
|
|
526 |
#$result["error"],錯誤訊息陣列.
|
|
|
527 |
#必填的參數:
|
|
|
528 |
#$conf["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
|
|
|
529 |
$conf["header::redirectionNow"]["headerLocation"]=$delStrAfterKeyWord["content"];
|
|
|
530 |
#可省略的參數:
|
|
|
531 |
#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
|
|
|
532 |
$conf["header::redirectionNow"]["sessionName"]=array("amazon::parseToken");
|
|
|
533 |
#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
|
|
|
534 |
$conf["header::redirectionNow"]["sessionValue"]=array($responseMultiInputDataSecurityEnhance["inputDataContent"]);
|
|
|
535 |
#參靠資料來源:
|
|
|
536 |
#http://php.net/manual/en/reserved.variables.server.php
|
|
|
537 |
$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
|
|
|
538 |
unset($conf["header::redirectionNow"]);
|
|
|
539 |
|
|
|
540 |
#如果轉址失敗
|
|
|
541 |
if($redirectionNow["status"]==="false"){
|
|
|
542 |
|
|
|
543 |
#設置執行不正常
|
|
|
544 |
$result["status"]="false";
|
|
|
545 |
|
|
|
546 |
#設置執行錯誤
|
|
|
547 |
$result["error"]=$redirectionNow;
|
|
|
548 |
|
|
|
549 |
#回傳結果
|
|
|
550 |
return $result;
|
|
|
551 |
|
|
|
552 |
}#if end
|
|
|
553 |
|
|
|
554 |
#執行到這代表不正常
|
|
|
555 |
$result["status"]="false";
|
|
|
556 |
|
|
|
557 |
#設置錯誤訊息
|
|
|
558 |
$result["error"][]="非預期的結果";
|
|
|
559 |
|
|
|
560 |
#回傳結果
|
|
|
561 |
return $result;
|
|
|
562 |
|
|
|
563 |
}#function parseToken end
|
|
|
564 |
|
|
|
565 |
/*
|
|
|
566 |
#函式說明:
|
|
|
567 |
#從表單接收解析從 amazon REST API 認證過後的 token 與相關資訊,並將結果儲存到$_SESSION變數裡面.
|
|
|
568 |
#回傳結果:
|
|
|
569 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
570 |
#$result["error"],錯誤訊息
|
|
|
571 |
#$result["content"],解析後的結果
|
|
|
572 |
#$result["function"],當前執行的函數名稱.
|
|
|
573 |
#$result["founded"],是否有找到必備的token.
|
|
|
574 |
#$result["isJson"],如果是輸出json,則為"true",反之為"false".
|
|
|
575 |
#$result["isJs"],如果回傳的是js語法則為"true",反之為"false".
|
|
|
576 |
#必填參數:
|
|
|
577 |
#無.
|
|
|
578 |
#可省略參數:
|
|
|
579 |
#$conf["inputVar"],字串,接收的post變數名稱,預設為"unParsedRestStr";
|
|
|
580 |
#$conf["inputVar"]="unParsedRestStr";
|
|
|
581 |
#$conf["restTokenSessionName"],字串陣列,儲存token資訊的session變數名稱,預設為array("amazon::parseRestToken").
|
|
|
582 |
#$conf["restTokenSessionName"]=array("amazon::parseRestToken");
|
|
|
583 |
#$conf["re_url"],字串,成功取得token資訊後要轉位到哪邊,預設為$_SERVER["PHP_SELF"].
|
|
|
584 |
#$conf["re_url"]=$_SERVER["PHP_SELF"];
|
|
|
585 |
#參考資料:
|
|
|
586 |
#無.
|
|
|
587 |
#備註:
|
|
|
588 |
#無.
|
|
|
589 |
*/
|
|
|
590 |
public static function parseRestToken(&$conf){
|
|
|
591 |
|
|
|
592 |
#初始化要回傳的結果
|
|
|
593 |
$result=array();
|
|
|
594 |
|
|
|
595 |
#取得當前執行的函數名稱
|
|
|
596 |
$result["function"]=__FUNCTION__;
|
|
|
597 |
|
|
|
598 |
#取得參數
|
|
|
599 |
$result["argu"]=$conf;
|
|
|
600 |
|
|
|
601 |
#如果 $conf 不為陣列
|
|
|
602 |
if(gettype($conf)!="array"){
|
|
|
603 |
|
|
|
604 |
#設置執行失敗
|
|
|
605 |
$result["status"]="false";
|
|
|
606 |
|
|
|
607 |
#設置執行錯誤訊息
|
|
|
608 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
609 |
|
|
|
610 |
#如果傳入的參數為 null
|
|
|
611 |
if($conf==null){
|
|
|
612 |
|
|
|
613 |
#設置執行錯誤訊息
|
|
|
614 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
615 |
|
|
|
616 |
}#if end
|
|
|
617 |
|
|
|
618 |
#回傳結果
|
|
|
619 |
return $result;
|
|
|
620 |
|
|
|
621 |
}#if end
|
|
|
622 |
|
|
|
623 |
#檢查參數
|
|
|
624 |
#函式說明:
|
|
|
625 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
626 |
#回傳結果:
|
|
|
627 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
628 |
#$result["error"],錯誤訊息陣列.
|
|
|
629 |
#$result["function"],當前執行的函式名稱.
|
|
|
630 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
631 |
#必填參數:
|
|
|
632 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
633 |
$conf["variableCheck::checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
634 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
635 |
$conf["variableCheck::checkSkipableVarType"]["sikpableVarNameArray"]=array("inputVar","restTokenSessionName","re_url");
|
|
|
636 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
637 |
$argu=&$conf;
|
|
|
638 |
#可省略參數:
|
|
|
639 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何,null代表不指定變數形態.
|
|
|
640 |
$conf["variableCheck::checkSkipableVarType"]["skipableVarTypeArray"]=array("string","string","string");
|
|
|
641 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的變數要初始化為什麼,null代表不指定.
|
|
|
642 |
$conf["variableCheck::checkSkipableVarType"]["skipableVarDefaultValue"]=array("unParsedRestStr","amazon::parseRestToken",$_SERVER["PHP_SELF"]);
|
|
|
643 |
$checkSkipableVarType=variableCheck::checkSkipableVarType($conf["variableCheck::checkSkipableVarType"],$argu);
|
|
|
644 |
unset($conf["variableCheck::checkSkipableVarType"]);
|
|
|
645 |
|
|
|
646 |
#如果檢查可省略參數失敗
|
|
|
647 |
if($checkSkipableVarType["status"]==="false"){
|
|
|
648 |
|
|
|
649 |
#設置執行失敗
|
|
|
650 |
$result["status"]="false";
|
|
|
651 |
|
|
|
652 |
#設置執行錯誤訊息
|
|
|
653 |
$result["error"]=$checkSkipableVarType;
|
|
|
654 |
|
|
|
655 |
#回傳結果
|
|
|
656 |
return $result;
|
|
|
657 |
|
|
|
658 |
}#if end
|
|
|
659 |
|
|
|
660 |
#取得變動後的參數
|
|
|
661 |
$conf=$argu;
|
|
|
662 |
|
|
|
663 |
#判斷是否為ajax要求
|
|
|
664 |
#函式說明:
|
|
|
665 |
#判斷當前php檔的執行是否為ajax的要求.
|
|
|
666 |
#回傳結果:
|
|
|
667 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
668 |
#$result["function"],當前執行的函數.
|
|
|
669 |
#$result["content"],是否為ajax要求,"true"代表是,"false"代表不是.
|
|
|
670 |
#可省略參數:
|
|
|
671 |
#$conf["useGetVarToRecogniseAjaxRequest"],字串,用來識別是否為ajax要求的get變數名稱,若其值為"true"則代表為ajax要求,反之為"false",判斷好後會將該變數移除.
|
|
|
672 |
#$conf["useGetVarToRecogniseAjaxRequest"]="is_ajax";
|
|
|
673 |
#$conf["usePostVarToRecogniseAjaxRequest"],字串,用來識別是否為ajax要求的post變數名稱,若其值為"true"則代表為ajax要求,反之為"false",判斷好後會將該變數移除.
|
|
|
674 |
#$conf["usePostVarToRecogniseAjaxRequest"]="is_ajax";
|
|
|
675 |
#備註:
|
|
|
676 |
#如果client端沒有傳送ajax要求的識別header,則無法識別是ajax要求.
|
|
|
677 |
$is_ajax=form::is_ajax();
|
|
|
678 |
|
|
|
679 |
#如果不是ajax
|
|
|
680 |
if($is_ajax["content"]==="false"){
|
|
|
681 |
|
|
|
682 |
#建立傳送當前網址的ajax要求.
|
|
|
683 |
#涵式說明:
|
|
|
684 |
#建立透過javaScript傳送post數值到特定頁面,並且取得頁面的回應,將之結果放置在特定的區塊裏面的js函式.
|
|
|
685 |
#回傳結果:
|
|
|
686 |
#$result["status"],執行正確與否,"true"代表執行正確,"false"代表執行失敗.
|
|
|
687 |
#$result["error"],錯誤訊息陣列.
|
|
|
688 |
#$result["content"],JavaScript的語法
|
|
|
689 |
#$result["function"],當前執行的函數名稱
|
|
|
690 |
#必填參數:
|
|
|
691 |
#$conf["receivePage"],字串,要接收數值的頁面.
|
|
|
692 |
$conf["javaScript::ajaxSendPostValue"]["receivePage"]=$_SERVER["PHP_SELF"];
|
|
|
693 |
$conf["javaScript::ajaxSendPostValue"]["jsFunctionName"]="parseRestToken";
|
|
|
694 |
#可省略參數:
|
|
|
695 |
#$conf["scriptTag"],是否要用<script></script>包住,預設為"false",不包住;"true"為包住.
|
|
|
696 |
$conf["javaScript::ajaxSendPostValue"]["scriptTag"]="true";
|
|
|
697 |
#$conf["varNameArray"],字串陣列,要傳送的數值名稱.
|
|
|
698 |
#$conf["javaScript::ajaxSendPostValue"]["varNameArray"]=array($conf["inputVar"]);
|
|
|
699 |
#$conf["varValueArray"],陣列,要傳送的數值內容.
|
|
|
700 |
#$conf["javaScript::ajaxSendPostValue"]["varValueArray"]=array("window.location.href");
|
|
|
701 |
#$conf["jsFunctionName"],字串,ajax裏面的js涵式名稱.
|
|
|
702 |
#$conf["jsVarNameArray"],字串陣列,要傳送的js數值名稱.
|
|
|
703 |
$conf["javaScript::ajaxSendPostValue"]["jsVarNameArray"]=array($conf["inputVar"]);
|
|
|
704 |
#$conf["jsVarValueArray"],陣列,要傳送的js數值內容.
|
|
|
705 |
$conf["javaScript::ajaxSendPostValue"]["jsVarValueArray"]=array("'&'+window.location.href.split('#')[1]");
|
|
|
706 |
#$conf["javaScript::ajaxSendPostValue"]["jsVarValueArray"]=array("encodeURIComponent(window.location.href.split('#')[1])");
|
|
|
707 |
#$conf["javaScript::ajaxSendPostValue"]["jsVarValueArray"]=array("encodeURI('&'+window.location.href.split('#')[1])");
|
|
|
708 |
#$conf["responsePalaceId"],字串,回傳的內容要呈現於哪個<span id = ? ></span>、<div id= ? ></div>區塊之間。
|
|
|
709 |
#$conf["javaScript::ajaxSendPostValue"]["responsePalaceId"]="";
|
|
|
710 |
#$conf["condition"],字串,立即執行ajax的條件.
|
|
|
711 |
$conf["javaScript::ajaxSendPostValue"]["condition"]=
|
|
|
712 |
"
|
|
|
713 |
window.location.href.search('&')!==-1 &&
|
|
|
714 |
window.location.href.search('#')!==-1 &&
|
|
|
715 |
window.location.href.search('access_token')!== -1 &&
|
|
|
716 |
window.location.href.search('token_type')!== -1 &&
|
|
|
717 |
window.location.href.search('expires_in')!== -1 &&
|
|
|
718 |
window.location.href.search('scope')!== -1
|
|
|
719 |
";
|
|
|
720 |
#$conf["conditionComment"],字串,立即執行ajax的條件註解,預設為$conf["condition"].
|
|
|
721 |
$conf["javaScript::ajaxSendPostValue"]["conditionComment"]="if is amazon token response";
|
|
|
722 |
#$conf["sendNow"],字串,是否要在document.
|
|
|
723 |
#$conf["sendNow"],字串,是否要在document.ready後馬上執行ajax,預設為"false",代表不要,"true"代表要.
|
|
|
724 |
$conf["javaScript::ajaxSendPostValue"]["sendNow"]="true";
|
|
|
725 |
#$conf["successAction"],字串,ajax要求成功後做的事情.
|
|
|
726 |
$conf["javaScript::ajaxSendPostValue"]["successAction"]="
|
|
|
727 |
|
|
|
728 |
//如果存在回應內容
|
|
|
729 |
if(xmlhttp.responseText!==undefined){
|
|
|
730 |
|
|
|
731 |
//取得json
|
|
|
732 |
if(data=JSON.parse(xmlhttp.responseText)){
|
|
|
733 |
|
|
|
734 |
//debug
|
|
|
735 |
//alert(data.toSource());
|
|
|
736 |
|
|
|
737 |
//如果存在 data.status
|
|
|
738 |
if(data.status!==undefined){
|
|
|
739 |
|
|
|
740 |
//如果 data.status 為 'true'
|
|
|
741 |
if(data.status==='true'){
|
|
|
742 |
|
|
|
743 |
//轉址
|
|
|
744 |
window.location.href='".$conf["re_url"]."';
|
|
|
745 |
|
|
|
746 |
}//if end
|
|
|
747 |
|
|
|
748 |
}//if end
|
|
|
749 |
|
|
|
750 |
}//if end
|
|
|
751 |
|
|
|
752 |
}//if end
|
|
|
753 |
";
|
|
|
754 |
|
|
|
755 |
#如果有設置 conf["re_url"]
|
|
|
756 |
if(isset($conf["re_url"])){
|
|
|
757 |
|
|
|
758 |
#$conf["redir_url"],字串,是否要在要求成功後進行轉址的動作,轉址到$conf["redir_url"].
|
|
|
759 |
$conf["javaScript::ajaxSendPostValue"]["redir_url"]=$conf["re_url"];
|
|
|
760 |
|
|
|
761 |
}#if end
|
|
|
762 |
|
|
|
763 |
#參考資料來源:
|
|
|
764 |
#http://www.w3school.com.cn/php/php_ajax_suggest.asp
|
|
|
765 |
$ajaxSendPostValue=javaScript::ajaxSendPostValue($conf["javaScript::ajaxSendPostValue"]);
|
|
|
766 |
unset($conf["javaScript::ajaxSendPostValue"]);
|
|
|
767 |
|
|
|
768 |
#如果建立 ajax 要求失敗
|
|
|
769 |
if($ajaxSendPostValue["status"]==="false"){
|
|
|
770 |
|
|
|
771 |
#設置執行失敗
|
|
|
772 |
$result["status"]="false";
|
|
|
773 |
|
|
|
774 |
#設置執行錯誤訊息
|
|
|
775 |
$result["error"]=$ajaxSendPostValue;
|
|
|
776 |
|
|
|
777 |
#回傳結果
|
|
|
778 |
return $result;
|
|
|
779 |
|
|
|
780 |
}#if end
|
|
|
781 |
|
|
|
782 |
#取得js語法
|
|
|
783 |
$result["content"]=$ajaxSendPostValue["content"];
|
|
|
784 |
|
|
|
785 |
#設置執行正常
|
|
|
786 |
$result["status"]="true";
|
|
|
787 |
|
|
|
788 |
#不是json
|
|
|
789 |
$result["isJson"]="false";
|
|
|
790 |
|
|
|
791 |
#是js語法
|
|
|
792 |
$result["isJs"]="true";
|
|
|
793 |
|
|
|
794 |
#回傳結果
|
|
|
795 |
return $result;
|
|
|
796 |
|
|
|
797 |
}#if end
|
|
|
798 |
|
|
|
799 |
#反之是ajax
|
|
|
800 |
else{
|
|
|
801 |
|
|
|
802 |
#接收變數
|
|
|
803 |
#涵式說明:
|
|
|
804 |
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
|
|
|
805 |
#回傳的結果:
|
|
|
806 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
807 |
#$result["error"],錯誤訊息陣列.
|
|
|
808 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
809 |
#$result["warning"],警告訊息陣列.
|
|
|
810 |
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
|
|
|
811 |
#$result["lostVarName"],沒有皆收到的變數名稱陣列
|
|
|
812 |
#$result["inputDataContent"],所接收的參數陣列.
|
|
|
813 |
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
|
|
|
814 |
#$result["inputDataCount"],從表單總共接收到幾個元素.
|
|
|
815 |
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
|
|
|
816 |
#必填的參數:
|
|
|
817 |
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
|
|
|
818 |
$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="POST";
|
|
|
819 |
#可省略的參數:
|
|
|
820 |
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
|
|
|
821 |
#$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";
|
|
|
822 |
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
|
|
|
823 |
#$conf["limitPrePage"]=array("");
|
|
|
824 |
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
|
|
|
825 |
#$conf["transferLocation"]="";
|
|
|
826 |
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
|
|
|
827 |
#$conf["ignore"]=array();
|
|
|
828 |
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
|
|
|
829 |
#$conf["correctCharacter"]="false";
|
|
|
830 |
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
|
|
|
831 |
$conf["form::responseMultiInputDataSecurityEnhance"]["checkedVarName"]=array($conf["inputVar"],"access_token","token_type","expires_in","scope");
|
|
|
832 |
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
|
|
|
833 |
$conf["form::responseMultiInputDataSecurityEnhance"]["canBeEmptyString"]="true";
|
|
|
834 |
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
|
|
|
835 |
#$conf["sessionNameArray"]=array();
|
|
|
836 |
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
|
|
|
837 |
#$conf["unsetSessionArray"]=array();
|
|
|
838 |
#參考資料來源:
|
|
|
839 |
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
|
|
|
840 |
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
|
|
|
841 |
#備註:
|
|
|
842 |
#表單變數的名稱若含有「.」,則會變成「-」。
|
|
|
843 |
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
844 |
unset($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
845 |
|
|
|
846 |
#如果接收變數失敗
|
|
|
847 |
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
|
|
|
848 |
|
|
|
849 |
#設置執行不正常
|
|
|
850 |
$result["status"]="false";
|
|
|
851 |
|
|
|
852 |
#設置執行錯誤
|
|
|
853 |
$result["error"]=$responseMultiInputDataSecurityEnhance;
|
|
|
854 |
|
|
|
855 |
#回傳結果
|
|
|
856 |
return $result;
|
|
|
857 |
|
|
|
858 |
}#if end
|
|
|
859 |
|
|
|
860 |
#如果沒有接收到一定要的變數
|
|
|
861 |
if($responseMultiInputDataSecurityEnhance["passed"]==="false"){
|
|
|
862 |
|
|
|
863 |
#嘗試取得 session 變數 amazon::parseToken
|
|
|
864 |
#函式說明:
|
|
|
865 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
866 |
#回傳的結果:
|
|
|
867 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
868 |
#$result["error"],錯誤訊息.
|
|
|
869 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
870 |
#$result["content"],取得的變數內容.
|
|
|
871 |
#$result["function"],當前執行的函數名稱.
|
|
|
872 |
#必填的參數:
|
|
|
873 |
#$conf["sessionVarName"],字串,要取得內容的session變數名稱
|
|
|
874 |
$conf["session::getSessionValue"]["sessionVarName"]=$conf["restTokenSessionName"];
|
|
|
875 |
#可省略的參數:
|
|
|
876 |
#$conf["unsetSessionVar"],字串,代表要卸除session變數,預設為"false"不卸除,"true"代表要卸除.
|
|
|
877 |
#$conf["session::getSessionValue"]["unsetSessionVar"]="true";
|
|
|
878 |
#參考資料:
|
|
|
879 |
#call-time-pass-by-reference-easy-fix-available=>http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
880 |
#可變變數=>http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
881 |
#卸除參考的原始變數=>http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
882 |
$getSessionValue=session::getSessionValue($conf["session::getSessionValue"]);
|
|
|
883 |
unset($conf["session::getSessionValue"]);
|
|
|
884 |
|
|
|
885 |
#如果嘗試取得session變數失敗
|
|
|
886 |
if($getSessionValue["status"]==="false"){
|
|
|
887 |
|
|
|
888 |
#設置執行不正常
|
|
|
889 |
$result["status"]="false";
|
|
|
890 |
|
|
|
891 |
#設置執行錯誤
|
|
|
892 |
$result["error"]=$getSessionValue;
|
|
|
893 |
|
|
|
894 |
#回傳結果
|
|
|
895 |
return $result;
|
|
|
896 |
|
|
|
897 |
}#if end
|
|
|
898 |
|
|
|
899 |
#如果取得到session變數
|
|
|
900 |
if($getSessionValue["founded"]==="true"){
|
|
|
901 |
|
|
|
902 |
#取得 session 變數值
|
|
|
903 |
$result["content"]=$getSessionValue["content"];
|
|
|
904 |
|
|
|
905 |
#設置執行正常
|
|
|
906 |
$result["status"]="true";
|
|
|
907 |
|
|
|
908 |
#設置有取得到token
|
|
|
909 |
$result["founded"]="true";
|
|
|
910 |
|
|
|
911 |
#不是json
|
|
|
912 |
$result["isJson"]="false";
|
|
|
913 |
|
|
|
914 |
#不是js語法
|
|
|
915 |
$result["isJs"]="false";
|
|
|
916 |
|
|
|
917 |
#回傳結果
|
|
|
918 |
return $result;
|
|
|
919 |
|
|
|
920 |
}#if end
|
|
|
921 |
|
|
|
922 |
#反之
|
|
|
923 |
else{
|
|
|
924 |
|
|
|
925 |
#設置執行正常
|
|
|
926 |
$result["status"]="true";
|
|
|
927 |
|
|
|
928 |
#設置沒有取得到token
|
|
|
929 |
$result["founded"]="false";
|
|
|
930 |
|
|
|
931 |
#印出 json
|
|
|
932 |
echo json_encode($result);
|
|
|
933 |
|
|
|
934 |
#設置是json
|
|
|
935 |
$result["isJson"]="true";
|
|
|
936 |
|
|
|
937 |
#不是js語法
|
|
|
938 |
$result["isJs"]="false";
|
|
|
939 |
|
|
|
940 |
#結束程式
|
|
|
941 |
return true;
|
|
|
942 |
|
|
|
943 |
}#else end
|
|
|
944 |
|
|
|
945 |
}#if end
|
|
|
946 |
|
|
|
947 |
#反之接收到一定要的變數
|
|
|
948 |
else{
|
|
|
949 |
|
|
|
950 |
#取得接收到的變數
|
|
|
951 |
$recVar=$responseMultiInputDataSecurityEnhance["inputDataContent"];
|
|
|
952 |
|
|
|
953 |
#卸除多餘的變數
|
|
|
954 |
unset($recVar["is_ajax"]);
|
|
|
955 |
unset($recVar[$conf["inputVar"]]);
|
|
|
956 |
|
|
|
957 |
#儲存解析好的token資訊
|
|
|
958 |
$_SESSION[$conf["restTokenSessionName"]]=$recVar;
|
|
|
959 |
|
|
|
960 |
#設置取得的token資訊
|
|
|
961 |
$result["content"]=$_SESSION[$conf["restTokenSessionName"]];
|
|
|
962 |
|
|
|
963 |
#設置token資訊儲存在哪個session變數裡面
|
|
|
964 |
$result["sessionName"]=$conf["restTokenSessionName"];
|
|
|
965 |
|
|
|
966 |
#設置執行正常
|
|
|
967 |
$result["status"]="true";
|
|
|
968 |
|
|
|
969 |
#印出 json
|
|
|
970 |
echo json_encode($result);
|
|
|
971 |
|
|
|
972 |
#設置是json
|
|
|
973 |
$result["isJson"]="true";
|
|
|
974 |
|
|
|
975 |
#不是ajax語法
|
|
|
976 |
$result["isJs"]="false";
|
|
|
977 |
|
|
|
978 |
#結束程式
|
|
|
979 |
return true;
|
|
|
980 |
|
|
|
981 |
}#else
|
|
|
982 |
|
|
|
983 |
}#else end
|
|
|
984 |
|
|
|
985 |
}#function parseRestToken end
|
|
|
986 |
|
|
|
987 |
/*
|
|
|
988 |
#函式說明:
|
|
|
989 |
#從表單接收解析從 amazon REST API 認證過後的 code 與相關資訊,並將結果儲存到$_SESSION變數裡面.
|
|
|
990 |
#回傳結果:
|
|
|
991 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
992 |
#$result["error"],錯誤訊息
|
|
|
993 |
#$result["content"],解析後的結果
|
|
|
994 |
#$result["function"],當前執行的函數名稱.
|
|
|
995 |
#$result["founded"],是否有找到必備的code.
|
|
|
996 |
#必填參數:
|
|
|
997 |
#無.
|
|
|
998 |
#可省略參數:
|
|
|
999 |
#$conf["restCodeSessionName"],字串陣列,儲存token資訊的session變數名稱,預設為array("amazon::parseRestCode").
|
|
|
1000 |
#$conf["restCodeSessionName"]=array("amazon::parseRestCode");
|
|
|
1001 |
#$conf["re_url"],字串,成功取得token資訊後要轉位到哪邊,預設為$_SERVER["PHP_SELF"].
|
|
|
1002 |
#$conf["re_url"]=$_SERVER["PHP_SELF"];
|
|
|
1003 |
#參考資料:
|
|
|
1004 |
#無.
|
|
|
1005 |
#備註:
|
|
|
1006 |
#無.
|
|
|
1007 |
*/
|
|
|
1008 |
public static function parseRestCode(&$conf){
|
|
|
1009 |
|
|
|
1010 |
#初始化要回傳的結果
|
|
|
1011 |
$result=array();
|
|
|
1012 |
|
|
|
1013 |
#取得當前執行的函數名稱
|
|
|
1014 |
$result["function"]=__FUNCTION__;
|
|
|
1015 |
|
|
|
1016 |
#取得參數
|
|
|
1017 |
$result["argu"]=$conf;
|
|
|
1018 |
|
|
|
1019 |
#如果 $conf 不為陣列
|
|
|
1020 |
if(gettype($conf)!="array"){
|
|
|
1021 |
|
|
|
1022 |
#設置執行失敗
|
|
|
1023 |
$result["status"]="false";
|
|
|
1024 |
|
|
|
1025 |
#設置執行錯誤訊息
|
|
|
1026 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1027 |
|
|
|
1028 |
#如果傳入的參數為 null
|
|
|
1029 |
if($conf==null){
|
|
|
1030 |
|
|
|
1031 |
#設置執行錯誤訊息
|
|
|
1032 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1033 |
|
|
|
1034 |
}#if end
|
|
|
1035 |
|
|
|
1036 |
#回傳結果
|
|
|
1037 |
return $result;
|
|
|
1038 |
|
|
|
1039 |
}#if end
|
|
|
1040 |
|
|
|
1041 |
#檢查參數
|
|
|
1042 |
#函式說明:
|
|
|
1043 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
1044 |
#回傳結果:
|
|
|
1045 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1046 |
#$result["error"],錯誤訊息陣列.
|
|
|
1047 |
#$result["function"],當前執行的函式名稱.
|
|
|
1048 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
1049 |
#必填參數:
|
|
|
1050 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
1051 |
$conf["variableCheck::checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
1052 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
1053 |
$conf["variableCheck::checkSkipableVarType"]["sikpableVarNameArray"]=array("restCodeSessionName","re_url");
|
|
|
1054 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
1055 |
$argu=&$conf;
|
|
|
1056 |
#可省略參數:
|
|
|
1057 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何,null代表不指定變數形態.
|
|
|
1058 |
$conf["variableCheck::checkSkipableVarType"]["skipableVarTypeArray"]=array("string","string");
|
|
|
1059 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的變數要初始化為什麼,null代表不指定.
|
|
|
1060 |
$conf["variableCheck::checkSkipableVarType"]["skipableVarDefaultValue"]=array("amazon::parseRestCode",$_SERVER["PHP_SELF"]);
|
|
|
1061 |
$checkSkipableVarType=variableCheck::checkSkipableVarType($conf["variableCheck::checkSkipableVarType"],$argu);
|
|
|
1062 |
unset($conf["variableCheck::checkSkipableVarType"]);
|
|
|
1063 |
|
|
|
1064 |
#如果檢查可省略參數失敗
|
|
|
1065 |
if($checkSkipableVarType["status"]==="false"){
|
|
|
1066 |
|
|
|
1067 |
#設置執行失敗
|
|
|
1068 |
$result["status"]="false";
|
|
|
1069 |
|
|
|
1070 |
#設置執行錯誤訊息
|
|
|
1071 |
$result["error"]=$checkSkipableVarType;
|
|
|
1072 |
|
|
|
1073 |
#回傳結果
|
|
|
1074 |
return $result;
|
|
|
1075 |
|
|
|
1076 |
}#if end
|
|
|
1077 |
|
|
|
1078 |
#取得變動後的參數
|
|
|
1079 |
$conf=$argu;
|
|
|
1080 |
|
|
|
1081 |
#接收變數
|
|
|
1082 |
#涵式說明:
|
|
|
1083 |
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
|
|
|
1084 |
#回傳的結果:
|
|
|
1085 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
1086 |
#$result["error"],錯誤訊息陣列.
|
|
|
1087 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
1088 |
#$result["warning"],警告訊息陣列.
|
|
|
1089 |
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
|
|
|
1090 |
#$result["lostVarName"],沒有皆收到的變數名稱陣列
|
|
|
1091 |
#$result["inputDataContent"],所接收的參數陣列.
|
|
|
1092 |
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
|
|
|
1093 |
#$result["inputDataCount"],從表單總共接收到幾個元素.
|
|
|
1094 |
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
|
|
|
1095 |
#必填的參數:
|
|
|
1096 |
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
|
|
|
1097 |
$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="GET";
|
|
|
1098 |
#可省略的參數:
|
|
|
1099 |
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
|
|
|
1100 |
$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";
|
|
|
1101 |
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
|
|
|
1102 |
#$conf["limitPrePage"]=array("");
|
|
|
1103 |
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
|
|
|
1104 |
#$conf["transferLocation"]="";
|
|
|
1105 |
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
|
|
|
1106 |
#$conf["ignore"]=array();
|
|
|
1107 |
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
|
|
|
1108 |
#$conf["correctCharacter"]="false";
|
|
|
1109 |
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
|
|
|
1110 |
$conf["form::responseMultiInputDataSecurityEnhance"]["checkedVarName"]=array("code","scope");
|
|
|
1111 |
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
|
|
|
1112 |
#$conf["form::responseMultiInputDataSecurityEnhance"]["canBeEmptyString"]="true";
|
|
|
1113 |
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
|
|
|
1114 |
#$conf["sessionNameArray"]=array();
|
|
|
1115 |
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
|
|
|
1116 |
#$conf["unsetSessionArray"]=array();
|
|
|
1117 |
#參考資料來源:
|
|
|
1118 |
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
|
|
|
1119 |
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
|
|
|
1120 |
#備註:
|
|
|
1121 |
#表單變數的名稱若含有「.」,則會變成「-」。
|
|
|
1122 |
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
1123 |
unset($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
1124 |
|
|
|
1125 |
#如果接收變數失敗
|
|
|
1126 |
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
|
|
|
1127 |
|
|
|
1128 |
#設置執行不正常
|
|
|
1129 |
$result["status"]="false";
|
|
|
1130 |
|
|
|
1131 |
#設置執行錯誤
|
|
|
1132 |
$result["error"]=$responseMultiInputDataSecurityEnhance;
|
|
|
1133 |
|
|
|
1134 |
#回傳結果
|
|
|
1135 |
return $result;
|
|
|
1136 |
|
|
|
1137 |
}#if end
|
|
|
1138 |
|
|
|
1139 |
#如果沒有接收到一定要的變數
|
|
|
1140 |
if($responseMultiInputDataSecurityEnhance["passed"]==="false"){
|
|
|
1141 |
|
|
|
1142 |
#嘗試取得 session 變數 amazon::parseToken
|
|
|
1143 |
#函式說明:
|
|
|
1144 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
1145 |
#回傳的結果:
|
|
|
1146 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
1147 |
#$result["error"],錯誤訊息.
|
|
|
1148 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
1149 |
#$result["content"],取得的變數內容.
|
|
|
1150 |
#$result["function"],當前執行的函數名稱.
|
|
|
1151 |
#必填的參數:
|
|
|
1152 |
#$conf["sessionVarName"],字串,要取得內容的session變數名稱
|
|
|
1153 |
$conf["session::getSessionValue"]["sessionVarName"]=$conf["restCodeSessionName"];
|
|
|
1154 |
#可省略的參數:
|
|
|
1155 |
#$conf["unsetSessionVar"],字串,代表要卸除session變數,預設為"false"不卸除,"true"代表要卸除.
|
|
|
1156 |
#$conf["session::getSessionValue"]["unsetSessionVar"]="true";
|
|
|
1157 |
#參考資料:
|
|
|
1158 |
#call-time-pass-by-reference-easy-fix-available=>http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
1159 |
#可變變數=>http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
1160 |
#卸除參考的原始變數=>http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
1161 |
$getSessionValue=session::getSessionValue($conf["session::getSessionValue"]);
|
|
|
1162 |
unset($conf["session::getSessionValue"]);
|
|
|
1163 |
|
|
|
1164 |
#如果嘗試取得session變數失敗
|
|
|
1165 |
if($getSessionValue["status"]==="false"){
|
|
|
1166 |
|
|
|
1167 |
#設置執行不正常
|
|
|
1168 |
$result["status"]="false";
|
|
|
1169 |
|
|
|
1170 |
#設置執行錯誤
|
|
|
1171 |
$result["error"]=$getSessionValue;
|
|
|
1172 |
|
|
|
1173 |
#回傳結果
|
|
|
1174 |
return $result;
|
|
|
1175 |
|
|
|
1176 |
}#if end
|
|
|
1177 |
|
|
|
1178 |
#如果取得到session變數
|
|
|
1179 |
if($getSessionValue["founded"]==="true"){
|
|
|
1180 |
|
|
|
1181 |
#取得 session 變數值
|
|
|
1182 |
$result["content"]=$getSessionValue["content"];
|
|
|
1183 |
|
|
|
1184 |
#設置執行正常
|
|
|
1185 |
$result["status"]="true";
|
|
|
1186 |
|
|
|
1187 |
#設置有取得到code
|
|
|
1188 |
$result["founded"]="true";
|
|
|
1189 |
|
|
|
1190 |
#回傳結果
|
|
|
1191 |
return $result;
|
|
|
1192 |
|
|
|
1193 |
}#if end
|
|
|
1194 |
|
|
|
1195 |
#反之
|
|
|
1196 |
else{
|
|
|
1197 |
|
|
|
1198 |
#設置執行正常
|
|
|
1199 |
$result["status"]="true";
|
|
|
1200 |
|
|
|
1201 |
#設置沒有取得到code
|
|
|
1202 |
$result["founded"]="false";
|
|
|
1203 |
|
|
|
1204 |
#結束程式
|
|
|
1205 |
return $result;
|
|
|
1206 |
|
|
|
1207 |
}#else end
|
|
|
1208 |
|
|
|
1209 |
}#if end
|
|
|
1210 |
|
|
|
1211 |
#反之接收到一定要的變數
|
|
|
1212 |
else{
|
|
|
1213 |
|
|
|
1214 |
#取得接收到的變數
|
|
|
1215 |
$recVar=$responseMultiInputDataSecurityEnhance["inputDataContent"];
|
|
|
1216 |
|
|
|
1217 |
#儲存解析好的token資訊
|
|
|
1218 |
$_SESSION[$conf["restCodeSessionName"]]=$recVar;
|
|
|
1219 |
|
|
|
1220 |
#函式說明:
|
|
|
1221 |
#設定session變數後,立即轉址.
|
|
|
1222 |
#回傳的結果:
|
|
|
1223 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
|
|
|
1224 |
#$result["function"],當前執行的函數名稱.
|
|
|
1225 |
#$result["error"],錯誤訊息陣列.
|
|
|
1226 |
#必填的參數:
|
|
|
1227 |
#$conf["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
|
|
|
1228 |
$conf["header::redirectionNow"]["headerLocation"]=$conf["re_url"];
|
|
|
1229 |
#可省略的參數:
|
|
|
1230 |
#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
|
|
|
1231 |
#$conf["sessionName"]=array("");
|
|
|
1232 |
#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
|
|
|
1233 |
#$conf["sessionValue"]=array("");
|
|
|
1234 |
#參靠資料來源:
|
|
|
1235 |
#http://php.net/manual/en/reserved.variables.server.php
|
|
|
1236 |
$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
|
|
|
1237 |
unset($conf["header::redirectionNow"]);
|
|
|
1238 |
|
|
|
1239 |
}#else
|
|
|
1240 |
|
|
|
1241 |
}#function parseRestCode end
|
|
|
1242 |
|
|
|
1243 |
/*
|
|
|
1244 |
#函式說明:
|
|
|
1245 |
#用 RESTful API 來跟 Amazon cloud 互動的要求連結,識別的方式為token.
|
|
|
1246 |
#回傳結果:
|
|
|
1247 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1248 |
#$result["error"],錯誤訊息
|
|
|
1249 |
#$result["content"],語法
|
|
|
1250 |
#$result["function"],當前執行的函數名稱
|
|
|
1251 |
#必填參數:
|
|
|
1252 |
#$conf["clientId"],字串,用戶端id,亦即app的clientId.
|
|
|
1253 |
$conf["clientId"]="";
|
|
|
1254 |
#$conf["scope"],字串,要求的權限,例如:clouddrive:read_all clouddrive:write就是代表擁有全部內容的讀寫權限.
|
|
|
1255 |
$conf["scope"]="";
|
|
|
1256 |
#可省略參數:
|
|
|
1257 |
#$conf["redirect_uri"],字串,認證完要轉址到哪哩,預設為當前網址.
|
|
|
1258 |
#$conf["redirect_uri"]="";
|
|
|
1259 |
#參考資料:
|
|
|
1260 |
#amazon cloud drive scrope=>https://developer.amazon.com/public/apis/experience/cloud-drive/content/getting-started
|
|
|
1261 |
#amazon restful api=>https://developer.amazon.com/appsandservices/apis/experience/cloud-drive/content/restful-api-getting-started
|
|
|
1262 |
#備註:
|
|
|
1263 |
#導頁後的網址格式=>https://127.0.0.1/#access_token=Atza%7CIwEBIA-3AFM0FETM_DFFpBQmyztJKN0TYp4AT7CBWy4k8InyFzTA-t1cMPJg05jaRFFjppk4S3VCu3FlBl4MwJj3Uh_A_15abg4SARxfgAv7-vRZ-1UbhYhFmbhjEdziWg4YyoYZvJn5ihZXI2o7mYxy-8r4d4TnwpIspJ3X9tLc6JYzJCU3VRPVCajwV3-WWGwyeQL-DiLgrwIm7iK8Y8W87HoqoXaomPpzsnuef0tQe2Fcquzo3_AVAIB0RYjyH97JtZgL95lQrCagjbr6HNL0mPvjD3GpHxhTjViZjvhMlj8zYAlHc0PYs6zMZ_gElFUOlH448woxtjJtDf4U-l8YZTYq25CBXYeN86l6YuNmi8ZuqozYwHGUDccWR2qbr8jsNdNvErSroeU30sKcPfPEdzbhi7VTOR4WtQS8oYdZHYZTwKWCPPKV1NXRfgQKA9LOUaH85KPWdTsseh-QeDKjk9dkP9j_noNre47mtQWbqojaIhSZfDmADwVQBqBUsQ1DFhaT0r5cF6vjC_LZmHfFZmY067G2JeMijpXfxCvlbwQweA&token_type=bearer&expires_in=3600&scope=clouddrive%3Aread_all
|
|
|
1264 |
*/
|
|
|
1265 |
public static function authenticateToACbyToken(&$conf){
|
|
|
1266 |
|
|
|
1267 |
#初始化要回傳的結果
|
|
|
1268 |
$result=array();
|
|
|
1269 |
|
|
|
1270 |
#取得當前執行的函數名稱
|
|
|
1271 |
$result["function"]=__FUNCTION__;
|
|
|
1272 |
|
|
|
1273 |
#如果沒有參數
|
|
|
1274 |
if(func_num_args()==0){
|
|
|
1275 |
|
|
|
1276 |
#設置執行失敗
|
|
|
1277 |
$result["status"]="false";
|
|
|
1278 |
|
|
|
1279 |
#設置執行錯誤訊息
|
|
|
1280 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1281 |
|
|
|
1282 |
#回傳結果
|
|
|
1283 |
return $result;
|
|
|
1284 |
|
|
|
1285 |
}#if end
|
|
|
1286 |
|
|
|
1287 |
#取得參數
|
|
|
1288 |
$result["argu"]=$conf;
|
|
|
1289 |
|
|
|
1290 |
#如果 $conf 不為陣列
|
|
|
1291 |
if(gettype($conf)!=="array"){
|
|
|
1292 |
|
|
|
1293 |
#設置執行失敗
|
|
|
1294 |
$result["status"]="false";
|
|
|
1295 |
|
|
|
1296 |
#設置執行錯誤訊息
|
|
|
1297 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1298 |
|
|
|
1299 |
#如果傳入的參數為 null
|
|
|
1300 |
if($conf===null){
|
|
|
1301 |
|
|
|
1302 |
#設置執行錯誤訊息
|
|
|
1303 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1304 |
|
|
|
1305 |
}#if end
|
|
|
1306 |
|
|
|
1307 |
#回傳結果
|
|
|
1308 |
return $result;
|
|
|
1309 |
|
|
|
1310 |
}#if end
|
|
|
1311 |
|
|
|
1312 |
#檢查參數
|
|
|
1313 |
#函式說明:
|
|
|
1314 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1315 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1316 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1317 |
#$result["function"],當前執行的函式名稱.
|
|
|
1318 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1319 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1320 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1321 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1322 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1323 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1324 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1325 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1326 |
#必填寫的參數:
|
|
|
1327 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1328 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1329 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1330 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("clientId","scope");
|
|
|
1331 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1332 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1333 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1334 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1335 |
#可以省略的參數:
|
|
|
1336 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1337 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1338 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1339 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1340 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1341 |
#$conf["canBeEmpty"]=array();
|
|
|
1342 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1343 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1344 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1345 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("redirect_uri");
|
|
|
1346 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1347 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1348 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1349 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["REQUEST_URI"]);
|
|
|
1350 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1351 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1352 |
#參考資料來源:
|
|
|
1353 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1354 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1355 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1356 |
|
|
|
1357 |
#如果參數檢查失敗
|
|
|
1358 |
if($checkArguments["status"]==="false"){
|
|
|
1359 |
|
|
|
1360 |
#設置執行不正常
|
|
|
1361 |
$result["status"]="false";
|
|
|
1362 |
|
|
|
1363 |
#設置執行錯誤
|
|
|
1364 |
$result["error"]=$checkArguments;
|
|
|
1365 |
|
|
|
1366 |
#回傳結果
|
|
|
1367 |
return $result;
|
|
|
1368 |
|
|
|
1369 |
}#if end
|
|
|
1370 |
|
|
|
1371 |
#如果參數檢查不通過
|
|
|
1372 |
if($checkArguments["passed"]==="false"){
|
|
|
1373 |
|
|
|
1374 |
#設置執行不正常
|
|
|
1375 |
$result["status"]="false";
|
|
|
1376 |
|
|
|
1377 |
#設置執行錯誤
|
|
|
1378 |
$result["error"]=$checkArguments;
|
|
|
1379 |
|
|
|
1380 |
#回傳結果
|
|
|
1381 |
return $result;
|
|
|
1382 |
|
|
|
1383 |
}#if end
|
|
|
1384 |
|
|
|
1385 |
#https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.b91a4d2fd2f641f2a15ea469&scope=clouddrive%3Aread_all%20clouddrive%3Awrite&response_type=token&redirect_uri=http://localhost
|
|
|
1386 |
|
|
|
1387 |
#初始化用 amazon RESTful 認證的 url
|
|
|
1388 |
$url="https://www.amazon.com/ap/oa";
|
|
|
1389 |
|
|
|
1390 |
#加密 $conf["clientId"]
|
|
|
1391 |
$conf["clientId"]=urlencode($conf["clientId"]);
|
|
|
1392 |
|
|
|
1393 |
#加密 $conf["scope"]
|
|
|
1394 |
$conf["scope"]=urlencode($conf["scope"]);
|
|
|
1395 |
|
|
|
1396 |
#加密 $response_type
|
|
|
1397 |
$response_type=urlencode("token");
|
|
|
1398 |
|
|
|
1399 |
#加密 $conf["redirect_uri"]
|
|
|
1400 |
$conf["redirect_uri"]=urlencode($conf["redirect_uri"]);
|
|
|
1401 |
|
|
|
1402 |
#組合成完整的url
|
|
|
1403 |
$url=$url."?client_id=".$conf["clientId"]."&scope=".$conf["scope"]."&response_type=".$response_type."&redirect_uri=".$conf["redirect_uri"];
|
|
|
1404 |
|
|
|
1405 |
#涵式說明:
|
|
|
1406 |
#放置超鏈結
|
|
|
1407 |
#回傳的結果:
|
|
|
1408 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1409 |
#$result["error"],錯誤訊息
|
|
|
1410 |
#$result["content"],語法
|
|
|
1411 |
#$result["function"],當前執行的函數名稱
|
|
|
1412 |
#必填的參數:
|
|
|
1413 |
#$conf["position"],字串,爲要連結到的位置,若留空,將回自動變成"#",則可以搭配ajax傳值.
|
|
|
1414 |
$conf["link::show_link"]["position"]=$url;
|
|
|
1415 |
#$conf["linkName",字串,爲連結的顯示名稱
|
|
|
1416 |
$conf["link::show_link"]["linkName"]="RESTful Authenticate";
|
|
|
1417 |
#可省略的參數:
|
|
|
1418 |
#$conf["method"],字串,爲點選連結後,新畫面要如何呈現,可省略預設爲"_self",可用的選項有 _top(覆蓋目前的視窗來顯現新內容) _parent _self _blank(跳新視窗)
|
|
|
1419 |
#$conf["method"]="";
|
|
|
1420 |
#$conf["class"],字串,爲要套用的css超連節樣式,可省略.
|
|
|
1421 |
#$conf["class"]="";
|
|
|
1422 |
#$conf["id"],字串,超連結的id.
|
|
|
1423 |
#$conf["id"]="";
|
|
|
1424 |
#$conf["no_outline"],字串,是否要取消連結的框線,"false為不取消,"true"代表要取消,預設為"false".
|
|
|
1425 |
#$conf["no_outline"]="";
|
|
|
1426 |
$show_link=link::show_link($conf["link::show_link"]);
|
|
|
1427 |
unset($conf["link::show_link"]);
|
|
|
1428 |
|
|
|
1429 |
#如果建立超連結的語法失敗
|
|
|
1430 |
if($show_link["status"]==="false"){
|
|
|
1431 |
|
|
|
1432 |
#取得當前執行的函式
|
|
|
1433 |
$result["function"]=__FUNCTION__;
|
|
|
1434 |
|
|
|
1435 |
#設置執行不正常
|
|
|
1436 |
$result["status"]="false";
|
|
|
1437 |
|
|
|
1438 |
#設置執行錯誤
|
|
|
1439 |
$result["error"]=$show_link;
|
|
|
1440 |
|
|
|
1441 |
#回傳結果
|
|
|
1442 |
return $result;
|
|
|
1443 |
|
|
|
1444 |
}#if end
|
|
|
1445 |
|
|
|
1446 |
#取得語法
|
|
|
1447 |
$result["content"]=$show_link["content"];
|
|
|
1448 |
|
|
|
1449 |
#設置執行正常
|
|
|
1450 |
$result["status"]="true";
|
|
|
1451 |
|
|
|
1452 |
#回傳結果
|
|
|
1453 |
return $result;
|
|
|
1454 |
|
|
|
1455 |
}#function demoAuthenticateToACbyToken end
|
|
|
1456 |
|
|
|
1457 |
/*
|
|
|
1458 |
#函式說明:
|
|
|
1459 |
#用 RESTful API 來跟 Amazon cloud 互動的要求連結,識別的方式為code.
|
|
|
1460 |
#回傳結果:
|
|
|
1461 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1462 |
#$result["error"],錯誤訊息
|
|
|
1463 |
#$result["content"],語法
|
|
|
1464 |
#$result["function"],當前執行的函數名稱
|
|
|
1465 |
#必填參數:
|
|
|
1466 |
#$conf["clientId"],字串,用戶端id,亦即app的clientId.
|
|
|
1467 |
$conf["clientId"]="";
|
|
|
1468 |
#$conf["scope"],字串,要求的權限,例如:clouddrive:read_all clouddrive:write就是代表擁有全部內容的讀寫權限.
|
|
|
1469 |
$conf["scope"]="";
|
|
|
1470 |
#可省略參數:
|
|
|
1471 |
#$conf["redirect_uri"],字串,認證完要轉址到哪哩,預設為當前網址.
|
|
|
1472 |
#$conf["redirect_uri"]="";
|
|
|
1473 |
#參考資料:
|
|
|
1474 |
#amazon cloud drive scrope=>https://developer.amazon.com/public/apis/experience/cloud-drive/content/getting-started
|
|
|
1475 |
#amazon restful api=>https://developer.amazon.com/appsandservices/apis/experience/cloud-drive/content/restful-api-getting-started
|
|
|
1476 |
#Amazon-Cloud-Drive-Python-SDK=>https://github.com/cnbeining/Amazon-Cloud-Drive-Python-SDK/blob/master/acd.py
|
|
|
1477 |
#備註:
|
|
|
1478 |
#導頁後的網址格式=>https://127.0.0.1/#access_token=Atza%7CIwEBIA-3AFM0FETM_DFFpBQmyztJKN0TYp4AT7CBWy4k8InyFzTA-t1cMPJg05jaRFFjppk4S3VCu3FlBl4MwJj3Uh_A_15abg4SARxfgAv7-vRZ-1UbhYhFmbhjEdziWg4YyoYZvJn5ihZXI2o7mYxy-8r4d4TnwpIspJ3X9tLc6JYzJCU3VRPVCajwV3-WWGwyeQL-DiLgrwIm7iK8Y8W87HoqoXaomPpzsnuef0tQe2Fcquzo3_AVAIB0RYjyH97JtZgL95lQrCagjbr6HNL0mPvjD3GpHxhTjViZjvhMlj8zYAlHc0PYs6zMZ_gElFUOlH448woxtjJtDf4U-l8YZTYq25CBXYeN86l6YuNmi8ZuqozYwHGUDccWR2qbr8jsNdNvErSroeU30sKcPfPEdzbhi7VTOR4WtQS8oYdZHYZTwKWCPPKV1NXRfgQKA9LOUaH85KPWdTsseh-QeDKjk9dkP9j_noNre47mtQWbqojaIhSZfDmADwVQBqBUsQ1DFhaT0r5cF6vjC_LZmHfFZmY067G2JeMijpXfxCvlbwQweA&token_type=bearer&expires_in=3600&scope=clouddrive%3Aread_all
|
|
|
1479 |
*/
|
|
|
1480 |
public static function authenticateToACbyCode(&$conf){
|
|
|
1481 |
|
|
|
1482 |
#初始化要回傳的結果
|
|
|
1483 |
$result=array();
|
|
|
1484 |
|
|
|
1485 |
#取得當前執行的函數名稱
|
|
|
1486 |
$result["function"]=__FUNCTION__;
|
|
|
1487 |
|
|
|
1488 |
#如果沒有參數
|
|
|
1489 |
if(func_num_args()==0){
|
|
|
1490 |
|
|
|
1491 |
#設置執行失敗
|
|
|
1492 |
$result["status"]="false";
|
|
|
1493 |
|
|
|
1494 |
#設置執行錯誤訊息
|
|
|
1495 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1496 |
|
|
|
1497 |
#回傳結果
|
|
|
1498 |
return $result;
|
|
|
1499 |
|
|
|
1500 |
}#if end
|
|
|
1501 |
|
|
|
1502 |
#取得參數
|
|
|
1503 |
$result["argu"]=$conf;
|
|
|
1504 |
|
|
|
1505 |
#如果 $conf 不為陣列
|
|
|
1506 |
if(gettype($conf)!=="array"){
|
|
|
1507 |
|
|
|
1508 |
#設置執行失敗
|
|
|
1509 |
$result["status"]="false";
|
|
|
1510 |
|
|
|
1511 |
#設置執行錯誤訊息
|
|
|
1512 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1513 |
|
|
|
1514 |
#如果傳入的參數為 null
|
|
|
1515 |
if($conf===null){
|
|
|
1516 |
|
|
|
1517 |
#設置執行錯誤訊息
|
|
|
1518 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1519 |
|
|
|
1520 |
}#if end
|
|
|
1521 |
|
|
|
1522 |
#回傳結果
|
|
|
1523 |
return $result;
|
|
|
1524 |
|
|
|
1525 |
}#if end
|
|
|
1526 |
|
|
|
1527 |
#檢查參數
|
|
|
1528 |
#函式說明:
|
|
|
1529 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1530 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1531 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1532 |
#$result["function"],當前執行的函式名稱.
|
|
|
1533 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1534 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1535 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1536 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1537 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1538 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1539 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1540 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1541 |
#必填寫的參數:
|
|
|
1542 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1543 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1544 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1545 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("clientId","scope");
|
|
|
1546 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1547 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1548 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1549 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1550 |
#可以省略的參數:
|
|
|
1551 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1552 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1553 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1554 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1555 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1556 |
#$conf["canBeEmpty"]=array();
|
|
|
1557 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1558 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1559 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1560 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("redirect_uri");
|
|
|
1561 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1562 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1563 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1564 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
1565 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1566 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1567 |
#參考資料來源:
|
|
|
1568 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1569 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1570 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1571 |
|
|
|
1572 |
#如果參數檢查失敗
|
|
|
1573 |
if($checkArguments["status"]==="false"){
|
|
|
1574 |
|
|
|
1575 |
#設置執行不正常
|
|
|
1576 |
$result["status"]="false";
|
|
|
1577 |
|
|
|
1578 |
#設置執行錯誤
|
|
|
1579 |
$result["error"]=$checkArguments;
|
|
|
1580 |
|
|
|
1581 |
#回傳結果
|
|
|
1582 |
return $result;
|
|
|
1583 |
|
|
|
1584 |
}#if end
|
|
|
1585 |
|
|
|
1586 |
#如果參數檢查不通過
|
|
|
1587 |
if($checkArguments["passed"]==="false"){
|
|
|
1588 |
|
|
|
1589 |
#設置執行不正常
|
|
|
1590 |
$result["status"]="false";
|
|
|
1591 |
|
|
|
1592 |
#設置執行錯誤
|
|
|
1593 |
$result["error"]=$checkArguments;
|
|
|
1594 |
|
|
|
1595 |
#回傳結果
|
|
|
1596 |
return $result;
|
|
|
1597 |
|
|
|
1598 |
}#if end
|
|
|
1599 |
|
|
|
1600 |
#https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.b91a4d2fd2f641f2a15ea469&scope=clouddrive%3Aread_all%20clouddrive%3Awrite&response_type=token&redirect_uri=http://localhost
|
|
|
1601 |
|
|
|
1602 |
#初始化用 amazon RESTful 認證的 url
|
|
|
1603 |
$url="https://www.amazon.com/ap/oa";
|
|
|
1604 |
|
|
|
1605 |
#加密 $conf["clientId"]
|
|
|
1606 |
$conf["clientId"]=urlencode($conf["clientId"]);
|
|
|
1607 |
|
|
|
1608 |
#加密 $conf["scope"]
|
|
|
1609 |
$conf["scope"]=urlencode($conf["scope"]);
|
|
|
1610 |
|
|
|
1611 |
#加密 $response_type
|
|
|
1612 |
$response_type=urlencode("code");
|
|
|
1613 |
|
|
|
1614 |
#加密 $conf["redirect_uri"]
|
|
|
1615 |
if(!isset($conf["redirect_uri"])){
|
|
|
1616 |
|
|
|
1617 |
#涵式說明:
|
|
|
1618 |
#取得用戶端的資訊,並依據需要寫入到資料表裡面
|
|
|
1619 |
#回傳的結果:
|
|
|
1620 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
1621 |
#$result["error"],錯誤訊息.
|
|
|
1622 |
#$result["function"],檔前執行的函數名稱.
|
|
|
1623 |
#$result["mode"],當前的模式是"cmd"還是"web".
|
|
|
1624 |
#$result["userBrowserType"],爲使用者的瀏覽器資訊
|
|
|
1625 |
#$result["userIp"],爲使用者的IP
|
|
|
1626 |
#$result["serverIp"],為伺服器的IP
|
|
|
1627 |
#$result["scheme"],通訊協定
|
|
|
1628 |
#$result["serverPort"],伺服器給對外下載網頁的port
|
|
|
1629 |
#$result["requestUri"],爲使用者要求的網址
|
|
|
1630 |
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
|
|
|
1631 |
#$result["phpUser"],運行該php的使用者帳戶.
|
|
|
1632 |
#必填的參數:
|
|
|
1633 |
$conf["csInformation::getConnectionInfo"]["getAccount"]="false";#是否要取得帳號
|
|
|
1634 |
#可省略的參數:
|
|
|
1635 |
#$conf["accountVar"]=$_SESSION["username"];#帳號儲存在哪個變數裏面,預設爲$_SESSION["username"]
|
|
|
1636 |
#$conf["saveToDb"]="true";#是否要除儲存到資料庫,"true"為要儲存",預設為不儲存
|
|
|
1637 |
#$conf["dbAddress"]=$dbAddress;;#爲mysql-Server的位置,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1638 |
#$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1639 |
#$conf["dbName"]=$dbName;#要選取的資料庫名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1640 |
#$conf["tableName"]="visitorInfo";#爲要插入資料的資料表名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1641 |
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#爲資料表的項目名稱,
|
|
|
1642 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
1643 |
#寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間
|
|
|
1644 |
#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1645 |
#$conf["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
1646 |
#參考資料:
|
|
|
1647 |
#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
|
|
|
1648 |
#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
|
|
|
1649 |
$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
|
|
|
1650 |
unset($conf["csInformation::getConnectionInfo"]);
|
|
|
1651 |
|
|
|
1652 |
#如果取得使用者資訊失敗
|
|
|
1653 |
if($getConnectionInfo["status"]==="false"){
|
|
|
1654 |
|
|
|
1655 |
#設置執行不正常
|
|
|
1656 |
$result["status"]="false";
|
|
|
1657 |
|
|
|
1658 |
#設置執行錯誤
|
|
|
1659 |
$result["error"]=$getConnectionInfo;
|
|
|
1660 |
|
|
|
1661 |
#回傳結果
|
|
|
1662 |
return $result;
|
|
|
1663 |
|
|
|
1664 |
}#if end
|
|
|
1665 |
|
|
|
1666 |
#預設的callback url
|
|
|
1667 |
$conf["redirect_uri"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["serverIp"].":".$getConnectionInfo["serverPort"].$getConnectionInfo["requestUri"];
|
|
|
1668 |
|
|
|
1669 |
}#if end
|
|
|
1670 |
|
|
|
1671 |
#組合成完整的url
|
|
|
1672 |
$url=$url."?client_id=".$conf["clientId"]."&scope=".$conf["scope"]."&response_type=".$response_type."&redirect_uri=".$conf["redirect_uri"];
|
|
|
1673 |
|
|
|
1674 |
#涵式說明:
|
|
|
1675 |
#放置超鏈結
|
|
|
1676 |
#回傳的結果:
|
|
|
1677 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1678 |
#$result["error"],錯誤訊息
|
|
|
1679 |
#$result["content"],語法
|
|
|
1680 |
#$result["function"],當前執行的函數名稱
|
|
|
1681 |
#必填的參數:
|
|
|
1682 |
#$conf["position"],字串,爲要連結到的位置,若留空,將回自動變成"#",則可以搭配ajax傳值.
|
|
|
1683 |
$conf["link::show_link"]["position"]=$url;
|
|
|
1684 |
#$conf["linkName",字串,爲連結的顯示名稱
|
|
|
1685 |
$conf["link::show_link"]["linkName"]="RESTful Authenticate";
|
|
|
1686 |
#可省略的參數:
|
|
|
1687 |
#$conf["method"],字串,爲點選連結後,新畫面要如何呈現,可省略預設爲"_self",可用的選項有 _top(覆蓋目前的視窗來顯現新內容) _parent _self _blank(跳新視窗)
|
|
|
1688 |
#$conf["method"]="";
|
|
|
1689 |
#$conf["class"],字串,爲要套用的css超連節樣式,可省略.
|
|
|
1690 |
#$conf["class"]="";
|
|
|
1691 |
#$conf["id"],字串,超連結的id.
|
|
|
1692 |
#$conf["id"]="";
|
|
|
1693 |
#$conf["no_outline"],字串,是否要取消連結的框線,"false為不取消,"true"代表要取消,預設為"false".
|
|
|
1694 |
#$conf["no_outline"]="";
|
|
|
1695 |
$show_link=link::show_link($conf["link::show_link"]);
|
|
|
1696 |
unset($conf["link::show_link"]);
|
|
|
1697 |
|
|
|
1698 |
#如果建立超連結的語法失敗
|
|
|
1699 |
if($show_link["status"]==="false"){
|
|
|
1700 |
|
|
|
1701 |
#取得當前執行的函式
|
|
|
1702 |
$result["function"]=__FUNCTION__;
|
|
|
1703 |
|
|
|
1704 |
#設置執行不正常
|
|
|
1705 |
$result["status"]="false";
|
|
|
1706 |
|
|
|
1707 |
#設置執行錯誤
|
|
|
1708 |
$result["error"]=$show_link;
|
|
|
1709 |
|
|
|
1710 |
#回傳結果
|
|
|
1711 |
return $result;
|
|
|
1712 |
|
|
|
1713 |
}#if end
|
|
|
1714 |
|
|
|
1715 |
#取得語法
|
|
|
1716 |
$result["content"]=$show_link["content"];
|
|
|
1717 |
|
|
|
1718 |
#設置執行正常
|
|
|
1719 |
$result["status"]="true";
|
|
|
1720 |
|
|
|
1721 |
#回傳結果
|
|
|
1722 |
return $result;
|
|
|
1723 |
|
|
|
1724 |
}#function demoAuthenticateToACbyCode end
|
|
|
1725 |
|
|
|
1726 |
/*
|
|
|
1727 |
#函式說明:
|
|
|
1728 |
#讀取Amazon cloud drive的檔案清單
|
|
|
1729 |
#回傳結果:
|
|
|
1730 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1731 |
#$result["error"],錯誤訊息陣列.
|
|
|
1732 |
#$result["function"],當前執行的函式名稱.
|
|
|
1733 |
#$result["content"],取得的回應內容.
|
|
|
1734 |
#必填參數:
|
|
|
1735 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1736 |
$conf["fileArgu"]=__FILE__;
|
|
|
1737 |
#$conf["authToken"],字串,使用者登入後取得的token.
|
|
|
1738 |
$conf["authToken"]="";
|
|
|
1739 |
#可省略參數:
|
|
|
1740 |
#無.
|
|
|
1741 |
#參考資料:
|
|
|
1742 |
#無.
|
|
|
1743 |
#備註:
|
|
|
1744 |
#建構中
|
|
|
1745 |
*/
|
|
|
1746 |
public static function readAD(&$conf){
|
|
|
1747 |
|
|
|
1748 |
#初始化要回傳的結果
|
|
|
1749 |
$result=array();
|
|
|
1750 |
|
|
|
1751 |
#取得當前執行的函數名稱
|
|
|
1752 |
$result["function"]=__FUNCTION__;
|
|
|
1753 |
|
|
|
1754 |
#如果沒有參數
|
|
|
1755 |
if(func_num_args()==0){
|
|
|
1756 |
|
|
|
1757 |
#設置執行失敗
|
|
|
1758 |
$result["status"]="false";
|
|
|
1759 |
|
|
|
1760 |
#設置執行錯誤訊息
|
|
|
1761 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1762 |
|
|
|
1763 |
#回傳結果
|
|
|
1764 |
return $result;
|
|
|
1765 |
|
|
|
1766 |
}#if end
|
|
|
1767 |
|
|
|
1768 |
#涵式說明:
|
|
|
1769 |
#判斷當前環境為web還是cmd
|
|
|
1770 |
#回傳結果:
|
|
|
1771 |
#$result,"web"或"cmd"
|
|
|
1772 |
if(csInformation::getEnv()==="web"){
|
|
|
1773 |
|
|
|
1774 |
#設置執行失敗
|
|
|
1775 |
$result["status"]="false";
|
|
|
1776 |
|
|
|
1777 |
#設置執行錯誤訊息
|
|
|
1778 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
|
|
1779 |
|
|
|
1780 |
#回傳結果
|
|
|
1781 |
return $result;
|
|
|
1782 |
|
|
|
1783 |
}#if end
|
|
|
1784 |
|
|
|
1785 |
#取得參數
|
|
|
1786 |
$result["argu"]=$conf;
|
|
|
1787 |
|
|
|
1788 |
#如果 $conf 不為陣列
|
|
|
1789 |
if(gettype($conf)!=="array"){
|
|
|
1790 |
|
|
|
1791 |
#設置執行失敗
|
|
|
1792 |
$result["status"]="false";
|
|
|
1793 |
|
|
|
1794 |
#設置執行錯誤訊息
|
|
|
1795 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1796 |
|
|
|
1797 |
#如果傳入的參數為 null
|
|
|
1798 |
if($conf===null){
|
|
|
1799 |
|
|
|
1800 |
#設置執行錯誤訊息
|
|
|
1801 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1802 |
|
|
|
1803 |
}#if end
|
|
|
1804 |
|
|
|
1805 |
#回傳結果
|
|
|
1806 |
return $result;
|
|
|
1807 |
|
|
|
1808 |
}#if end
|
|
|
1809 |
|
|
|
1810 |
#檢查參數
|
|
|
1811 |
#函式說明:
|
|
|
1812 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1813 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1814 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1815 |
#$result["function"],當前執行的函式名稱.
|
|
|
1816 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1817 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1818 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1819 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1820 |
#必填寫的參數:
|
|
|
1821 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1822 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1823 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1824 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("authToken","fileArgu");
|
|
|
1825 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
1826 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1827 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1828 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1829 |
#可以省略的參數:
|
|
|
1830 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1831 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1832 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1833 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("header","allowAnySSLcertificate","postVar");
|
|
|
1834 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1835 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","array");
|
|
|
1836 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1837 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,array());
|
|
|
1838 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1839 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
1840 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1841 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1842 |
|
|
|
1843 |
#如果檢查參數失敗
|
|
|
1844 |
if($checkResult["status"]=="false"){
|
|
|
1845 |
|
|
|
1846 |
#設置執行失敗
|
|
|
1847 |
$result["status"]="false";
|
|
|
1848 |
|
|
|
1849 |
#設置執行錯誤
|
|
|
1850 |
$result["error"]=$checkResult;
|
|
|
1851 |
|
|
|
1852 |
#回傳結果
|
|
|
1853 |
return $result;
|
|
|
1854 |
|
|
|
1855 |
}#if end
|
|
|
1856 |
|
|
|
1857 |
#如果檢查參數不通過
|
|
|
1858 |
if($checkResult["passed"]=="false"){
|
|
|
1859 |
|
|
|
1860 |
#設置執行失敗
|
|
|
1861 |
$result["status"]="false";
|
|
|
1862 |
|
|
|
1863 |
#設置執行錯誤
|
|
|
1864 |
$result["error"]=$checkResult;
|
|
|
1865 |
|
|
|
1866 |
#回傳結果
|
|
|
1867 |
return $result;
|
|
|
1868 |
|
|
|
1869 |
}#if end
|
|
|
1870 |
|
|
|
1871 |
#函式說明:
|
|
|
1872 |
#運行curl cmd
|
|
|
1873 |
#回傳結果:
|
|
|
1874 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1875 |
#$result["error"],錯誤訊息陣列.
|
|
|
1876 |
#$result["function"],當前執行的函式名稱.
|
|
|
1877 |
#$result["content"],取得的回應內容.
|
|
|
1878 |
#$result["cmd"],執行的command
|
|
|
1879 |
#必填參數:
|
|
|
1880 |
#$conf["url"],字串,目標url.
|
|
|
1881 |
$url="https://drive.amazonaws.com/drive/v1/account/endpoint";
|
|
|
1882 |
#$url="https://cdws.us-east-1.amazonaws.com/drive/v1/changes";
|
|
|
1883 |
#$url="https://drive.amazonaws.com/drive/v1/";
|
|
|
1884 |
$conf["catchWebContent::curlCmd"]["url"]=$url;
|
|
|
1885 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1886 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
1887 |
#可省略參數:
|
|
|
1888 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
1889 |
$conf["header"][]="Authorization: Bearer ".$conf["authToken"];
|
|
|
1890 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
1891 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
1892 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
1893 |
#$conf["postVar"]=array();
|
|
|
1894 |
#備註:
|
|
|
1895 |
#僅能在命令列下執行.
|
|
|
1896 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
1897 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
1898 |
|
|
|
1899 |
#如果運行curl失敗
|
|
|
1900 |
if($curlCmd["status"]==="false"){
|
|
|
1901 |
|
|
|
1902 |
#設置執行失敗
|
|
|
1903 |
$result["status"]="false";
|
|
|
1904 |
|
|
|
1905 |
#設置執行錯誤訊息
|
|
|
1906 |
$result["error"]=$curlCmd;
|
|
|
1907 |
|
|
|
1908 |
#回傳結果
|
|
|
1909 |
return $result;
|
|
|
1910 |
|
|
|
1911 |
}#if end
|
|
|
1912 |
|
|
|
1913 |
var_dump($curlCmd);
|
|
|
1914 |
|
|
|
1915 |
}#function readAD end
|
|
|
1916 |
|
|
|
1917 |
/*
|
|
|
1918 |
#函式說明:
|
|
|
1919 |
#用parseRestCode函數取得的code來取得token
|
|
|
1920 |
#回傳結果:
|
|
|
1921 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1922 |
#$result["error"],錯誤訊息陣列.
|
|
|
1923 |
#$result["function"],當前執行的函式名稱.
|
|
|
1924 |
#$result["content"],取得的回應內容.
|
|
|
1925 |
#$result["cmd"],執行的command
|
|
|
1926 |
#必填參數:
|
|
|
1927 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1928 |
$conf["fileArgu"]=__FILE__;
|
|
|
1929 |
#$conf["code"],字串,從parseRestCode函數取得的code.
|
|
|
1930 |
$conf["code"]="";
|
|
|
1931 |
#$conf["clientId"],字串,用戶端id,亦即app的clientId.
|
|
|
1932 |
$conf["clientId"]="";
|
|
|
1933 |
#$conf["clientSecret"],字串,用戶端的 client secret.
|
|
|
1934 |
$conf["clientSecret"]="";
|
|
|
1935 |
#可省略參數:
|
|
|
1936 |
#無
|
|
|
1937 |
#參考資料:
|
|
|
1938 |
#php的amazon cloud drive api應用=>https://github.com/alex-phillips/clouddrive-php
|
|
|
1939 |
#備註:
|
|
|
1940 |
#僅能在命令列下執行.
|
|
|
1941 |
#似乎因為沒有被 Amazon 列到 white list 裡面所以目前無法取得token
|
|
|
1942 |
*/
|
|
|
1943 |
public static function getACtokenByCode(&$conf){
|
|
|
1944 |
|
|
|
1945 |
#初始化要回傳的結果
|
|
|
1946 |
$result=array();
|
|
|
1947 |
|
|
|
1948 |
#取得當前執行的函數名稱
|
|
|
1949 |
$result["function"]=__FUNCTION__;
|
|
|
1950 |
|
|
|
1951 |
#如果沒有參數
|
|
|
1952 |
if(func_num_args()==0){
|
|
|
1953 |
|
|
|
1954 |
#設置執行失敗
|
|
|
1955 |
$result["status"]="false";
|
|
|
1956 |
|
|
|
1957 |
#設置執行錯誤訊息
|
|
|
1958 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1959 |
|
|
|
1960 |
#回傳結果
|
|
|
1961 |
return $result;
|
|
|
1962 |
|
|
|
1963 |
}#if end
|
|
|
1964 |
|
|
|
1965 |
#涵式說明:
|
|
|
1966 |
#判斷當前環境為web還是cmd
|
|
|
1967 |
#回傳結果:
|
|
|
1968 |
#$result,"web"或"cmd"
|
|
|
1969 |
if(csInformation::getEnv()==="web"){
|
|
|
1970 |
|
|
|
1971 |
#設置執行失敗
|
|
|
1972 |
$result["status"]="false";
|
|
|
1973 |
|
|
|
1974 |
#設置執行錯誤訊息
|
|
|
1975 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
|
|
1976 |
|
|
|
1977 |
#回傳結果
|
|
|
1978 |
return $result;
|
|
|
1979 |
|
|
|
1980 |
}#if end
|
|
|
1981 |
|
|
|
1982 |
#取得參數
|
|
|
1983 |
$result["argu"]=$conf;
|
|
|
1984 |
|
|
|
1985 |
#如果 $conf 不為陣列
|
|
|
1986 |
if(gettype($conf)!=="array"){
|
|
|
1987 |
|
|
|
1988 |
#設置執行失敗
|
|
|
1989 |
$result["status"]="false";
|
|
|
1990 |
|
|
|
1991 |
#設置執行錯誤訊息
|
|
|
1992 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1993 |
|
|
|
1994 |
#如果傳入的參數為 null
|
|
|
1995 |
if($conf===null){
|
|
|
1996 |
|
|
|
1997 |
#設置執行錯誤訊息
|
|
|
1998 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1999 |
|
|
|
2000 |
}#if end
|
|
|
2001 |
|
|
|
2002 |
#回傳結果
|
|
|
2003 |
return $result;
|
|
|
2004 |
|
|
|
2005 |
}#if end
|
|
|
2006 |
|
|
|
2007 |
#檢查參數
|
|
|
2008 |
#函式說明:
|
|
|
2009 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2010 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2011 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2012 |
#$result["function"],當前執行的函式名稱.
|
|
|
2013 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2014 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2015 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2016 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2017 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2018 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2019 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2020 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2021 |
#必填寫的參數:
|
|
|
2022 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2023 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2024 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2025 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("clientId","code","fileArgu","clientSecret");
|
|
|
2026 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2027 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
|
|
|
2028 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2029 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2030 |
#可以省略的參數:
|
|
|
2031 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2032 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2033 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2034 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2035 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2036 |
#$conf["canBeEmpty"]=array();
|
|
|
2037 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2038 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2039 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2040 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("redirect_uri");
|
|
|
2041 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2042 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2043 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2044 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
2045 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2046 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2047 |
#參考資料來源:
|
|
|
2048 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2049 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2050 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2051 |
|
|
|
2052 |
#如果參數檢查失敗
|
|
|
2053 |
if($checkArguments["status"]==="false"){
|
|
|
2054 |
|
|
|
2055 |
#設置執行不正常
|
|
|
2056 |
$result["status"]="false";
|
|
|
2057 |
|
|
|
2058 |
#設置執行錯誤
|
|
|
2059 |
$result["error"]=$checkArguments;
|
|
|
2060 |
|
|
|
2061 |
#回傳結果
|
|
|
2062 |
return $result;
|
|
|
2063 |
|
|
|
2064 |
}#if end
|
|
|
2065 |
|
|
|
2066 |
#如果參數檢查不通過
|
|
|
2067 |
if($checkArguments["passed"]==="false"){
|
|
|
2068 |
|
|
|
2069 |
#設置執行不正常
|
|
|
2070 |
$result["status"]="false";
|
|
|
2071 |
|
|
|
2072 |
#設置執行錯誤
|
|
|
2073 |
$result["error"]=$checkArguments;
|
|
|
2074 |
|
|
|
2075 |
#回傳結果
|
|
|
2076 |
return $result;
|
|
|
2077 |
|
|
|
2078 |
}#if end
|
|
|
2079 |
|
|
|
2080 |
#函式說明:
|
|
|
2081 |
#運行curl cmd
|
|
|
2082 |
#回傳結果:
|
|
|
2083 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2084 |
#$result["error"],錯誤訊息陣列.
|
|
|
2085 |
#$result["function"],當前執行的函式名稱.
|
|
|
2086 |
#$result["content"],取得的回應內容.
|
|
|
2087 |
#$result["cmd"],執行的command
|
|
|
2088 |
#必填參數:
|
|
|
2089 |
#$conf["url"],字串,目標url.
|
|
|
2090 |
$conf["catchWebContent::curlCmd"]["url"]="https://api.amazon.com/auth/o2/token";
|
|
|
2091 |
#$conf["catchWebContent::curlCmd"]["url"]="https://127.0.0.1/~qbpwcf/samplePage/phplib/qbpwcf/testCase/amazonT/showRequest.php";
|
|
|
2092 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2093 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2094 |
#可省略參數:
|
|
|
2095 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
2096 |
$conf["catchWebContent::curlCmd"]["header"][]="HTTP/1.1";
|
|
|
2097 |
$conf["catchWebContent::curlCmd"]["header"][]="Content-Type: application/x-www-form-urlencoded";
|
|
|
2098 |
$conf["catchWebContent::curlCmd"]["header"][]="Cache-Control: no-cache";
|
|
|
2099 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
2100 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
2101 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
2102 |
$conf["catchWebContent::curlCmd"]["postVar"]["grant_type"]="authorization_code";
|
|
|
2103 |
$conf["catchWebContent::curlCmd"]["postVar"]["code"]=$conf["code"];
|
|
|
2104 |
$conf["catchWebContent::curlCmd"]["postVar"]["client_id"]=$conf["clientId"];
|
|
|
2105 |
$conf["catchWebContent::curlCmd"]["postVar"]["client_secret"]=$conf["clientSecret"];
|
|
|
2106 |
$conf["catchWebContent::curlCmd"]["postVar"]["redirect_uri"]="https://localhost";
|
|
|
2107 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
2108 |
$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
2109 |
#備註:
|
|
|
2110 |
#僅能在命令列下執行.
|
|
|
2111 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
2112 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
2113 |
|
|
|
2114 |
#如果執行curl cmd失敗
|
|
|
2115 |
if($curlCmd["status"]==="false"){
|
|
|
2116 |
|
|
|
2117 |
#設置執行失敗
|
|
|
2118 |
$result["status"]="false";
|
|
|
2119 |
|
|
|
2120 |
#設置執行錯誤訊息
|
|
|
2121 |
$result["error"]=$curlCmd;
|
|
|
2122 |
|
|
|
2123 |
#回傳結果
|
|
|
2124 |
return $result;
|
|
|
2125 |
|
|
|
2126 |
}#if end
|
|
|
2127 |
|
|
|
2128 |
#取得回應
|
|
|
2129 |
$result["content"]=$curlCmd["content"];
|
|
|
2130 |
|
|
|
2131 |
#取得執行的culr命令
|
|
|
2132 |
$result["cmd"]=$curlCmd["cmd"];
|
|
|
2133 |
|
|
|
2134 |
#設置正常執行
|
|
|
2135 |
$result["status"]="true";
|
|
|
2136 |
|
|
|
2137 |
#回傳結果
|
|
|
2138 |
return $result;
|
|
|
2139 |
|
|
|
2140 |
}#functino getACtokenByCode end
|
|
|
2141 |
|
|
|
2142 |
}#class amazon end
|
|
|
2143 |
|
|
|
2144 |
?>
|