Subversion Repositories php-qbpwcf

Rev

Rev 317 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 317 Rev 323
Line 68... Line 68...
68
	//如果執行異常
68
	//如果執行異常
69
	if(res.status==='false'){
69
	if(res.status==='false'){
70
 
70
 
71
		//console erorr message
71
		//console erorr message
72
		console.error(res.error);
72
		console.error(res.error);
-
 
73
		
-
 
74
		//結束執行
-
 
75
		return;
73
 
76
 
74
		}//if end
77
		}//if end
75
 
78
 
76
	//如果不是合法的 json 格式
79
	//如果不是合法的 json 格式
77
	if(res.compliantJson==='false'){
80
	if(res.compliantJson==='false'){
78
 
81
 
79
		//console erorr message
82
		//console erorr message
80
		console.error('invalid json response');
83
		console.error('invalid json response');
-
 
84
		
-
 
85
		//結束執行
-
 
86
		return;
81
 
87
 
82
		}//if end
88
		}//if end
83
 
89
 
84
	//debug
90
	//debug
85
	//console.log(res);
91
	//console.log(res);
Line 94... Line 100...
94
 
100
 
95
		mail:res.json.post,
101
		mail:res.json.post,
96
 
102
 
97
		}//data end
103
		}//data end
98
 
104
 
-
 
105
	//儲存用於識別用戶資源的id
-
 
106
	var wsClientId=crypto.randomUUID();
-
 
107
 
99
	//傳送要求認證的 ajax 給 api
108
	//傳送要求認證的 ajax 給 api
100
	//傳送表單
109
	//傳送表單
101
	/*
110
	/*
102
	設置 window.qbpwcf.ajaxP 函數
111
	設置 window.qbpwcf.ajaxP 函數
103
	說明:
112
	說明:
Line 112... Line 121...
112
	參考資料:
121
	參考資料:
113
	https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.html
122
	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
123
	https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
115
	*/
124
	*/
116
	ajaxP_params={};
125
	ajaxP_params={};
117
	ajaxP_params.data='sid='+encodeURIComponent(res.json.get)+'&mail='+encodeURIComponent(res.json.post);
126
	ajaxP_params.data='sid='+encodeURIComponent(res.json.sess)+'&mail='+encodeURIComponent(res.json.post)+'&id='+encodeURIComponent(wsClientId);
118
	ajaxP_params.method='POST';
127
	ajaxP_params.method='POST';
119
	ajaxP_params.url='../system/sendMailAgent/mail.php';
128
	ajaxP_params.url='../system/sendMailAgent/mail.php';
120
	var res = await window.qbpwcf.ajaxP.call(this,ajaxP_params);
129
	var res = await window.qbpwcf.ajaxP.call(this,ajaxP_params);
121
 
130
 
122
	//如果執行異常
131
	//如果執行異常
123
	if(res.status==='false'){
132
	if(res.status==='false'){
124
 
133
 
125
		//console erorr message
134
		//console erorr message
126
		console.error(res.error);
135
		console.error(res.error);
-
 
136
		
-
 
137
		//結束執行
-
 
138
		return;
127
 
139
 
128
		}//if end
140
		}//if end
129
 
141
 
130
	//如果不是合法的 json 格式
142
	//如果不是合法的 json 格式
131
	if(res.compliantJson==='false'){
143
	if(res.compliantJson==='false'){
132
 
144
 
133
		//console erorr message
145
		//console erorr message
134
		console.error('invalid json response');
146
		console.error('invalid json response');
-
 
147
		
-
 
148
		//結束執行
-
 
149
		return;
135
 
150
 
136
		}//if end
151
		}//if end
137
 
152
 
138
	//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.
153
	//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.
139
	//params,參數物件.
154
	//params,參數物件.
140
	//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss
155
	//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss
141
	//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.
156
	//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.
142
	//params.data,要傳輸的資料物件.
157
	//params.data,要傳輸的資料物件.
143
	//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.
158
	//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.
144
	var params={};
159
	var params={};
-
 
160
	params.url='wss://".\system_sendMailAgent_ws_domain."';
145
	params.data={};
161
	params.data={};
146
	params.data.sess=encodeURIComponent(sess);
162
	params.data.sess=sess;
-
 
163
	params.data.id=wsClientId;
147
	var status=await window.qbpwcf.ws.init(params);
164
	var res=await window.qbpwcf.ws.init(params);
148
	
165
	
149
	//如果認證通過
166
	//如果來自server說認證通過
150
	if(status=='authenticated'){
167
	while(res.from!='server' || res.msg!='authenticated'){
151
	
168
	
-
 
169
		//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.
-
 
170
		//params,參數物件.
-
 
171
		//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss
-
 
172
		//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.
152
		//提示 email 已經通過認證
173
		//params.data,要傳輸的資料物件.
-
 
174
		//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.
-
 
175
		var params={};
-
 
176
		params.url='wss://".\system_sendMailAgent_ws_domain."';
-
 
177
		params.data={};
-
 
178
		params.data.id=window.qbpwcf.ws.wss[params.url].params.data.id;
153
		console.log('email:'+mail+' authenticated');
179
		var res=await window.qbpwcf.ws.init(params);
154
	
180
	
155
		}//if end
181
		}//if end
156
		
182
		
-
 
183
	//提示通過email認證
-
 
184
	console.log('email validated');
-
 
185
		
157
	";
186
	";
158
#可省略參數:
187
#可省略參數:
159
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
188
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
160
#$conf["onReady"]="true";
189
#$conf["onReady"]="true";
161
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
190
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.