傳送簡訊驗證碼方法
阿新 • • 發佈:2019-02-15
方法定義
function dosendMsg(msgparameter,regmsgid) { var initTimeout = 90; var smsTimeout = initTimeout; var begintime = 0; var canSend = true; if(canSend){ $("#getMsgCode").removeAttr("disabled");//將按鈕可用 }else{ $("#getMsgCode").attr({"disabled":"disabled"});//按鈕不可用 } var updateSendMsg = function(){ var nowDate = new Date(); smsTimeout = parseInt(initTimeout-(nowDate.getTime() - begintime.getTime())/1000); if (smsTimeout < 0) { canSend = true; smsTimeout = initTimeout; $('#getMsgCode').html("獲取驗證碼"); return; } $('#getMsgCode').html(smsTimeout + "秒後重發"); canSend = false; window.setTimeout(updateSendMsg,1000); } if (canSend == false) return; canSend = false; // 呼叫交易,傳送簡訊 $.ajax({ type : 'POST', url : basePath + 'WebService', dataType : 'json', data : JSON.stringify(msgparameter), success : function(data){ if (data.issuccess) { // 開始計數 var date = new Date(); begintime = date; updateSendMsg(); console.log(data.result.msgid); regmsgid = data.result.msgid; } else { console.log(data); canSend = true; if(data.rtnmessage){ layer.msg(data.rtnmessage) }else{ layer.msg(data.solution) } } }, error: function(data){ //彈出錯誤資訊 console.log(data); } }); }