Subversion Repositories php-qbpwcf

Rev

Rev 323 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
317 liveuser 1
<?php
2
 
3
/*
4
 
5
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2026 MIN ZHI, 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
 
25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
28
#assets dir
29
$assetsDir="assets of system_sendMailAgent_20250528";
30
 
31
#函式說明:
32
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
33
#回傳結果:
34
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
35
#$result["error"],錯誤訊息陣列
36
#$result["function"],當前執行的函數名稱
37
#$result["content"],要執行的javaScript語法
38
#必填參數:
39
#$conf["script"],字串,要執行的javaScript語法.
40
$conf["script"]="
41
 
42
	//需要認證email
43
	var mail='".systemMailAcct."';
44
 
45
	//將需要加密的內容 ajax 給 api
46
	//傳送表單
47
	/*
48
	設置 window.qbpwcf.ajaxP 函數
49
	說明:
50
	傳送ajax,指定傳送前要做什麼事情,然後回傳一個Promise.
51
	參數:
52
	params={};
53
	params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
54
	params.headers={name:value};
55
	params.url='url to request';
56
	params.preAc='function name to call before send request';
57
	params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
58
	參考資料:
59
	https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.html
60
	https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
61
	*/
62
	ajaxP_params={};
63
	ajaxP_params.data='mail='+encodeURIComponent(mail);
64
	ajaxP_params.method='POST';
65
	ajaxP_params.url='../system/sendMailAgent/encrypt.php';
66
	var res = await window.qbpwcf.ajaxP.call(this,ajaxP_params);
67
 
68
	//如果執行異常
69
	if(res.status==='false'){
70
 
71
		//console erorr message
72
		console.error(res.error);
73
 
74
		}//if end
75
 
76
	//如果不是合法的 json 格式
77
	if(res.compliantJson==='false'){
78
 
79
		//console erorr message
80
		console.error('invalid json response');
81
 
82
		}//if end
83
 
84
	//debug
85
	//console.log(res);
86
 
87
	//另存 加密後的 session
88
	var sess=res.json.sess;
89
 
90
	//要傳送給 api 的 mail 資料
91
	var data={
92
 
93
		sid:sess,
94
 
95
		mail:res.json.post,
96
 
97
		}//data end
98
 
99
	//傳送要求認證的 ajax 給 api
100
	//傳送表單
101
	/*
102
	設置 window.qbpwcf.ajaxP 函數
103
	說明:
104
	傳送ajax,指定傳送前要做什麼事情,然後回傳一個Promise.
105
	參數:
106
	params={};
107
	params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
108
	params.headers={name:value};
109
	params.url='url to request';
110
	params.preAc='function name to call before send request';
111
	params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
112
	參考資料:
113
	https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.html
114
	https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
115
	*/
116
	ajaxP_params={};
117
	ajaxP_params.data='sid='+encodeURIComponent(res.json.get)+'&mail='+encodeURIComponent(res.json.post);
118
	ajaxP_params.method='POST';
119
	ajaxP_params.url='../system/sendMailAgent/mail.php';
120
	var res = await window.qbpwcf.ajaxP.call(this,ajaxP_params);
121
 
122
	//如果執行異常
123
	if(res.status==='false'){
124
 
125
		//console erorr message
126
		console.error(res.error);
127
 
128
		}//if end
129
 
130
	//如果不是合法的 json 格式
131
	if(res.compliantJson==='false'){
132
 
133
		//console erorr message
134
		console.error('invalid json response');
135
 
136
		}//if end
137
 
138
	//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.
139
	//params,參數物件.
140
	//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss
141
	//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.
142
	//params.data,要傳輸的資料物件.
143
	//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.
144
	var params={};
145
	params.data={};
146
	params.data.sess=encodeURIComponent(sess);
147
	var status=await window.qbpwcf.ws.init(params);
148
 
149
	//如果認證通過
150
	if(status=='authenticated'){
151
 
152
		//提示 email 已經通過認證
153
		console.log('email:'+mail+' authenticated');
154
 
155
		}//if end
156
 
157
	";
158
#可省略參數:
159
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
160
#$conf["onReady"]="true";
161
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
162
#$conf["globalJs"]=array();
163
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
164
#$conf["jsFunciton"]=array();
165
#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
166
#$conf["noScriptTag"]="false";
167
#參考資料:
168
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
169
#備註:
170
#無.
171
$toScript=javaScript::toScript($conf);
172
unset($conf);
173
 
174
#如果執行失敗
175
if($toScript["status"]==="false"){
176
 
177
	#函式說明:
178
	#撰寫log
179
	#回傳結果:
180
	#$result["status"],狀態,"true"或"false".
181
	#$result["error"],錯誤訊息陣列.
182
	#$result["function"],當前函式的名稱.
183
	#$result["argu"],使用的參數.
184
	#必填參數:
185
	#$conf["path"],字串,log檔案的路徑與名稱.
186
	$conf["path"]=$logFile;
187
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
188
	$conf["content"]=$toScript;
189
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
190
	$conf["fileArgu"]=__FILE__;
191
	#可省略參數:
192
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
193
	#$conf["rewrite"]="false";
194
	#參考資料:
195
	#無.
196
	#備註:
197
	#無.
198
	$record=logs::record($conf);
199
	unset($conf);
200
 
201
	#如果寫log失敗
202
	if($record["status"]==="false"){
203
 
204
		#印出結果
205
		var_dump($record);
206
 
207
		}#if end
208
 
209
	#結束執行,回傳錯誤代碼1
210
	exit(1);
211
 
212
	}#if end
213
 
214
#debug
215
echo $toScript["content"];
216