Rev 323 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2014~2026 MIN ZHI, CHENThis file is part of QBPWCF.QBPWCF is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.QBPWCF is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with QBPWCF. If not, see <http://www.gnu.org/licenses/>.*/#使用命名空間qbpwcfnamespace qbpwcf;#assets dir$assetsDir="assets of system_sendMailAgent_20250528";#函式說明:#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).#回傳結果:#$result["status"],執行是否正常,"true"為正常,"false"為不正常.#$result["error"],錯誤訊息陣列#$result["function"],當前執行的函數名稱#$result["content"],要執行的javaScript語法#必填參數:#$conf["script"],字串,要執行的javaScript語法.$conf["script"]="//需要認證emailvar mail='".systemMailAcct."';//將需要加密的內容 ajax 給 api//傳送表單/*設置 window.qbpwcf.ajaxP 函數說明:傳送ajax,指定傳送前要做什麼事情,然後回傳一個Promise.參數:params={};params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';params.headers={name:value};params.url='url to request';params.preAc='function name to call before send request';params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};參考資料:https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.htmlhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise*/ajaxP_params={};ajaxP_params.data='mail='+encodeURIComponent(mail);ajaxP_params.method='POST';ajaxP_params.url='../system/sendMailAgent/encrypt.php';var res = await window.qbpwcf.ajaxP.call(this,ajaxP_params);//如果執行異常if(res.status==='false'){//console erorr messageconsole.error(res.error);//結束執行return;}//if end//如果不是合法的 json 格式if(res.compliantJson==='false'){//console erorr messageconsole.error('invalid json response');//結束執行return;}//if end//debug//console.log(res);//另存 加密後的 sessionvar sess=res.json.sess;//要傳送給 api 的 mail 資料var data={sid:sess,mail:res.json.post,}//data end//儲存用於識別用戶資源的idvar wsClientId=crypto.randomUUID();//傳送要求認證的 ajax 給 api//傳送表單/*設置 window.qbpwcf.ajaxP 函數說明:傳送ajax,指定傳送前要做什麼事情,然後回傳一個Promise.參數:params={};params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';params.headers={name:value};params.url='url to request';params.preAc='function name to call before send request';params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};參考資料:https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.htmlhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise*/ajaxP_params={};ajaxP_params.data='sid='+encodeURIComponent(res.json.sess)+'&mail='+encodeURIComponent(res.json.post)+'&id='+encodeURIComponent(wsClientId);ajaxP_params.method='POST';ajaxP_params.url='../system/sendMailAgent/mail.php';var res = await window.qbpwcf.ajaxP.call(this,ajaxP_params);//如果執行異常if(res.status==='false'){//console erorr messageconsole.error(res.error);//結束執行return;}//if end//如果不是合法的 json 格式if(res.compliantJson==='false'){//console erorr messageconsole.error('invalid json response');//結束執行return;}//if end//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.//params,參數物件.//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.//params.data,要傳輸的資料物件.//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.var params={};params.url='wss://".\system_sendMailAgent_ws_domain."';params.data={};params.data.sess=sess;params.data.id=wsClientId;var res=await window.qbpwcf.ws.init(params);//debugconsole.log(res);//如果來自server說認證通過while(res.from!='server' || res.msg!='authenticated'){//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.//params,參數物件.//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.//params.data,要傳輸的資料物件.//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.var params={};params.url='wss://".\system_sendMailAgent_ws_domain."';params.data={};params.data.id=window.qbpwcf.ws.wss[params.url].params.data.id;res=await window.qbpwcf.ws.init(params);//debugconsole.log(res);}//if end//提示通過email認證console.log('email validated');";#可省略參數:#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.#$conf["onReady"]="true";#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.#$conf["globalJs"]=array();#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.#$conf["jsFunciton"]=array();#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.#$conf["noScriptTag"]="false";#參考資料:#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the#備註:#無.$toScript=javaScript::toScript($conf);unset($conf);#如果執行失敗if($toScript["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$toScript;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);unset($conf);#如果寫log失敗if($record["status"]==="false"){#印出結果var_dump($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#debugecho $toScript["content"];